fix: notification.vueのIntersectionObserverまわりを修正 (#8010)

* fix notification.vue

* remove a blank line

* disconnect intersection observer

* disconnect2

* Update packages/client/src/components/notification.vue

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

* disconnect

* oops

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
tamaina 2021-11-26 13:43:11 +09:00 committed by GitHub
parent d9775c147f
commit 8e0108a0b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -107,28 +107,25 @@ export default defineComponent({
const reactionRef = ref(null); const reactionRef = ref(null);
onMounted(() => { onMounted(() => {
let readObserver: IntersectionObserver | null = null;
let connection = null;
if (!props.notification.isRead) { if (!props.notification.isRead) {
readObserver = new IntersectionObserver((entries, observer) => { const readObserver = new IntersectionObserver((entries, observer) => {
if (!entries.some(entry => entry.isIntersecting)) return; if (!entries.some(entry => entry.isIntersecting)) return;
os.stream.send('readNotification', { os.stream.send('readNotification', {
id: props.notification.id id: props.notification.id
}); });
entries.map(({ target }) => observer.unobserve(target)); observer.disconnect();
}); });
readObserver.observe(elRef.value); readObserver.observe(elRef.value);
connection = os.stream.useChannel('main'); const connection = os.stream.useChannel('main');
connection.on('readAllNotifications', () => readObserver.unobserve(elRef.value)); connection.on('readAllNotifications', () => readObserver.disconnect());
}
onUnmounted(() => { onUnmounted(() => {
if (readObserver) readObserver.unobserve(elRef.value); readObserver.disconnect();
if (connection) connection.dispose(); connection.dispose();
}); });
}
}); });
const followRequestDone = ref(false); const followRequestDone = ref(false);