2017-02-18 00:07:24 +00:00
|
|
|
/**
|
|
|
|
* Desktop App Router
|
|
|
|
*/
|
|
|
|
|
2017-03-18 11:05:11 +00:00
|
|
|
import * as riot from 'riot';
|
2017-11-13 09:05:35 +00:00
|
|
|
import * as route from 'page';
|
2017-11-15 18:06:52 +00:00
|
|
|
import MiOS from '../common/mios';
|
2017-02-18 00:07:24 +00:00
|
|
|
let page = null;
|
|
|
|
|
2017-11-15 18:06:52 +00:00
|
|
|
export default (mios: MiOS) => {
|
2017-11-08 11:03:58 +00:00
|
|
|
route('/', index);
|
|
|
|
route('/selectdrive', selectDrive);
|
2017-11-08 14:43:47 +00:00
|
|
|
route('/i/customize-home', customizeHome);
|
2017-11-08 11:03:58 +00:00
|
|
|
route('/i/drive', drive);
|
|
|
|
route('/i/drive/folder/:folder', drive);
|
2017-11-12 22:32:47 +00:00
|
|
|
route('/i/messaging/:user', messaging);
|
2017-11-08 11:03:58 +00:00
|
|
|
route('/i/mentions', mentions);
|
|
|
|
route('/post::post', post);
|
2017-12-20 19:01:44 +00:00
|
|
|
route('/search', search);
|
2017-11-08 11:03:58 +00:00
|
|
|
route('/:user', user.bind(null, 'home'));
|
|
|
|
route('/:user/graphs', user.bind(null, 'graphs'));
|
|
|
|
route('/:user/:post', post);
|
|
|
|
route('*', notFound);
|
2017-02-18 00:07:24 +00:00
|
|
|
|
|
|
|
function index() {
|
2017-11-15 18:06:52 +00:00
|
|
|
mios.isSignedin ? home() : entrance();
|
2017-02-18 00:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function home() {
|
|
|
|
mount(document.createElement('mk-home-page'));
|
|
|
|
}
|
|
|
|
|
2017-11-08 14:43:47 +00:00
|
|
|
function customizeHome() {
|
|
|
|
mount(document.createElement('mk-home-customize-page'));
|
|
|
|
}
|
|
|
|
|
2017-02-18 00:07:24 +00:00
|
|
|
function entrance() {
|
|
|
|
mount(document.createElement('mk-entrance'));
|
|
|
|
document.documentElement.setAttribute('data-page', 'entrance');
|
|
|
|
}
|
|
|
|
|
|
|
|
function mentions() {
|
|
|
|
const el = document.createElement('mk-home-page');
|
|
|
|
el.setAttribute('mode', 'mentions');
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
function search(ctx) {
|
|
|
|
const el = document.createElement('mk-search-page');
|
2017-12-20 19:01:44 +00:00
|
|
|
el.setAttribute('query', ctx.querystring.substr(2));
|
2017-02-18 00:07:24 +00:00
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
function user(page, ctx) {
|
|
|
|
const el = document.createElement('mk-user-page');
|
|
|
|
el.setAttribute('user', ctx.params.user);
|
|
|
|
el.setAttribute('page', page);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
function post(ctx) {
|
|
|
|
const el = document.createElement('mk-post-page');
|
|
|
|
el.setAttribute('post', ctx.params.post);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
2017-10-31 17:16:05 +00:00
|
|
|
function selectDrive() {
|
|
|
|
mount(document.createElement('mk-selectdrive-page'));
|
|
|
|
}
|
|
|
|
|
2017-11-08 11:03:58 +00:00
|
|
|
function drive(ctx) {
|
|
|
|
const el = document.createElement('mk-drive-page');
|
|
|
|
if (ctx.params.folder) el.setAttribute('folder', ctx.params.folder);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
2017-11-12 22:32:47 +00:00
|
|
|
function messaging(ctx) {
|
|
|
|
const el = document.createElement('mk-messaging-room-page');
|
|
|
|
el.setAttribute('user', ctx.params.user);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
2017-02-18 00:07:24 +00:00
|
|
|
function notFound() {
|
|
|
|
mount(document.createElement('mk-not-found'));
|
|
|
|
}
|
|
|
|
|
2017-11-13 09:05:35 +00:00
|
|
|
(riot as any).mixin('page', {
|
2017-02-18 00:07:24 +00:00
|
|
|
page: route
|
|
|
|
});
|
|
|
|
|
|
|
|
// EXEC
|
2017-11-13 09:05:35 +00:00
|
|
|
(route as any)();
|
2017-02-18 00:07:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function mount(content) {
|
|
|
|
document.documentElement.removeAttribute('data-page');
|
|
|
|
if (page) page.unmount();
|
|
|
|
const body = document.getElementById('app');
|
|
|
|
page = riot.mount(body.appendChild(content))[0];
|
|
|
|
}
|