Closes #12, #227 and #58
This commit is contained in:
syuilo
2017-03-18 20:05:11 +09:00
parent 2496cece91
commit 45e8331e26
150 changed files with 610 additions and 609 deletions

View File

@@ -1,25 +0,0 @@
const riot = require('riot');
module.exports = me => {
if (me) {
require('./scripts/stream')(me);
}
require('./scripts/ui');
riot.mixin('open-post-form', {
openPostForm: opts => {
const app = document.getElementById('app');
app.style.display = 'none';
function recover() {
app.style.display = 'block';
}
const form = riot.mount(document.body.appendChild(document.createElement('mk-post-form')), opts)[0];
form
.on('cancel', recover)
.on('post', recover);
}
});
};

View File

@@ -2,11 +2,11 @@
* Mobile App Router
*/
const riot = require('riot');
import * as riot from 'riot';
const route = require('page');
let page = null;
module.exports = me => {
export default me => {
route('/', index);
route('/i/notifications', notifications);
route('/i/messaging', messaging);

View File

@@ -6,9 +6,8 @@
import './style.styl';
require('./tags');
const boot = require('../boot');
const mixins = require('./mixins');
const route = require('./router');
import boot from '../boot';
import route from './router';
/**
* Boot
@@ -17,9 +16,6 @@ boot(me => {
// http://qiita.com/junya/items/3ff380878f26ca447f85
document.body.setAttribute('ontouchstart', '');
// Register mixins
mixins(me);
// Start routing
route(me);
});

View File

@@ -0,0 +1,15 @@
import * as riot from 'riot';
export default opts => {
const app = document.getElementById('app');
app.style.display = 'none';
function recover() {
app.style.display = 'block';
}
const form = riot.mount(document.body.appendChild(document.createElement('mk-post-form')), opts)[0];
form
.on('cancel', recover)
.on('post', recover);
};

View File

@@ -1,11 +0,0 @@
const stream = require('../../common/scripts/stream');
const riot = require('riot');
module.exports = me => {
const s = stream(me);
riot.mixin('stream', {
stream: s.event,
getStreamState: s.getState,
streamStateEv: s.stateEv
});
};

View File

@@ -0,0 +1,5 @@
import * as riot from 'riot';
const ev = riot.observable();
export default ev;

View File

@@ -1,7 +0,0 @@
const riot = require('riot');
const ui = riot.observable();
riot.mixin('ui', {
ui: ui
});

View File

@@ -133,9 +133,12 @@
</style>
<script>
this.mixin('i');
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.files = [];
this.folders = [];
this.hierarchyFolders = [];
@@ -151,10 +154,10 @@
this.multiple =this.opts.multiple;
this.on('mount', () => {
this.stream.on('drive_file_created', this.onStreamDriveFileCreated);
this.stream.on('drive_file_updated', this.onStreamDriveFileUpdated);
this.stream.on('drive_folder_created', this.onStreamDriveFolderCreated);
this.stream.on('drive_folder_updated', this.onStreamDriveFolderUpdated);
stream.on('drive_file_created', this.onStreamDriveFileCreated);
stream.on('drive_file_updated', this.onStreamDriveFileUpdated);
stream.on('drive_folder_created', this.onStreamDriveFolderCreated);
stream.on('drive_folder_updated', this.onStreamDriveFolderUpdated);
// Riotのバグでnullを渡しても""になる
// https://github.com/riot/riot/issues/2080
@@ -170,10 +173,10 @@
});
this.on('unmount', () => {
this.stream.off('drive_file_created', this.onStreamDriveFileCreated);
this.stream.off('drive_file_updated', this.onStreamDriveFileUpdated);
this.stream.off('drive_folder_created', this.onStreamDriveFolderCreated);
this.stream.off('drive_folder_updated', this.onStreamDriveFolderUpdated);
stream.off('drive_file_created', this.onStreamDriveFileCreated);
stream.off('drive_file_updated', this.onStreamDriveFileUpdated);
stream.off('drive_folder_created', this.onStreamDriveFolderCreated);
stream.off('drive_folder_updated', this.onStreamDriveFolderUpdated);
});
this.onStreamDriveFileCreated = file => {

View File

@@ -11,9 +11,9 @@
</span>
<span class="separator"></span>
<span class="aspect-ratio">
<span class="width">{ file.properties.width / getGcd(file.properties.width, file.properties.height) }</span>
<span class="width">{ file.properties.width / gcd(file.properties.width, file.properties.height) }</span>
<span class="colon">:</span>
<span class="height">{ file.properties.height / getGcd(file.properties.width, file.properties.height) }</span>
<span class="height">{ file.properties.height / gcd(file.properties.width, file.properties.height) }</span>
</span>
</footer>
</div>
@@ -184,8 +184,11 @@
</style>
<script>
this.bytesToSize = require('../../../common/scripts/bytes-to-size.js');
this.getGcd = require('../../../common/scripts/gcd.js');
import bytesToSize from '../../../common/scripts/bytes-to-size';
import gcd from '../../../common/scripts/gcd';
this.bytesToSize = bytesToSize;
this.gcd = gcd;
this.mixin('api');

View File

@@ -122,7 +122,8 @@
</style>
<script>
this.bytesToSize = require('../../../common/scripts/bytes-to-size');
import bytesToSize from '../../../common/scripts/bytes-to-size';
this.bytesToSize = bytesToSize;
this.browser = this.parent;
this.file = this.opts.file;

View File

@@ -48,12 +48,16 @@
</style>
<script>
this.mixin('i');
this.mixin('api');
this.mixin('is-promise');
this.mixin('stream');
const stream = this.stream.event;
const isPromise = require('../../common/scripts/is-promise');
this.user = null;
this.userPromise = this.isPromise(this.opts.user)
this.userPromise = isPromise(this.opts.user)
? this.opts.user
: Promise.resolve(this.opts.user);
this.init = true;
@@ -65,14 +69,14 @@
init: false,
user: user
});
this.stream.on('follow', this.onStreamFollow);
this.stream.on('unfollow', this.onStreamUnfollow);
stream.on('follow', this.onStreamFollow);
stream.on('unfollow', this.onStreamUnfollow);
});
});
this.on('unmount', () => {
this.stream.off('follow', this.onStreamFollow);
this.stream.off('unfollow', this.onStreamUnfollow);
stream.off('follow', this.onStreamFollow);
stream.off('unfollow', this.onStreamUnfollow);
});
this.onStreamFollow = user => {

View File

@@ -5,9 +5,12 @@
display block
</style>
<script>
this.mixin('i');
this.mixin('api');
this.mixin('stream');
const stream = this.stream.event;
this.init = new Promise((res, rej) => {
this.api('posts/timeline').then(posts => {
res(posts);
@@ -16,15 +19,15 @@
});
this.on('mount', () => {
this.stream.on('post', this.onStreamPost);
this.stream.on('follow', this.onStreamFollow);
this.stream.on('unfollow', this.onStreamUnfollow);
stream.on('post', this.onStreamPost);
stream.on('follow', this.onStreamFollow);
stream.on('unfollow', this.onStreamUnfollow);
});
this.on('unmount', () => {
this.stream.off('post', this.onStreamPost);
this.stream.off('follow', this.onStreamFollow);
this.stream.off('unfollow', this.onStreamUnfollow);
stream.off('post', this.onStreamPost);
stream.off('follow', this.onStreamFollow);
stream.off('unfollow', this.onStreamUnfollow);
});
this.more = () => {

View File

@@ -107,7 +107,8 @@
</style>
<script>
this.mixin('get-post-summary');
import getPostSummary from '../../common/scripts/get-post-summary';
this.getPostSummary = getPostSummary;
this.notification = this.opts.notification;
</script>
</mk-notification-preview>

View File

@@ -167,7 +167,8 @@
</style>
<script>
this.mixin('get-post-summary');
import getPostSummary from '../../common/scripts/get-post-summary';
this.getPostSummary = getPostSummary;
this.notification = this.opts.notification;
</script>
</mk-notification>

View File

@@ -57,9 +57,13 @@
</style>
<script>
import getPostSummary from '../../common/scripts/get-post-summary';
this.getPostSummary = getPostSummary;
this.mixin('api');
this.mixin('stream');
this.mixin('get-post-summary');
const stream = this.stream.event;
this.notifications = [];
this.loading = true;
@@ -74,11 +78,11 @@
this.trigger('fetched');
});
this.stream.on('notification', this.onNotification);
stream.on('notification', this.onNotification);
});
this.on('unmount', () => {
this.stream.off('notification', this.onNotification);
stream.off('notification', this.onNotification);
});
this.onNotification = notification => {

View File

@@ -7,27 +7,27 @@
display block
</style>
<script>
this.mixin('ui');
this.mixin('ui-progress');
import ui from '../../scripts/ui-event';
import Progress from '../../../common/scripts/loading';
this.on('mount', () => {
document.title = 'Misskey Drive';
this.ui.trigger('title', '<i class="fa fa-cloud"></i>ドライブ');
ui.trigger('title', '<i class="fa fa-cloud"></i>ドライブ');
this.ui.trigger('func', () => {
ui.trigger('func', () => {
this.refs.ui.refs.browser.openContextMenu();
}, 'ellipsis-h');
this.refs.ui.refs.browser.on('begin-fetch', () => {
this.Progress.start();
Progress.start();
});
this.refs.ui.refs.browser.on('fetched-mid', () => {
this.Progress.set(0.5);
Progress.set(0.5);
});
this.refs.ui.refs.browser.on('fetched', () => {
this.Progress.done();
Progress.done();
});
this.refs.ui.refs.browser.on('move-root', () => {
@@ -37,7 +37,7 @@
history.pushState(null, title, '/i/drive');
document.title = title;
this.ui.trigger('title', '<i class="fa fa-cloud"></i>ドライブ');
ui.trigger('title', '<i class="fa fa-cloud"></i>ドライブ');
});
this.refs.ui.refs.browser.on('open-folder', (folder, silent) => {
@@ -50,7 +50,7 @@
document.title = title;
// TODO: escape html characters in folder.name
this.ui.trigger('title', '<i class="fa fa-folder-open"></i>' + folder.name);
ui.trigger('title', '<i class="fa fa-folder-open"></i>' + folder.name);
});
this.refs.ui.refs.browser.on('open-file', (file, silent) => {
@@ -63,7 +63,7 @@
document.title = title;
// TODO: escape html characters in file.name
this.ui.trigger('title', '<mk-file-type-icon class="icon"></mk-file-type-icon>' + file.name);
ui.trigger('title', '<mk-file-type-icon class="icon"></mk-file-type-icon>' + file.name);
riot.mount('mk-file-type-icon', {
type: file.type
});

View File

@@ -7,42 +7,45 @@
display block
</style>
<script>
import ui from '../../scripts/ui-event';
import Progress from '../../../common/scripts/loading';
import getPostSummary from '../../../common/scripts/get-post-summary';
import openPostForm from '../../scripts/open-post-form';
this.mixin('i');
this.mixin('ui');
this.mixin('ui-progress');
this.mixin('stream');
this.mixin('get-post-summary');
this.mixin('open-post-form');
const stream = this.stream.event;
this.unreadCount = 0;
this.on('mount', () => {
document.title = 'Misskey'
this.ui.trigger('title', '<i class="fa fa-home"></i>ホーム');
ui.trigger('title', '<i class="fa fa-home"></i>ホーム');
this.ui.trigger('func', () => {
this.openPostForm();
ui.trigger('func', () => {
openPostForm();
}, 'pencil');
this.Progress.start();
Progress.start();
this.stream.on('post', this.onStreamPost);
stream.on('post', this.onStreamPost);
document.addEventListener('visibilitychange', this.onVisibilitychange, false);
this.refs.ui.refs.home.on('loaded', () => {
this.Progress.done();
Progress.done();
});
});
this.on('unmount', () => {
this.stream.off('post', this.onStreamPost);
stream.off('post', this.onStreamPost);
document.removeEventListener('visibilitychange', this.onVisibilitychange);
});
this.onStreamPost = post => {
if (document.hidden && post.user_id !== this.I.id) {
this.unreadCount++;
document.title = `(${this.unreadCount}) ${this.getPostSummary(post)}`;
document.title = `(${this.unreadCount}) ${getPostSummary(post)}`;
}
};

View File

@@ -7,8 +7,9 @@
display block
</style>
<script>
import ui from '../../scripts/ui-event';
this.mixin('api');
this.mixin('ui');
this.fetching = true;
@@ -23,7 +24,7 @@
document.title = `メッセージ: ${user.name} | Misskey`;
// TODO: ユーザー名をエスケープ
this.ui.trigger('title', '<i class="fa fa-comments-o"></i>' + user.name);
ui.trigger('title', '<i class="fa fa-comments-o"></i>' + user.name);
});
});
</script>

View File

@@ -7,12 +7,13 @@
display block
</style>
<script>
this.mixin('ui');
import ui from '../../scripts/ui-event';
this.mixin('page');
this.on('mount', () => {
document.title = 'Misskey | メッセージ';
this.ui.trigger('title', '<i class="fa fa-comments-o"></i>メッセージ');
ui.trigger('title', '<i class="fa fa-comments-o"></i>メッセージ');
this.refs.ui.refs.index.on('navigate-user', user => {
this.page('/i/messaging/' + user.username);

View File

@@ -5,20 +5,19 @@
<style>
:scope
display block
</style>
<script>
this.mixin('ui');
this.mixin('ui-progress');
import ui from '../../scripts/ui-event';
import Progress from '../../../common/scripts/loading';
this.on('mount', () => {
document.title = 'Misskey | 通知';
this.ui.trigger('title', '<i class="fa fa-bell-o"></i>通知');
ui.trigger('title', '<i class="fa fa-bell-o"></i>通知');
this.Progress.start();
Progress.start();
this.refs.ui.refs.notifications.on('fetched', () => {
this.Progress.done();
Progress.done();
});
});
</script>

View File

@@ -18,23 +18,23 @@
</style>
<script>
this.mixin('ui');
this.mixin('ui-progress');
import ui from '../../scripts/ui-event';
import Progress from '../../../common/scripts/loading';
this.post = this.opts.post;
this.on('mount', () => {
document.title = 'Misskey';
this.ui.trigger('title', '<i class="fa fa-sticky-note-o"></i>投稿');
ui.trigger('title', '<i class="fa fa-sticky-note-o"></i>投稿');
this.Progress.start();
Progress.start();
this.refs.ui.refs.post.on('post-fetched', () => {
this.Progress.set(0.5);
Progress.set(0.5);
});
this.refs.ui.refs.post.on('loaded', () => {
this.Progress.done();
Progress.done();
});
});
</script>

View File

@@ -7,18 +7,18 @@
display block
</style>
<script>
this.mixin('ui');
this.mixin('ui-progress');
import ui from '../../scripts/ui-event';
import Progress from '../../../common/scripts/loading';
this.on('mount', () => {
document.title = `検索: ${this.opts.query} | Misskey`
// TODO: クエリをHTMLエスケープ
this.ui.trigger('title', '<i class="fa fa-search"></i>' + this.opts.query);
ui.trigger('title', '<i class="fa fa-search"></i>' + this.opts.query);
this.Progress.start();
Progress.start();
this.refs.ui.refs.search.on('loaded', () => {
this.Progress.done();
Progress.done();
});
});
</script>

View File

@@ -13,11 +13,11 @@
display block
</style>
<script>
this.mixin('ui');
import ui from '../../scripts/ui-event';
this.on('mount', () => {
document.title = 'Misskey | 設定';
this.ui.trigger('title', '<i class="fa fa-cog"></i>設定');
ui.trigger('title', '<i class="fa fa-cog"></i>設定');
});
</script>
</mk-settings-page>

View File

@@ -7,11 +7,11 @@
display block
</style>
<script>
this.mixin('ui');
const ui = require('../../../scripts/ui-event');
this.on('mount', () => {
document.title = 'Misskey | API';
this.ui.trigger('title', '<i class="fa fa-key"></i>API');
ui.trigger('title', '<i class="fa fa-key"></i>API');
});
</script>
</mk-api-info-page>

View File

@@ -7,11 +7,11 @@
display block
</style>
<script>
this.mixin('ui');
const ui = require('../../../scripts/ui-event');
this.on('mount', () => {
document.title = 'Misskey | アプリケーション';
this.ui.trigger('title', '<i class="fa fa-puzzle-piece"></i>アプリケーション');
ui.trigger('title', '<i class="fa fa-puzzle-piece"></i>アプリケーション');
});
</script>
</mk-authorized-apps-page>

View File

@@ -7,11 +7,11 @@
display block
</style>
<script>
this.mixin('ui');
const ui = require('../../../scripts/ui-event');
this.on('mount', () => {
document.title = 'Misskey | ログイン履歴';
this.ui.trigger('title', '<i class="fa fa-sign-in"></i>ログイン履歴');
ui.trigger('title', '<i class="fa fa-sign-in"></i>ログイン履歴');
});
</script>
</mk-signin-history-page>

View File

@@ -7,11 +7,11 @@
display block
</style>
<script>
this.mixin('ui');
const ui = require('../../../scripts/ui-event');
this.on('mount', () => {
document.title = 'Misskey | Twitter連携';
this.ui.trigger('title', '<i class="fa fa-twitter"></i>Twitter連携');
ui.trigger('title', '<i class="fa fa-twitter"></i>Twitter連携');
});
</script>
</mk-twitter-setting-page>

View File

@@ -7,15 +7,16 @@
display block
</style>
<script>
this.mixin('ui');
this.mixin('ui-progress');
import ui from '../../scripts/ui-event';
import Progress from '../../../common/scripts/loading';
this.mixin('api');
this.fetching = true;
this.user = null;
this.on('mount', () => {
this.Progress.start();
Progress.start();
this.api('users/show', {
username: this.opts.user
@@ -27,10 +28,10 @@
document.title = user.name + 'のフォロワー | Misskey';
// TODO: ユーザー名をエスケープ
this.ui.trigger('title', '<img src="' + user.avatar_url + '?thumbnail&size=64">' + user.name + 'のフォロワー');
ui.trigger('title', '<img src="' + user.avatar_url + '?thumbnail&size=64">' + user.name + 'のフォロワー');
this.refs.ui.refs.list.on('loaded', () => {
this.Progress.done();
Progress.done();
});
});
});

View File

@@ -7,15 +7,16 @@
display block
</style>
<script>
this.mixin('ui');
this.mixin('ui-progress');
import ui from '../../scripts/ui-event';
import Progress from '../../../common/scripts/loading';
this.mixin('api');
this.fetching = true;
this.user = null;
this.on('mount', () => {
this.Progress.start();
Progress.start();
this.api('users/show', {
username: this.opts.user
@@ -27,10 +28,10 @@
document.title = user.name + 'のフォロー | Misskey';
// TODO: ユーザー名をエスケープ
this.ui.trigger('title', '<img src="' + user.avatar_url + '?thumbnail&size=64">' + user.name + 'のフォロー');
ui.trigger('title', '<img src="' + user.avatar_url + '?thumbnail&size=64">' + user.name + 'のフォロー');
this.refs.ui.refs.list.on('loaded', () => {
this.Progress.done();
Progress.done();
});
});
});

View File

@@ -5,22 +5,21 @@
<style>
:scope
display block
</style>
<script>
this.mixin('ui');
this.mixin('ui-progress');
import ui from '../../scripts/ui-event';
import Progress from '../../../common/scripts/loading';
this.user = this.opts.user;
this.on('mount', () => {
this.Progress.start();
Progress.start();
this.refs.ui.refs.user.on('loaded', user => {
this.Progress.done();
Progress.done();
document.title = user.name + ' | Misskey';
// TODO: ユーザー名をエスケープ
this.ui.trigger('title', '<i class="fa fa-user"></i>' + user.name);
ui.trigger('title', '<i class="fa fa-user"></i>' + user.name);
});
});
</script>

View File

@@ -342,9 +342,11 @@
</style>
<script>
this.mixin('api');
this.mixin('text');
this.mixin('get-post-summary');
this.mixin('open-post-form');
import compile from '../../common/scripts/text-compiler';
this.getPostSummary = require('../../common/scripts/get-post-summary');
this.openPostForm = require('../scripts/open-post-form');
this.fetching = true;
this.loadingContext = false;
@@ -368,9 +370,9 @@
this.trigger('loaded');
if (this.p.text) {
const tokens = this.analyze(this.p.text);
const tokens = this.p.ast;
this.refs.text.innerHTML = this.compile(tokens);
this.refs.text.innerHTML = compile(tokens);
this.refs.text.children.forEach(e => {
if (e.tagName == 'MK-URL') riot.mount(e);

View File

@@ -182,7 +182,7 @@
</style>
<script>
const getCat = require('../../common/scripts/get-cat');
import getCat from '../../common/scripts/get-cat';
this.mixin('api');

View File

@@ -28,14 +28,14 @@
</style>
<script>
this.mixin('text');
import compile from '../../common/scripts/text-compiler';
this.post = this.opts.post;
this.on('mount', () => {
if (this.post.text) {
const tokens = this.analyze(this.post.text);
this.refs.text.innerHTML = this.compile(tokens, false);
const tokens = this.post.ast;
this.refs.text.innerHTML = compile(tokens, false);
this.refs.text.children.forEach(e => {
if (e.tagName == 'MK-URL') riot.mount(e);

View File

@@ -306,21 +306,22 @@
</style>
<script>
this.mixin('api');
this.mixin('text');
this.mixin('get-post-summary');
this.mixin('open-post-form');
import compile from '../../common/scripts/text-compiler';
import getPostSummary from '../../common/scripts/get-post-summary';
import openPostForm from '../scripts/open-post-form';
this.post = this.opts.post;
this.isRepost = this.post.repost != null && this.post.text == null;
this.p = this.isRepost ? this.post.repost : this.post;
this.summary = this.getPostSummary(this.p);
this.summary = getPostSummary(this.p);
this.url = `/${this.p.user.username}/${this.p.id}`;
this.on('mount', () => {
if (this.p.text) {
const tokens = this.analyze(this.p.text);
const tokens = this.p.ast;
this.refs.text.innerHTML = this.refs.text.innerHTML.replace('<p class="dummy"></p>', this.compile(tokens));
this.refs.text.innerHTML = this.refs.text.innerHTML.replace('<p class="dummy"></p>', compile(tokens));
this.refs.text.children.forEach(e => {
if (e.tagName == 'MK-URL') riot.mount(e);
@@ -338,7 +339,7 @@
});
this.reply = () => {
this.openPostForm({
openPostForm({
reply: this.p
});
};

View File

@@ -88,14 +88,14 @@
</style>
<script>
this.mixin('ui');
import ui from '../scripts/ui-event';
this.func = null;
this.funcIcon = null;
this.on('unmount', () => {
this.ui.off('title', this.setTitle);
this.ui.off('func', this.setFunc);
ui.off('title', this.setTitle);
ui.off('func', this.setFunc);
});
this.setTitle = title => {
@@ -109,7 +109,7 @@
});
};
this.ui.on('title', this.setTitle);
this.ui.on('func', this.setFunc);
ui.on('title', this.setTitle);
ui.on('func', this.setFunc);
</script>
</mk-ui-header>

View File

@@ -11,16 +11,20 @@
padding-top 48px
</style>
<script>
this.mixin('i');
this.mixin('stream');
const stream = this.stream.event;
this.isDrawerOpening = false;
this.on('mount', () => {
this.stream.on('notification', this.onStreamNotification);
stream.on('notification', this.onStreamNotification);
});
this.on('unmount', () => {
this.stream.off('notification', this.onStreamNotification);
stream.off('notification', this.onStreamNotification);
});
this.toggleDrawer = () => {