Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: flarum 2.0 upgrade #77

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
fix: errors
  • Loading branch information
SychO9 committed Nov 15, 2024
commit 44ed1a10bca95a70cf150ce6857f846d061da3ff
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -80,5 +80,6 @@
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
},
"minimum-stability": "dev"
"minimum-stability": "dev",
"prefer-stable": true
}
14 changes: 14 additions & 0 deletions js/src/admin/extend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import app from 'flarum/admin/app';
import Extend from 'flarum/common/extenders';
import followingPageOptions from '../common/utils/followingPageOptions';

export default [
new Extend.Admin().setting(() => ({
setting: 'fof-follow-tags.following_page_default',
options: followingPageOptions('admin.settings'),
type: 'select',
label: app.translator.trans('fof-follow-tags.admin.settings.following_page_default_label'),
default: 'none',
required: true,
})),
];
12 changes: 3 additions & 9 deletions js/src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import app from 'flarum/admin/app';
import followingPageOptions from '../common/utils/followingPageOptions';

export { default as extend } from './extend';

app.initializers.add('fof/follow-tags', () => {
app.registry.for('fof-follow-tags').registerSetting({
setting: 'fof-follow-tags.following_page_default',
options: followingPageOptions('admin.settings'),
type: 'select',
label: app.translator.trans('fof-follow-tags.admin.settings.following_page_default_label'),
default: 'none',
required: true,
});
//
});
13 changes: 7 additions & 6 deletions js/src/common/utils/followingPageOptions.js
Original file line number Diff line number Diff line change
@@ -2,10 +2,11 @@ import app from 'flarum/common/app';

let opts;

export default (section) =>
opts ||
(opts = ['none', 'tags'].reduce((o, key) => {
o[key] = app.translator.trans(`fof-follow-tags.${section}.following_${key}_label`);
export default function followingPageOptions(section) {
return opts ||
(opts = ['none', 'tags'].reduce((o, key) => {
o[key] = app.translator.trans(`fof-follow-tags.${section}.following_${key}_label`);

return o;
}, {}));
return o;
}, {}));
}
1 change: 0 additions & 1 deletion js/src/forum/addSubscriptionControls.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ import IndexSidebar from 'flarum/forum/components/IndexSidebar';
import app from 'flarum/forum/app';
import { extend } from 'flarum/common/extend';
import Model from 'flarum/common/Model';
import IndexPage from 'flarum/forum/components/IndexPage';
import SubscriptionModal from './components/SubscriptionModal';
import SubscriptionStateButton from './components/SubscriptionStateButton';

2 changes: 1 addition & 1 deletion js/src/forum/components/SubscriptionModal.tsx
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ export default class SubscriptionModal extends Modal<ISubscriptionModalAttrs> {
'subscription_type',
<div className="Form-group">
<label>{app.translator.trans('fof-follow-tags.forum.sub_controls.subscription_label', { tagName: this.attrs.model.name() })}</label>
{this.subscriptionOptionItems().toArray()}
<div className="SubscriptionModal-options">{this.subscriptionOptionItems().toArray()}</div>
</div>,
60
);
3 changes: 2 additions & 1 deletion js/src/forum/components/SubscriptionStateButton.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import { utils } from '../utils';
import Tooltip from 'flarum/common/components/Tooltip';
import extractText from 'flarum/common/utils/extractText';
import Stream from 'flarum/common/utils/Stream';
import classList from 'flarum/common/utils/classList';

export default class SubscriptionStateButton extends Button {
oninit(vnode) {
@@ -36,7 +37,7 @@ export default class SubscriptionStateButton extends Button {
let buttonIcon = option ? option.icon : 'fas fa-star';
let buttonLabel = option ? app.translator.trans(option.labelKey) : app.translator.trans('fof-follow-tags.forum.sub_controls.follow_button');

this.attrs.className = (this.attrs.className || '') + ' SubscriptionButton ' + 'SubscriptionButton--' + subscription;
this.attrs.className = classList(this.attrs.className, `SubscriptionButton SubscriptionButton--${subscription}`);
this.attrs.icon = buttonIcon;

const preferences = app.session.user.preferences();
29 changes: 20 additions & 9 deletions resources/less/forum.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.SubscriptionButton {
width: 100%; // as per your dropdown's button width
display: inline-block; // to make it sit alongside other elements

&--follow {
.Button--color(#de8e00, #fff2ae);
@@ -39,25 +38,27 @@
margin-left: 1px;
}

@primary-btn-bg: @primary-color;
@primary-btn-text: @body-bg-light;
@secondary-btn-bg: @control-bg;
@secondary-btn-text: @text-color;

// Subscription Modal
.SubscriptionModal {
--primary-btn-bg: var(--primary-color);
--primary-btn-text: var(--body-bg-light);

.Modal-body {
color: var(--text-color);
}

.Button.Button--primary {
background-color: @primary-btn-bg;
color: @primary-btn-text;
background-color: var(--primary-btn-bg);
color: var(--primary-btn-text);
}

.Form-group {
margin-bottom: 20px;
}

&-options {
width: 100%;
}
}

// Subscription Options List
@@ -68,6 +69,16 @@
}

.SubscriptionOption {
--secondary-btn-text: var(--text-color);

[data-theme^="light"] & {
--secondary-btn-bg: darken(@control-bg-light, 10%)
}

[data-theme^="dark"] & {
--secondary-btn-bg: darken(@control-bg-dark, 10%)
}

padding: 10px;
border: 1px solid var(--muted-color);
border-radius: var(--border-radius);
@@ -83,7 +94,7 @@
}

&:hover {
background-color: darken(@secondary-btn-bg, 10%);
background-color: var(--secondary-btn-bg);
}

&.selected {