wip
This commit is contained in:
@@ -3,41 +3,49 @@
|
||||
<style>
|
||||
:scope
|
||||
display block
|
||||
|
||||
</style>
|
||||
<script>
|
||||
this.mixin('api');
|
||||
this.mixin('stream');
|
||||
|
||||
this.init = new Promise (res, rej) =>
|
||||
this.api 'posts/timeline'
|
||||
}).then((posts) => {
|
||||
res posts
|
||||
this.init = new Promise((res, rej) => {
|
||||
this.api('posts/timeline').then(posts => {
|
||||
res(posts);
|
||||
this.trigger('loaded');
|
||||
});
|
||||
});
|
||||
|
||||
this.on('mount', () => {
|
||||
this.stream.on 'post' this.on-stream-post
|
||||
this.stream.on 'follow' this.on-stream-follow
|
||||
this.stream.on 'unfollow' this.on-stream-unfollow
|
||||
this.stream.on('post', this.onStreamPost);
|
||||
this.stream.on('follow', this.onStreamFollow);
|
||||
this.stream.on('unfollow', this.onStreamUnfollow);
|
||||
});
|
||||
|
||||
this.on('unmount', () => {
|
||||
this.stream.off 'post' this.on-stream-post
|
||||
this.stream.off 'follow' this.on-stream-follow
|
||||
this.stream.off 'unfollow' this.on-stream-unfollow
|
||||
this.stream.off('post', this.onStreamPost);
|
||||
this.stream.off('follow', this.onStreamFollow);
|
||||
this.stream.off('unfollow', this.onStreamUnfollow);
|
||||
});
|
||||
|
||||
this.more = () => {
|
||||
this.api('posts/timeline', {
|
||||
max_id: this.refs.timeline.tail!.id
|
||||
max_id: this.refs.timeline.tail().id
|
||||
});
|
||||
};
|
||||
|
||||
this.on-stream-post = (post) => {
|
||||
this.is-empty = false
|
||||
this.update();
|
||||
this.refs.timeline.add-post post
|
||||
this.onStreamPost = post => {
|
||||
this.update({
|
||||
isEmpty: false
|
||||
});
|
||||
this.refs.timeline.addPost(post);
|
||||
};
|
||||
|
||||
this.on-stream-follow = () => {
|
||||
@fetch!
|
||||
this.onStreamFollow = () => {
|
||||
this.fetch();
|
||||
};
|
||||
|
||||
this.on-stream-unfollow = () => {
|
||||
@fetch!
|
||||
this.onStreamUnfollow = () => {
|
||||
this.fetch();
|
||||
};
|
||||
</script>
|
||||
</mk-home-timeline>
|
||||
|
@@ -74,45 +74,58 @@
|
||||
|
||||
</style>
|
||||
<script>
|
||||
this.posts = []
|
||||
this.init = true
|
||||
this.fetching = false
|
||||
this.can-fetch-more = true
|
||||
this.posts = [];
|
||||
this.init = true;
|
||||
this.fetching = false;
|
||||
this.canFetchMore = true;
|
||||
|
||||
this.on('mount', () => {
|
||||
this.opts.init}).then((posts) => {
|
||||
this.init = false
|
||||
@set-posts posts
|
||||
this.opts.init.then(posts => {
|
||||
this.init = false;
|
||||
this.setPosts(posts);
|
||||
});
|
||||
});
|
||||
|
||||
this.on('update', () => {
|
||||
this.posts.forEach (post) =>
|
||||
date = (new Date post.created_at).getDate()
|
||||
month = (new Date post.created_at).getMonth() + 1
|
||||
post._date = date
|
||||
post._datetext = month + '月 ' + date + '日'
|
||||
this.posts.forEach(post => {
|
||||
const date = new Date(post.created_at).getDate();
|
||||
const month = new Date(post.created_at).getMonth() + 1;
|
||||
post._date = date;
|
||||
post._datetext = `${month}月 ${date}日`;
|
||||
});
|
||||
});
|
||||
|
||||
this.more = () => {
|
||||
if @init or @fetching or this.posts.length == 0 then return
|
||||
this.fetching = true
|
||||
this.update();
|
||||
this.opts.more!}).then((posts) => {
|
||||
this.fetching = false
|
||||
this.prepend-posts posts
|
||||
if (this.init || this.fetching || this.posts.length == 0) return;
|
||||
this.update({
|
||||
fetching: true
|
||||
});
|
||||
this.opts.more().then(posts => {
|
||||
this.fetching = false;
|
||||
this.prependPosts(posts);
|
||||
});
|
||||
};
|
||||
|
||||
this.set-posts = (posts) => {
|
||||
this.posts = posts
|
||||
this.update();
|
||||
this.setPosts = posts => {
|
||||
this.update({
|
||||
posts: posts
|
||||
});
|
||||
};
|
||||
|
||||
this.prepend-posts = (posts) => {
|
||||
posts.forEach (post) =>
|
||||
this.posts.push post
|
||||
this.prependPosts = posts => {
|
||||
posts.forEach(post => {
|
||||
this.posts.push(post);
|
||||
this.update();
|
||||
});
|
||||
}
|
||||
|
||||
this.add-post = (post) => {
|
||||
this.posts.unshift post
|
||||
this.addPost = post => {
|
||||
this.posts.unshift(post);
|
||||
this.update();
|
||||
};
|
||||
|
||||
this.tail = () => {
|
||||
this.posts[this.posts.length - 1]
|
||||
return this.posts[this.posts.length - 1];
|
||||
};
|
||||
</script>
|
||||
</mk-timeline>
|
||||
|
@@ -89,16 +89,18 @@
|
||||
</style>
|
||||
<script>
|
||||
this.mixin('ui');
|
||||
this.mixin('openPostForm');
|
||||
this.mixin('open-post-form');
|
||||
|
||||
this.on('mount', () => {
|
||||
this.opts.ready!
|
||||
this.opts.ready();
|
||||
});
|
||||
|
||||
this.ui.on('title', (title) => {
|
||||
if this.refs.title?
|
||||
this.refs.title.innerHTML = title
|
||||
this.ui.on('title', title => {
|
||||
if (this.refs.title) this.refs.title.innerHTML = title;
|
||||
});
|
||||
|
||||
this.post = () => {
|
||||
this.openPostForm!
|
||||
this.openPostForm();
|
||||
};
|
||||
</script>
|
||||
</mk-ui-header>
|
||||
|
Reference in New Issue
Block a user