2017-01-11 21:55:38 +01:00
|
|
|
<mk-search-posts>
|
2017-01-11 22:00:12 +01:00
|
|
|
<div class="loading" if={ isLoading }>
|
2017-06-07 08:43:29 +02:00
|
|
|
<mk-ellipsis-icon/>
|
2017-01-11 21:55:38 +01:00
|
|
|
</div>
|
2017-01-11 22:00:12 +01:00
|
|
|
<p class="empty" if={ isEmpty }><i class="fa fa-search"></i>「{ query }」に関する投稿は見つかりませんでした。</p>
|
2017-06-07 08:43:29 +02:00
|
|
|
<mk-timeline ref="timeline"><yield to="footer"><i class="fa fa-moon-o" if={ !parent.moreLoading }></i><i class="fa fa-spinner fa-pulse fa-fw" if={ parent.moreLoading }></i></yield/>
|
2017-02-19 04:31:53 +01:00
|
|
|
<style>
|
2017-01-11 21:55:38 +01:00
|
|
|
:scope
|
|
|
|
display block
|
|
|
|
background #fff
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-01-11 21:55:38 +01:00
|
|
|
> .loading
|
|
|
|
padding 64px 0
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-01-11 21:55:38 +01:00
|
|
|
> .empty
|
|
|
|
display block
|
|
|
|
margin 0 auto
|
|
|
|
padding 32px
|
|
|
|
max-width 400px
|
|
|
|
text-align center
|
|
|
|
color #999
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-01-11 21:55:38 +01:00
|
|
|
> i
|
|
|
|
display block
|
|
|
|
margin-bottom 16px
|
|
|
|
font-size 3em
|
|
|
|
color #ccc
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-01-11 21:55:38 +01:00
|
|
|
</style>
|
|
|
|
<script>
|
2017-02-20 01:53:57 +01:00
|
|
|
this.mixin('api');
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-02-21 12:05:03 +01:00
|
|
|
this.query = this.opts.query;
|
|
|
|
this.isLoading = true;
|
|
|
|
this.isEmpty = false;
|
|
|
|
this.moreLoading = false;
|
|
|
|
this.page = 0;
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-02-20 01:53:57 +01:00
|
|
|
this.on('mount', () => {
|
2017-02-21 12:05:03 +01:00
|
|
|
document.addEventListener('keydown', this.onDocumentKeydown);
|
|
|
|
window.addEventListener('scroll', this.onScroll);
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-02-20 08:09:46 +01:00
|
|
|
this.api('posts/search', {
|
2017-02-20 12:13:42 +01:00
|
|
|
query: this.query
|
2017-02-21 12:05:03 +01:00
|
|
|
}).then(posts => {
|
|
|
|
this.update({
|
|
|
|
isLoading: false,
|
|
|
|
isEmpty: posts.length == 0
|
|
|
|
});
|
|
|
|
this.refs.timeline.setPosts(posts);
|
2017-02-20 01:53:57 +01:00
|
|
|
this.trigger('loaded');
|
2017-02-21 12:05:03 +01:00
|
|
|
});
|
|
|
|
});
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-02-20 01:53:57 +01:00
|
|
|
this.on('unmount', () => {
|
2017-02-21 12:05:03 +01:00
|
|
|
document.removeEventListener('keydown', this.onDocumentKeydown);
|
|
|
|
window.removeEventListener('scroll', this.onScroll);
|
|
|
|
});
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-02-21 12:05:03 +01:00
|
|
|
this.onDocumentKeydown = e => {
|
|
|
|
if (e.target.tagName != 'INPUT' && e.target.tagName != 'TEXTAREA') {
|
|
|
|
if (e.which == 84) { // t
|
2017-02-20 01:53:57 +01:00
|
|
|
this.refs.timeline.focus();
|
2017-02-21 12:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-02-20 02:34:57 +01:00
|
|
|
this.more = () => {
|
2017-02-21 12:05:03 +01:00
|
|
|
if (this.moreLoading || this.isLoading || this.timeline.posts.length == 0) return;
|
|
|
|
this.update({
|
|
|
|
moreLoading: true
|
|
|
|
});
|
2017-02-20 08:09:46 +01:00
|
|
|
this.api('posts/search', {
|
2017-02-21 12:05:03 +01:00
|
|
|
query: this.query,
|
2017-02-20 03:02:43 +01:00
|
|
|
page: this.page + 1
|
2017-02-21 12:05:03 +01:00
|
|
|
}).then(posts => {
|
|
|
|
this.update({
|
|
|
|
moreLoading: false,
|
|
|
|
page: page + 1
|
|
|
|
});
|
|
|
|
this.refs.timeline.prependPosts(posts);
|
|
|
|
});
|
|
|
|
};
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2017-02-21 12:05:03 +01:00
|
|
|
this.onScroll = () => {
|
|
|
|
const current = window.scrollY + window.innerHeight;
|
|
|
|
if (current > document.body.offsetHeight - 16) this.more();
|
|
|
|
};
|
2017-01-11 21:55:38 +01:00
|
|
|
</script>
|
|
|
|
</mk-search-posts>
|