This commit is contained in:
syuilo 2018-04-17 07:40:19 +09:00
parent 772b1c557d
commit e2378380c6
2 changed files with 20 additions and 21 deletions

View file

@ -29,15 +29,16 @@ export default Vue.extend({
notes: [], notes: [],
connection: null, connection: null,
connectionId: null, connectionId: null,
date: null, date: null
isTop: true
}; };
}, },
computed: { computed: {
alone(): boolean { alone(): boolean {
return (this as any).os.i.followingCount == 0; return (this as any).os.i.followingCount == 0;
} }
}, },
mounted() { mounted() {
this.connection = (this as any).os.stream.getConnection(); this.connection = (this as any).os.stream.getConnection();
this.connectionId = (this as any).os.stream.use(); this.connectionId = (this as any).os.stream.use();
@ -51,6 +52,7 @@ export default Vue.extend({
this.fetch(); this.fetch();
}, },
beforeDestroy() { beforeDestroy() {
this.connection.off('note', this.onNote); this.connection.off('note', this.onNote);
this.connection.off('follow', this.onChangeFollowing); this.connection.off('follow', this.onChangeFollowing);
@ -60,6 +62,7 @@ export default Vue.extend({
document.removeEventListener('keydown', this.onKeydown); document.removeEventListener('keydown', this.onKeydown);
window.removeEventListener('scroll', this.onScroll); window.removeEventListener('scroll', this.onScroll);
}, },
methods: { methods: {
fetch(cb?) { fetch(cb?) {
this.fetching = true; this.fetching = true;
@ -78,6 +81,7 @@ export default Vue.extend({
if (cb) cb(); if (cb) cb();
}); });
}, },
more() { more() {
if (this.moreFetching || this.fetching || this.notes.length == 0 || !this.existMore) return; if (this.moreFetching || this.fetching || this.notes.length == 0 || !this.existMore) return;
this.moreFetching = true; this.moreFetching = true;
@ -94,6 +98,7 @@ export default Vue.extend({
this.moreFetching = false; this.moreFetching = false;
}); });
}, },
onNote(note) { onNote(note) {
// //
if ((this as any).os.isEnableSounds) { if ((this as any).os.isEnableSounds) {
@ -102,19 +107,23 @@ export default Vue.extend({
sound.play(); sound.play();
} }
if (this.isTop) this.notes.pop();
this.notes.unshift(note); this.notes.unshift(note);
const isTop = window.scrollY > 8;
if (isTop) this.notes.pop();
}, },
onChangeFollowing() { onChangeFollowing() {
this.fetch(); this.fetch();
}, },
onScroll() { onScroll() {
if ((this as any).os.i.clientSettings.fetchOnScroll !== false) { if ((this as any).os.i.clientSettings.fetchOnScroll !== false) {
const current = window.scrollY + window.innerHeight; const current = window.scrollY + window.innerHeight;
if (current > document.body.offsetHeight - 8) this.more(); if (current > document.body.offsetHeight - 8) this.more();
} }
this.isTop = window.scrollY < 100;
}, },
onKeydown(e) { onKeydown(e) {
if (e.target.tagName != 'INPUT' && e.target.tagName != 'TEXTAREA') { if (e.target.tagName != 'INPUT' && e.target.tagName != 'TEXTAREA') {
if (e.which == 84) { // t if (e.which == 84) { // t
@ -122,6 +131,7 @@ export default Vue.extend({
} }
} }
}, },
warp(date) { warp(date) {
this.date = date; this.date = date;
this.fetch(); this.fetch();

View file

@ -37,8 +37,7 @@ export default Vue.extend({
notes: [], notes: [],
existMore: false, existMore: false,
connection: null, connection: null,
connectionId: null, connectionId: null
isTop: true
}; };
}, },
computed: { computed: {
@ -54,18 +53,13 @@ export default Vue.extend({
this.connection.on('follow', this.onChangeFollowing); this.connection.on('follow', this.onChangeFollowing);
this.connection.on('unfollow', this.onChangeFollowing); this.connection.on('unfollow', this.onChangeFollowing);
window.addEventListener('scroll', this.onScroll);
this.fetch(); this.fetch();
}, },
beforeDestroy() { beforeDestroy() {
this.connection.off('note', this.onNote); this.connection.off('note', this.onNote);
this.connection.off('follow', this.onChangeFollowing); this.connection.off('follow', this.onChangeFollowing);
this.connection.off('unfollow', this.onChangeFollowing); this.connection.off('unfollow', this.onChangeFollowing);
this.connection.off('unfollow', this.onChangeFollowing);
(this as any).os.stream.dispose(this.connectionId); (this as any).os.stream.dispose(this.connectionId);
window.removeEventListener('scroll', this.onScroll);
}, },
methods: { methods: {
fetch(cb?) { fetch(cb?) {
@ -101,18 +95,13 @@ export default Vue.extend({
}); });
}, },
onNote(note) { onNote(note) {
this.isTop = window.scrollY < 100; this.notes.unshift(note);
const isTop = window.scrollY > 8;
if (isTop) this.notes.pop();
}, },
onChangeFollowing() { onChangeFollowing() {
this.fetch(); this.fetch();
},
onScroll() {
if ((this as any).os.i.clientSettings.fetchOnScroll !== false) {
const current = window.scrollY + window.innerHeight;
if (current > document.body.offsetHeight - 8) this.more();
}
if (window.scrollY > 100) this.isTop = false;
else this.isTop = true;
} }
} }
}); });