mirror of
https://github.com/flarum/core.git
synced 2025-07-24 10:11:43 +02:00
Initial refactor of client actions, data preloading, SEO
An initial stab at flarum/core#126. Still WIP. Preliminary implementation of flarum/core#128 and flarum/core#13.
This commit is contained in:
@@ -70,7 +70,7 @@ export default class AvatarEditor extends Component {
|
||||
m.redraw();
|
||||
m.request({
|
||||
method: 'POST',
|
||||
url: app.config['api_url']+'/users/'+user.id()+'/avatar',
|
||||
url: app.forum.attribute('apiUrl')+'/users/'+user.id()+'/avatar',
|
||||
data: data,
|
||||
serialize: data => data,
|
||||
background: true,
|
||||
@@ -91,7 +91,7 @@ export default class AvatarEditor extends Component {
|
||||
m.redraw();
|
||||
m.request({
|
||||
method: 'DELETE',
|
||||
url: app.config['api_url']+'/users/'+user.id()+'/avatar',
|
||||
url: app.forum.attribute('apiUrl')+'/users/'+user.id()+'/avatar',
|
||||
config: app.session.authorize.bind(app.session)
|
||||
}).then(function(data) {
|
||||
self.loading(false);
|
||||
|
@@ -20,7 +20,7 @@ export default class ChangePasswordModal extends FormModal {
|
||||
|
||||
m.request({
|
||||
method: 'POST',
|
||||
url: app.config['api_url']+'/forgot',
|
||||
url: app.forum.attribute('apiUrl')+'/forgot',
|
||||
data: {email: app.session.user().email()},
|
||||
background: true
|
||||
}).then(response => {
|
||||
|
@@ -64,9 +64,9 @@ export default class DiscussionList extends Component {
|
||||
}
|
||||
|
||||
loadResults(offset) {
|
||||
if (app.preload.response) {
|
||||
var discussions = app.store.pushPayload(app.preload.response);
|
||||
app.preload.response = null;
|
||||
const discussions = app.preloadedDocument();
|
||||
|
||||
if (discussions) {
|
||||
return m.deferred().resolve(discussions).promise;
|
||||
} else {
|
||||
var params = this.params();
|
||||
|
@@ -43,17 +43,13 @@ export default class DiscussionPage extends mixin(Component, evented) {
|
||||
var params = this.params();
|
||||
params.include = params.include.join(',');
|
||||
|
||||
var discussion;
|
||||
if (app.preload.response) {
|
||||
const discussion = app.preloadedDocument();
|
||||
if (discussion) {
|
||||
// We must wrap this in a setTimeout because if we are mounting this
|
||||
// component for the first time on page load, then any calls to m.redraw
|
||||
// will be ineffective and thus any configs (scroll code) will be run
|
||||
// before stuff is drawn to the page.
|
||||
setTimeout(() => {
|
||||
var discussion = app.store.pushPayload(app.preload.response);
|
||||
app.preload.response = null;
|
||||
this.setupDiscussion(discussion);
|
||||
});
|
||||
setTimeout(this.setupDiscussion.bind(this, discussion));
|
||||
} else {
|
||||
app.store.find('discussions', m.route.param('id'), params).then(this.setupDiscussion.bind(this));
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ export default class ForgotPasswordModal extends FormModal {
|
||||
|
||||
m.request({
|
||||
method: 'POST',
|
||||
url: app.config['api_url']+'/forgot',
|
||||
url: app.forum.attribute('apiUrl')+'/forgot',
|
||||
data: {email: this.email()},
|
||||
background: true,
|
||||
extract: xhr => {
|
||||
|
@@ -61,7 +61,7 @@ export default class NotificationList extends Component {
|
||||
badges && badges.length ? m('ul.badges', listItems(badges)) : '',
|
||||
group.discussion.title()
|
||||
)
|
||||
: m('div.notification-group-header', app.config['forum_title']),
|
||||
: m('div.notification-group-header', app.forum.attribute('title')),
|
||||
m('ul.notification-group-list', group.notifications.map(notification => {
|
||||
var NotificationComponent = app.notificationComponentRegistry[notification.contentType()];
|
||||
return NotificationComponent ? m('li', NotificationComponent.component({notification})) : '';
|
||||
|
@@ -45,7 +45,7 @@ export default class UserDropdown extends Component {
|
||||
ActionButton.component({
|
||||
icon: 'wrench',
|
||||
label: 'Administration',
|
||||
href: app.config['base_url']+'/admin'
|
||||
href: app.forum.attribute('baseUrl')+'/admin'
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@@ -17,8 +17,8 @@ export default class WelcomeHero extends Component {
|
||||
m('div.container', [
|
||||
m('button.close.btn.btn-icon.btn-link', {onclick: () => this.$().slideUp(this.hide.bind(this))}, m('i.fa.fa-times')),
|
||||
m('div.container-narrow', [
|
||||
m('h2', app.config['welcome_title']),
|
||||
m('div.subtitle', m.trust(app.config['welcome_message']))
|
||||
m('h2', app.forum.attribute('welcomeTitle')),
|
||||
m('div.subtitle', m.trust(app.forum.attribute('welcomeMessage')))
|
||||
])
|
||||
])
|
||||
])
|
||||
|
@@ -1,9 +1,9 @@
|
||||
export default function(app) {
|
||||
if (app.preload.data) {
|
||||
app.store.pushPayload({data: app.preload.data});
|
||||
}
|
||||
app.store.pushPayload({data: app.preload.data});
|
||||
app.forum = app.store.getById('forums', 1);
|
||||
|
||||
if (app.preload.session) {
|
||||
app.session.token(app.preload.session.token);
|
||||
app.session.user(app.store.getById('users', app.preload.session.userId));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import Store from 'flarum/store';
|
||||
import Forum from 'flarum/models/forum';
|
||||
import User from 'flarum/models/user';
|
||||
import Discussion from 'flarum/models/discussion';
|
||||
import Post from 'flarum/models/post';
|
||||
@@ -9,10 +10,13 @@ import Notification from 'flarum/models/notification';
|
||||
export default function(app) {
|
||||
app.store = new Store();
|
||||
|
||||
app.store.models['users'] = User;
|
||||
app.store.models['discussions'] = Discussion;
|
||||
app.store.models['posts'] = Post;
|
||||
app.store.models['groups'] = Group;
|
||||
app.store.models['activity'] = Activity;
|
||||
app.store.models['notifications'] = Notification;
|
||||
};
|
||||
app.store.models = {
|
||||
forums: Forum,
|
||||
users: User,
|
||||
discussions: Discussion,
|
||||
posts: Post,
|
||||
groups: Group,
|
||||
activity: Activity,
|
||||
notifications: Notification
|
||||
};
|
||||
}
|
||||
|
@@ -10,6 +10,10 @@ export default class Model {
|
||||
return this.data().id;
|
||||
}
|
||||
|
||||
attribute(attribute) {
|
||||
return this.data().attributes[attribute];
|
||||
}
|
||||
|
||||
pushData(newData) {
|
||||
var data = this.data();
|
||||
|
||||
@@ -90,7 +94,7 @@ export default class Model {
|
||||
|
||||
return app.request({
|
||||
method: this.exists ? 'PATCH' : 'POST',
|
||||
url: app.config['api_url']+'/'+this.data().type+(this.exists ? '/'+this.data().id : ''),
|
||||
url: app.forum.attribute('apiUrl')+'/'+this.data().type+(this.exists ? '/'+this.data().id : ''),
|
||||
data: {data},
|
||||
background: true,
|
||||
config: app.session.authorize.bind(app.session)
|
||||
@@ -108,7 +112,7 @@ export default class Model {
|
||||
|
||||
return app.request({
|
||||
method: 'DELETE',
|
||||
url: app.config['api_url']+'/'+this.data().type+'/'+this.data().id,
|
||||
url: app.forum.attribute('apiUrl')+'/'+this.data().type+'/'+this.data().id,
|
||||
background: true,
|
||||
config: app.session.authorize.bind(app.session)
|
||||
}).then(() => this.exists = false);
|
||||
|
5
framework/core/js/lib/models/forum.js
Normal file
5
framework/core/js/lib/models/forum.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import Model from 'flarum/model';
|
||||
|
||||
class Forum extends Model {}
|
||||
|
||||
export default Forum;
|
@@ -13,7 +13,7 @@ export default class Session extends mixin(class {}, evented) {
|
||||
var self = this;
|
||||
m.request({
|
||||
method: 'POST',
|
||||
url: app.config['base_url']+'/login',
|
||||
url: app.forum.attribute('baseUrl')+'/login',
|
||||
data: {identification, password},
|
||||
background: true
|
||||
}).then(function(response) {
|
||||
@@ -32,7 +32,7 @@ export default class Session extends mixin(class {}, evented) {
|
||||
}
|
||||
|
||||
logout() {
|
||||
window.location = app.config['base_url']+'/logout';
|
||||
window.location = app.forum.attribute('baseUrl')+'/logout?token='+this.token();
|
||||
}
|
||||
|
||||
authorize(xhr) {
|
||||
|
@@ -38,7 +38,7 @@ export default class Store {
|
||||
}
|
||||
return app.request({
|
||||
method: 'GET',
|
||||
url: app.config['api_url']+'/'+endpoint,
|
||||
url: app.forum.attribute('apiUrl')+'/'+endpoint,
|
||||
data: params,
|
||||
background: true,
|
||||
config: app.session.authorize.bind(app.session)
|
||||
|
@@ -15,8 +15,17 @@ class App {
|
||||
this.initializers.toArray().forEach((initializer) => initializer(this));
|
||||
}
|
||||
|
||||
preloadedDocument() {
|
||||
if (app.preload.document) {
|
||||
const results = app.store.pushPayload(app.preload.document);
|
||||
app.preload.document = null;
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
setTitle(title) {
|
||||
document.title = (title ? title+' - ' : '')+this.config['forum_title'];
|
||||
document.title = (title ? title+' - ' : '')+this.forum.attribute('title');
|
||||
}
|
||||
|
||||
request(options) {
|
||||
|
Reference in New Issue
Block a user