2017-02-18 09:00:14 +09:00
|
|
|
/**
|
|
|
|
* Mobile App Router
|
|
|
|
*/
|
|
|
|
|
2017-03-18 20:05:11 +09:00
|
|
|
import * as riot from 'riot';
|
2017-11-13 18:05:35 +09:00
|
|
|
import * as route from 'page';
|
2017-11-16 03:06:52 +09:00
|
|
|
import MiOS from '../common/mios';
|
2017-02-18 09:00:14 +09:00
|
|
|
let page = null;
|
|
|
|
|
2017-11-16 03:06:52 +09:00
|
|
|
export default (mios: MiOS) => {
|
2017-02-18 09:00:14 +09:00
|
|
|
route('/', index);
|
2017-11-01 03:31:36 +09:00
|
|
|
route('/selectdrive', selectDrive);
|
2017-02-18 09:00:14 +09:00
|
|
|
route('/i/notifications', notifications);
|
|
|
|
route('/i/messaging', messaging);
|
|
|
|
route('/i/messaging/:username', messaging);
|
|
|
|
route('/i/drive', drive);
|
|
|
|
route('/i/drive/folder/:folder', drive);
|
|
|
|
route('/i/drive/file/:file', drive);
|
|
|
|
route('/i/settings', settings);
|
2017-08-28 19:43:24 +09:00
|
|
|
route('/i/settings/profile', settingsProfile);
|
2017-02-18 09:00:14 +09:00
|
|
|
route('/i/settings/signin-history', settingsSignin);
|
|
|
|
route('/i/settings/twitter', settingsTwitter);
|
|
|
|
route('/i/settings/authorized-apps', settingsAuthorizedApps);
|
|
|
|
route('/post/new', newPost);
|
|
|
|
route('/post::post', post);
|
2017-12-21 04:01:44 +09:00
|
|
|
route('/search', search);
|
2017-08-30 01:37:33 +09:00
|
|
|
route('/:user', user.bind(null, 'overview'));
|
2017-02-18 09:00:14 +09:00
|
|
|
route('/:user/graphs', user.bind(null, 'graphs'));
|
|
|
|
route('/:user/followers', userFollowers);
|
|
|
|
route('/:user/following', userFollowing);
|
|
|
|
route('/:user/:post', post);
|
|
|
|
route('*', notFound);
|
|
|
|
|
|
|
|
function index() {
|
2017-11-16 03:06:52 +09:00
|
|
|
mios.isSignedin ? home() : entrance();
|
2017-02-18 09:00:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function home() {
|
|
|
|
mount(document.createElement('mk-home-page'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function entrance() {
|
|
|
|
mount(document.createElement('mk-entrance'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function notifications() {
|
|
|
|
mount(document.createElement('mk-notifications-page'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function messaging(ctx) {
|
|
|
|
if (ctx.params.username) {
|
|
|
|
const el = document.createElement('mk-messaging-room-page');
|
|
|
|
el.setAttribute('username', ctx.params.username);
|
|
|
|
mount(el);
|
|
|
|
} else {
|
|
|
|
mount(document.createElement('mk-messaging-page'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function newPost() {
|
|
|
|
mount(document.createElement('mk-new-post-page'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function settings() {
|
|
|
|
mount(document.createElement('mk-settings-page'));
|
|
|
|
}
|
|
|
|
|
2017-08-28 19:43:24 +09:00
|
|
|
function settingsProfile() {
|
|
|
|
mount(document.createElement('mk-profile-setting-page'));
|
|
|
|
}
|
|
|
|
|
2017-02-18 09:00:14 +09:00
|
|
|
function settingsSignin() {
|
|
|
|
mount(document.createElement('mk-signin-history-page'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function settingsTwitter() {
|
|
|
|
mount(document.createElement('mk-twitter-setting-page'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function settingsAuthorizedApps() {
|
|
|
|
mount(document.createElement('mk-authorized-apps-page'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function search(ctx) {
|
|
|
|
const el = document.createElement('mk-search-page');
|
2017-12-21 04:01:44 +09:00
|
|
|
el.setAttribute('query', ctx.querystring.substr(2));
|
2017-02-18 09:00:14 +09: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 userFollowing(ctx) {
|
|
|
|
const el = document.createElement('mk-user-following-page');
|
|
|
|
el.setAttribute('user', ctx.params.user);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
function userFollowers(ctx) {
|
|
|
|
const el = document.createElement('mk-user-followers-page');
|
|
|
|
el.setAttribute('user', ctx.params.user);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
function post(ctx) {
|
|
|
|
const el = document.createElement('mk-post-page');
|
|
|
|
el.setAttribute('post', ctx.params.post);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
function drive(ctx) {
|
|
|
|
const el = document.createElement('mk-drive-page');
|
|
|
|
if (ctx.params.folder) el.setAttribute('folder', ctx.params.folder);
|
|
|
|
if (ctx.params.file) el.setAttribute('file', ctx.params.file);
|
|
|
|
mount(el);
|
|
|
|
}
|
|
|
|
|
2017-11-01 03:31:36 +09:00
|
|
|
function selectDrive() {
|
|
|
|
mount(document.createElement('mk-selectdrive-page'));
|
|
|
|
}
|
|
|
|
|
2017-02-18 09:00:14 +09:00
|
|
|
function notFound() {
|
|
|
|
mount(document.createElement('mk-not-found'));
|
|
|
|
}
|
|
|
|
|
2017-11-13 18:05:35 +09:00
|
|
|
(riot as any).mixin('page', {
|
2017-02-18 09:00:14 +09:00
|
|
|
page: route
|
|
|
|
});
|
|
|
|
|
|
|
|
// EXEC
|
2017-11-13 18:05:35 +09:00
|
|
|
(route as any)();
|
2017-02-18 09:00:14 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
function mount(content) {
|
2017-08-28 19:43:24 +09:00
|
|
|
document.documentElement.style.background = '#fff';
|
2017-02-18 09:00:14 +09:00
|
|
|
if (page) page.unmount();
|
|
|
|
const body = document.getElementById('app');
|
|
|
|
page = riot.mount(body.appendChild(content))[0];
|
|
|
|
}
|