wip
This commit is contained in:
parent
e770cd6f55
commit
f37fb38640
25 changed files with 189 additions and 86 deletions
32
src/web/app/ch/router.js
Normal file
32
src/web/app/ch/router.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import * as riot from 'riot';
|
||||
const route = require('page');
|
||||
let page = null;
|
||||
|
||||
export default me => {
|
||||
route('/', index);
|
||||
route('/:channel', channel);
|
||||
route('*', notFound);
|
||||
|
||||
function index() {
|
||||
mount(document.createElement('mk-index'));
|
||||
}
|
||||
|
||||
function channel(ctx) {
|
||||
const el = document.createElement('mk-channel');
|
||||
el.setAttribute('id', ctx.params.channel);
|
||||
mount(el);
|
||||
}
|
||||
|
||||
function notFound() {
|
||||
mount(document.createElement('mk-not-found'));
|
||||
}
|
||||
|
||||
// EXEC
|
||||
route();
|
||||
};
|
||||
|
||||
function mount(content) {
|
||||
if (page) page.unmount();
|
||||
const body = document.getElementById('app');
|
||||
page = riot.mount(body.appendChild(content))[0];
|
||||
}
|
||||
18
src/web/app/ch/script.js
Normal file
18
src/web/app/ch/script.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* Channels
|
||||
*/
|
||||
|
||||
// Style
|
||||
import './style.styl';
|
||||
|
||||
require('./tags');
|
||||
import init from '../init';
|
||||
import route from './router';
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
init(me => {
|
||||
// Start routing
|
||||
route(me);
|
||||
});
|
||||
4
src/web/app/ch/style.styl
Normal file
4
src/web/app/ch/style.styl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
@import "../base"
|
||||
|
||||
html
|
||||
background #efefef
|
||||
204
src/web/app/ch/tags/channel.tag
Normal file
204
src/web/app/ch/tags/channel.tag
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
<mk-channel>
|
||||
<main if={ !fetching }>
|
||||
<h1>{ channel.title }</h1>
|
||||
<virtual if={ posts }>
|
||||
<mk-channel-post each={ posts.slice().reverse() } post={ this } form={ parent.refs.form }/>
|
||||
</virtual>
|
||||
<hr>
|
||||
<mk-channel-form if={ SIGNIN } channel={ channel } ref="form"/>
|
||||
<div if={ !SIGNIN }>
|
||||
<p>参加するには<a href={ CONFIG.url }>ログインまたは新規登録</a>してください</p>
|
||||
</div>
|
||||
<hr>
|
||||
<footer>
|
||||
<small>Misskey ver { version } (葵 aoi)</small>
|
||||
</footer>
|
||||
</main>
|
||||
<style>
|
||||
:scope
|
||||
display block
|
||||
|
||||
main
|
||||
padding 8px
|
||||
|
||||
> h1
|
||||
color #f00
|
||||
</style>
|
||||
<script>
|
||||
import Progress from '../../common/scripts/loading';
|
||||
import ChannelStream from '../../common/scripts/channel-stream';
|
||||
|
||||
this.mixin('i');
|
||||
this.mixin('api');
|
||||
|
||||
this.id = this.opts.id;
|
||||
this.fetching = true;
|
||||
this.channel = null;
|
||||
this.posts = null;
|
||||
this.connection = new ChannelStream(this.id);
|
||||
this.version = VERSION;
|
||||
|
||||
this.on('mount', () => {
|
||||
document.documentElement.style.background = '#efefef';
|
||||
|
||||
Progress.start();
|
||||
|
||||
this.api('channels/show', {
|
||||
channel_id: this.id
|
||||
}).then(channel => {
|
||||
Progress.done();
|
||||
|
||||
this.update({
|
||||
fetching: false,
|
||||
channel: channel
|
||||
});
|
||||
|
||||
document.title = channel.title + ' | Misskey'
|
||||
});
|
||||
|
||||
this.api('channels/posts', {
|
||||
channel_id: this.id
|
||||
}).then(posts => {
|
||||
this.update({
|
||||
posts: posts
|
||||
});
|
||||
});
|
||||
|
||||
this.connection.on('post', this.onPost);
|
||||
});
|
||||
|
||||
this.on('unmount', () => {
|
||||
this.connection.off('post', this.onPost);
|
||||
this.connection.close();
|
||||
});
|
||||
|
||||
this.onPost = post => {
|
||||
this.posts.unshift(post);
|
||||
this.update();
|
||||
};
|
||||
|
||||
</script>
|
||||
</mk-channel>
|
||||
|
||||
<mk-channel-post>
|
||||
<header>
|
||||
<a class="index" onclick={ reply }>{ post.index }:</a>
|
||||
<a class="name" href={ '/' + post.user.username }><b>{ post.user.name }</b></a>
|
||||
<mk-time time={ post.created_at } mode="detail"/>
|
||||
<span>ID:<i>{ post.user.username }</i></span>
|
||||
</header>
|
||||
<div>
|
||||
<a if={ post.reply_to }>>>{ post.reply_to.index }</a>
|
||||
{ post.text }
|
||||
<div class="media" if={ post.media }>
|
||||
<virtual each={ file in post.media }>
|
||||
<img src={ file.url + '?thumbnail&size=512' } alt={ file.name } title={ file.name }/>
|
||||
</virtual>
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
:scope
|
||||
display block
|
||||
margin 0
|
||||
padding 0
|
||||
|
||||
> header
|
||||
> .index
|
||||
margin-right 0.25em
|
||||
color #000
|
||||
|
||||
> .name
|
||||
margin-right 0.5em
|
||||
color #008000
|
||||
|
||||
> mk-time
|
||||
margin-right 0.5em
|
||||
|
||||
> div
|
||||
padding 0 0 1em 2em
|
||||
|
||||
</style>
|
||||
<script>
|
||||
this.post = this.opts.post;
|
||||
this.form = this.opts.form;
|
||||
|
||||
this.reply = () => {
|
||||
this.form.update({
|
||||
reply: this.post
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</mk-channel-post>
|
||||
|
||||
<mk-channel-form>
|
||||
<p if={ reply }><b>>>{ reply.index }</b> ({ reply.user.name }): <a onclick={ clearReply }>[x]</a></p>
|
||||
<textarea ref="text" disabled={ wait }></textarea>
|
||||
<button class={ wait: wait } ref="submit" disabled={ wait || (refs.text.value.length == 0) } onclick={ post }>
|
||||
{ wait ? 'やってます' : 'やる' }<mk-ellipsis if={ wait }/>
|
||||
</button>
|
||||
<br>
|
||||
<button onclick={ drive }>ドライブ</button>
|
||||
<ol if={ files }>
|
||||
<li each={ files }>{ name }</li>
|
||||
</ol>
|
||||
<style>
|
||||
:scope
|
||||
display block
|
||||
|
||||
</style>
|
||||
<script>
|
||||
import CONFIG from '../../common/scripts/config';
|
||||
|
||||
this.mixin('api');
|
||||
|
||||
this.channel = this.opts.channel;
|
||||
|
||||
this.clearReply = () => {
|
||||
this.update({
|
||||
reply: null
|
||||
});
|
||||
};
|
||||
|
||||
this.clear = () => {
|
||||
this.clearReply();
|
||||
this.update({
|
||||
files: null
|
||||
});
|
||||
this.refs.text.value = '';
|
||||
};
|
||||
|
||||
this.post = e => {
|
||||
this.update({
|
||||
wait: true
|
||||
});
|
||||
|
||||
const files = this.files && this.files.length > 0
|
||||
? this.files.map(f => f.id)
|
||||
: undefined;
|
||||
|
||||
this.api('posts/create', {
|
||||
text: this.refs.text.value,
|
||||
media_ids: files,
|
||||
reply_to_id: this.reply ? this.reply.id : undefined,
|
||||
channel_id: this.channel.id
|
||||
}).then(data => {
|
||||
this.clear();
|
||||
}).catch(err => {
|
||||
alert('失敗した');
|
||||
}).then(() => {
|
||||
this.update({
|
||||
wait: false
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.drive = () => {
|
||||
window['cb'] = files => {
|
||||
this.update({
|
||||
files: files
|
||||
});
|
||||
};
|
||||
window.open(CONFIG.url + '/selectdrive?multiple=true', '_blank');
|
||||
};
|
||||
</script>
|
||||
</mk-channel-form>
|
||||
2
src/web/app/ch/tags/index.js
Normal file
2
src/web/app/ch/tags/index.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require('./index.tag');
|
||||
require('./channel.tag');
|
||||
24
src/web/app/ch/tags/index.tag
Normal file
24
src/web/app/ch/tags/index.tag
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<mk-index>
|
||||
<button onclick={ new }>%i18n:ch.tags.mk-index.new%</button>
|
||||
<style>
|
||||
:scope
|
||||
display block
|
||||
|
||||
</style>
|
||||
<script>
|
||||
this.mixin('api');
|
||||
|
||||
this.on('mount', () => {
|
||||
});
|
||||
|
||||
this.new = () => {
|
||||
const title = window.prompt('%i18n:ch.tags.mk-index.channel-title%');
|
||||
|
||||
this.api('channels/create', {
|
||||
title: title
|
||||
}).then(channel => {
|
||||
location.href = '/' + channel.id;
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</mk-index>
|
||||
Loading…
Add table
Add a link
Reference in a new issue