From 6f6d4fc0cfd887ea0cbcf884463238f8a0334da9 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Tue, 14 Mar 2023 18:47:16 +0800 Subject: [PATCH] Remove unused code --- src/app.jsx | 169 ---------------------------------------------------- 1 file changed, 169 deletions(-) diff --git a/src/app.jsx b/src/app.jsx index 3ec2bfaf..77d2ce17 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -182,15 +182,6 @@ function App() { if (!showModal) focusDeck(); }, [showModal]); - // useEffect(() => { - // // HACK: prevent this from running again due to HMR - // if (states.init) return; - // if (isLoggedIn) { - // requestAnimationFrame(startVisibility); - // states.init = true; - // } - // }, [isLoggedIn]); - // Notifications service // - WebSocket to receive notifications when page is visible const [visible, setVisible] = useState(true); @@ -485,164 +476,4 @@ function App() { ); } -// let ws; -// async function startStream() { -// const { masto, instance } = api(); -// if ( -// ws && -// (ws.readyState === WebSocket.CONNECTING || ws.readyState === WebSocket.OPEN) -// ) { -// return; -// } - -// const stream = await masto.v1.stream.streamUser(); -// console.log('STREAM START', { stream }); -// ws = stream.ws; - -// const handleNewStatus = debounce((status) => { -// console.log('UPDATE', status); -// if (document.visibilityState === 'hidden') return; - -// const inHomeNew = states.homeNew.find((s) => s.id === status.id); -// const inHome = status.id === states.homeLast?.id; -// if (!inHomeNew && !inHome) { -// if (states.settings.boostsCarousel && status.reblog) { -// // do nothing -// } else { -// states.homeNew.unshift({ -// id: status.id, -// reblog: status.reblog?.id, -// reply: !!status.inReplyToAccountId, -// }); -// console.log('homeNew 1', [...states.homeNew]); -// } -// } - -// saveStatus(status, instance); -// }, 5000); -// stream.on('update', handleNewStatus); -// stream.on('status.update', (status) => { -// console.log('STATUS.UPDATE', status); -// saveStatus(status, instance); -// }); -// stream.on('delete', (statusID) => { -// console.log('DELETE', statusID); -// // delete states.statuses[statusID]; -// const s = getStatus(statusID); -// if (s) s._deleted = true; -// }); -// stream.on('notification', (notification) => { -// console.log('NOTIFICATION', notification); - -// const inNotificationsNew = states.notificationsNew.find( -// (n) => n.id === notification.id, -// ); -// const inNotifications = notification.id === states.notificationsLast?.id; -// if (!inNotificationsNew && !inNotifications) { -// states.notificationsNew.unshift(notification); -// } - -// saveStatus(notification.status, instance, { override: false }); -// }); - -// stream.ws.onclose = () => { -// console.log('STREAM CLOSED!'); -// if (document.visibilityState !== 'hidden') { -// startStream(); -// } -// }; - -// return { -// stream, -// stopStream: () => { -// stream.ws.close(); -// }, -// }; -// } - -// let lastHidden; -// function startVisibility() { -// const { masto, instance } = api(); -// const handleVisible = (visible) => { -// if (!visible) { -// const timestamp = Date.now(); -// lastHidden = timestamp; -// } else { -// const timestamp = Date.now(); -// const diff = timestamp - lastHidden; -// const diffMins = Math.round(diff / 1000 / 60); -// console.log(`visible: ${visible}`, { lastHidden, diffMins }); -// if (!lastHidden || diffMins > 1) { -// (async () => { -// try { -// const firstStatusID = states.homeLast?.id; -// const firstNotificationID = states.notificationsLast?.id; -// console.log({ states, firstNotificationID, firstStatusID }); -// const fetchHome = masto.v1.timelines.listHome({ -// limit: 5, -// ...(firstStatusID && { sinceId: firstStatusID }), -// }); -// const fetchNotifications = masto.v1.notifications.list({ -// limit: 1, -// ...(firstNotificationID && { sinceId: firstNotificationID }), -// }); - -// const newStatuses = await fetchHome; -// const hasOneAndReblog = -// newStatuses.length === 1 && newStatuses?.[0]?.reblog; -// if (newStatuses.length) { -// if (states.settings.boostsCarousel && hasOneAndReblog) { -// // do nothing -// } else { -// states.homeNew = newStatuses.map((status) => { -// saveStatus(status, instance); -// return { -// id: status.id, -// reblog: status.reblog?.id, -// reply: !!status.inReplyToAccountId, -// }; -// }); -// console.log('homeNew 2', [...states.homeNew]); -// } -// } - -// const newNotifications = await fetchNotifications; -// if (newNotifications.length) { -// const notification = newNotifications[0]; -// const inNotificationsNew = states.notificationsNew.find( -// (n) => n.id === notification.id, -// ); -// const inNotifications = -// notification.id === states.notificationsLast?.id; -// if (!inNotificationsNew && !inNotifications) { -// states.notificationsNew.unshift(notification); -// } - -// saveStatus(notification.status, instance, { override: false }); -// } -// } catch (e) { -// // Silently fail -// console.error(e); -// } finally { -// startStream(); -// } -// })(); -// } -// } -// }; - -// const handleVisibilityChange = () => { -// const hidden = document.visibilityState === 'hidden'; -// handleVisible(!hidden); -// console.log('VISIBILITY: ' + (hidden ? 'hidden' : 'visible')); -// }; -// document.addEventListener('visibilitychange', handleVisibilityChange); -// requestAnimationFrame(handleVisibilityChange); -// return { -// stop: () => { -// document.removeEventListener('visibilitychange', handleVisibilityChange); -// }, -// }; -// } - export { App };