This commit is contained in:
syuilo 2017-11-21 12:40:48 +09:00
parent e5eaa5b6e7
commit ed18d3cc22
2 changed files with 14 additions and 1 deletions

View file

@ -198,6 +198,7 @@ export default class MiOS extends EventEmitter {
fetchme(cachedMe.token, freshData => { fetchme(cachedMe.token, freshData => {
Object.assign(cachedMe, freshData); Object.assign(cachedMe, freshData);
cachedMe.trigger('updated'); cachedMe.trigger('updated');
cachedMe.trigger('refreshed');
}); });
} else { } else {
// Get token from cookie // Get token from cookie

View file

@ -193,11 +193,16 @@
this.home = []; this.home = [];
this.bakeHomeData = () => JSON.stringify(this.I.client_settings.home);
this.bakedHomeData = this.bakeHomeData();
this.on('mount', () => { this.on('mount', () => {
this.refs.tl.on('loaded', () => { this.refs.tl.on('loaded', () => {
this.trigger('loaded'); this.trigger('loaded');
}); });
this.I.on('refreshed', this.onMeRefreshed);
this.I.client_settings.home.forEach(widget => { this.I.client_settings.home.forEach(widget => {
try { try {
this.setWidget(widget); this.setWidget(widget);
@ -256,6 +261,8 @@
}); });
this.on('unmount', () => { this.on('unmount', () => {
this.I.off('refreshed', this.onMeRefreshed);
this.home.forEach(widget => { this.home.forEach(widget => {
widget.unmount(); widget.unmount();
}); });
@ -266,6 +273,12 @@
} }
}); });
this.onMeRefreshed = () => {
if (this.bakedHomeData != this.bakeHomeData()) {
alert('別の場所でホームが編集されました。ページを再度読み込みすると編集が反映されます。');
}
};
this.setWidget = (widget, prepend = false) => { this.setWidget = (widget, prepend = false) => {
const el = document.createElement(`mk-${widget.name}-home-widget`); const el = document.createElement(`mk-${widget.name}-home-widget`);
@ -366,7 +379,6 @@
this.api('i/update_home', { this.api('i/update_home', {
home: data home: data
}).then(() => { }).then(() => {
this.I.client_settings.home = data;
this.I.update(); this.I.update();
}); });
}; };