Skip to content

Commit

Permalink
Merge pull request #3 from datlechin/main
Browse files Browse the repository at this point in the history
Add workflows and run yarn format
  • Loading branch information
justoverclockl committed Jun 26, 2022
2 parents 767b56e + 08427af commit 1d5da57
Show file tree
Hide file tree
Showing 13 changed files with 1,624 additions and 1,592 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


name: Popular Tags PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: false

backend_directory: .
19 changes: 19 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Popular Tags JS

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false

frontend_directory: ./js
backend_directory: .
js_package_manager: yarn
main_git_branch: main

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions js/src/admin/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import app from 'flarum/admin/app';
import registerWidget from "../common/registerWidget";
import registerWidget from '../common/registerWidget';

app.initializers.add('justoverclock/popular-tags', () => {
registerWidget(app)
app.extensionData
.for('justoverclock-popular-tags')
.registerSetting({
setting: 'justoverclock-popular-tags.numberOfTags',
name: 'justoverclock-popular-tags.numberOfTags',
type: 'number',
label: app.translator.trans('justoverclock-popular-tags.admin.limit'),
help: app.translator.trans('justoverclock-popular-tags.admin.limit-help'),
})
registerWidget(app);
app.extensionData.for('justoverclock-popular-tags').registerSetting({
setting: 'justoverclock-popular-tags.numberOfTags',
name: 'justoverclock-popular-tags.numberOfTags',
type: 'number',
label: app.translator.trans('justoverclock-popular-tags.admin.limit'),
help: app.translator.trans('justoverclock-popular-tags.admin.limit-help'),
});
});
48 changes: 24 additions & 24 deletions js/src/common/components/PopularTags.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import Widget from 'flarum/extensions/afrux-forum-widgets-core/common/components/Widget';
import app from 'flarum/forum/app'
import getTags from "../helpers/getTags";
import LoadingIndicator from "flarum/common/components/LoadingIndicator";
import Link from 'flarum/common/components/Link'
import app from 'flarum/forum/app';
import getTags from '../helpers/getTags';
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
import Link from 'flarum/common/components/Link';

export default class MyWidget extends Widget {

oninit(vnode) {
super.oninit(vnode);
this.loading = true;
}

oncreate(vnode) {
super.oncreate(vnode);
const showedTags = app.forum.attribute('justoverclock-popular-tags.numberOfTags') || 4
const url = app.forum.attribute('baseUrl') + '/api/tags'
getTags(url).then(res => {
this.popularTags = res.slice(0, showedTags)
this.loading = false
m.redraw()
})
const showedTags = app.forum.attribute('justoverclock-popular-tags.numberOfTags') || 4;
const url = app.forum.attribute('baseUrl') + '/api/tags';
getTags(url).then((res) => {
this.popularTags = res.slice(0, showedTags);
this.loading = false;
m.redraw();
});
}

className() {
Expand All @@ -36,22 +35,23 @@ export default class MyWidget extends Widget {

content() {
if (this.loading) {
return <LoadingIndicator/>;
return <LoadingIndicator />;
}
return (
<div className="popular-tags">
<ul className="poptag-ul">
{this.popularTags && this.popularTags.map((tag) => {
const baseUrl = app.forum.attribute('baseUrl')
const discussionCount = app.translator.trans('justoverclock-popular-tags.forum.count') + tag.attributes.discussionCount
return (
<Link href={baseUrl + '/t/' + tag.attributes.slug} className="popular-tags-link">
<li className="poptag-li" title={discussionCount}>
{tag.attributes.name}
</li>
</Link>
)
})}
{this.popularTags &&
this.popularTags.map((tag) => {
const baseUrl = app.forum.attribute('baseUrl');
const discussionCount = app.translator.trans('justoverclock-popular-tags.forum.count') + tag.attributes.discussionCount;
return (
<Link href={baseUrl + '/t/' + tag.attributes.slug} className="popular-tags-link">
<li className="poptag-li" title={discussionCount}>
{tag.attributes.name}
</li>
</Link>
);
})}
</ul>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions js/src/common/helpers/getTags.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export default async function getTags(url) {
const response = await fetch(url)
const data = await response.json()
const response = await fetch(url);
const data = await response.json();
return data.data.sort((a, b) => {
if (a.number === b.number) {
return b.attributes.discussionCount - a.attributes.discussionCount;
} else {
return b.number - a.number;
}
})
});
}
2 changes: 1 addition & 1 deletion js/src/common/helpers/randomColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export default function randomBgColors() {
const x = Math.floor(Math.random() * 256);
const y = Math.floor(Math.random() * 256);
const z = Math.floor(Math.random() * 256);
return "rgb(" + x + "," + y + "," + z + ")"
return 'rgb(' + x + ',' + y + ',' + z + ')';
}
22 changes: 12 additions & 10 deletions js/src/common/registerWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import Widgets from 'flarum/extensions/afrux-forum-widgets-core/common/extend/Wi

import PopularTags from './components/PopularTags';

export default function(app) {
(new Widgets).add({
key: 'PopularTags',
component: PopularTags,
isDisabled: false,
isUnique: true,
placement: 'end',
position: 1,
}).extend(app, 'justoverclock-popular-tags');
};
export default function (app) {
new Widgets()
.add({
key: 'PopularTags',
component: PopularTags,
isDisabled: false,
isUnique: true,
placement: 'end',
position: 1,
})
.extend(app, 'justoverclock-popular-tags');
}
2 changes: 1 addition & 1 deletion js/src/forum/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import app from 'flarum/forum/app';
import registerWidget from "../common/registerWidget";
import registerWidget from '../common/registerWidget';

app.initializers.add('justoverclock/popular-tags', () => {
registerWidget(app);
Expand Down
Loading

0 comments on commit 1d5da57

Please sign in to comment.