this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Begin work on account-specific store

1. Move boostsCarousel setting to account-specific, sadly no migration from previous setting
2. Cache last notification to prevent keep getting unread notification badge

+58 -18
+5 -3
src/app.jsx
··· 214 214 {/* <Route path="/:anything" element={<NotFound />} /> */} 215 215 </Routes> 216 216 <Routes> 217 - {isLoggedIn && <Route path="/s/:id" element={<Status />} />} 217 + <Route path="/s/:id" element={<Status />} /> 218 218 </Routes> 219 219 <nav id="tab-bar" hidden> 220 220 <li> ··· 409 409 410 410 const handleNewStatus = debounce((status) => { 411 411 console.log('UPDATE', status); 412 + if (document.visibilityState === 'hidden') return; 412 413 413 414 const inHomeNew = states.homeNew.find((s) => s.id === status.id); 414 415 const inHome = status.id === states.homeLast?.id; ··· 444 445 const inNotificationsNew = states.notificationsNew.find( 445 446 (n) => n.id === notification.id, 446 447 ); 447 - const inNotifications = notification.id === states.notificationLast?.id; 448 + const inNotifications = notification.id === states.notificationsLast?.id; 448 449 if (!inNotificationsNew && !inNotifications) { 449 450 states.notificationsNew.unshift(notification); 450 451 } ··· 483 484 try { 484 485 const firstStatusID = states.homeLast?.id; 485 486 const firstNotificationID = states.notificationsLast?.id; 487 + console.log({ states, firstNotificationID, firstStatusID }); 486 488 const fetchHome = masto.v1.timelines.listHome({ 487 489 limit: 5, 488 490 ...(firstStatusID && { sinceId: firstStatusID }), ··· 518 520 (n) => n.id === notification.id, 519 521 ); 520 522 const inNotifications = 521 - notification.id === states.notificationLast?.id; 523 + notification.id === states.notificationsLast?.id; 522 524 if (!inNotificationsNew && !inNotifications) { 523 525 states.notificationsNew.unshift(notification); 524 526 }
+5 -2
src/main.jsx
··· 18 18 document.getElementById('app'), 19 19 ); 20 20 21 - // Clean up iconify localStorage 22 - // TODO: Remove this after few weeks? 21 + // Storage cleanup 23 22 setTimeout(() => { 24 23 try { 24 + // Clean up iconify localStorage 25 25 Object.keys(localStorage).forEach((key) => { 26 26 if (key.startsWith('iconify')) { 27 27 localStorage.removeItem(key); ··· 32 32 sessionStorage.removeItem(key); 33 33 } 34 34 }); 35 + 36 + // Clean up old settings key 37 + localStorage.removeItem('settings:boostsCarousel'); 35 38 } catch (e) {} 36 39 }, 5000);
+1 -1
src/pages/notifications.jsx
··· 81 81 const groupedNotifications = groupNotifications(notificationsValues); 82 82 83 83 if (firstLoad) { 84 - states.notificationLast = notificationsValues[0]; 84 + states.notificationsLast = notificationsValues[0]; 85 85 states.notifications = groupedNotifications; 86 86 } else { 87 87 states.notifications.push(...groupedNotifications);
+12 -11
src/utils/states.js
··· 1 - import { proxy, subscribe } from 'valtio'; 1 + import { proxy } from 'valtio'; 2 + import { subscribeKey } from 'valtio/utils'; 2 3 3 4 import store from './store'; 4 5 ··· 14 15 homeLast: null, // Last item in 'home' list 15 16 homeLastFetchTime: null, 16 17 notifications: [], 17 - notificationLast: null, // Last item in 'notifications' list 18 + notificationsLast: store.account.get('notificationsLast') || null, // Last item in 'notifications' list 18 19 notificationsNew: [], 19 20 notificationsLastFetchTime: null, 20 21 accounts: {}, ··· 27 28 showAccount: false, 28 29 showDrafts: false, 29 30 showMediaModal: false, 30 - composeCharacterCount: 0, 31 + // Settings 31 32 settings: { 32 - boostsCarousel: store.local.get('settings:boostsCarousel') 33 - ? store.local.get('settings:boostsCarousel') === '1' 34 - : true, 33 + boostsCarousel: store.account.get('settings-boostCarousel') ?? true, 35 34 }, 36 35 }); 36 + 37 37 export default states; 38 38 39 - subscribe(states.settings, () => { 40 - store.local.set( 41 - 'settings:boostsCarousel', 42 - states.settings.boostsCarousel ? '1' : '0', 43 - ); 39 + subscribeKey(states, 'notificationsLast', (v) => { 40 + console.log('CHANGE', v); 41 + store.account.set('notificationsLast', states.notificationsLast); 42 + }); 43 + subscribeKey(states, 'settings-boostCarousel', (v) => { 44 + store.account.set('settings-boostCarousel', !!v); 44 45 }); 45 46 46 47 export function hideAllModals() {
+35 -1
src/utils/store.js
··· 1 + import { getCurrentAccountNS } from './store-utils'; 2 + 1 3 const local = { 2 4 get: (key) => { 3 5 try { ··· 84 86 }, 85 87 }; 86 88 87 - export default { local, session }; 89 + // Store with account namespace (id@domain.tld) <- uses id, not username 90 + const account = { 91 + get: (key) => { 92 + try { 93 + return local.getJSON(key)[getCurrentAccountNS()]; 94 + } catch (e) { 95 + console.warn(e); 96 + return null; 97 + } 98 + }, 99 + set: (key, value) => { 100 + try { 101 + const data = local.getJSON(key) || {}; 102 + data[getCurrentAccountNS()] = value; 103 + return local.setJSON(key, data); 104 + } catch (e) { 105 + console.warn(e); 106 + return null; 107 + } 108 + }, 109 + del: (key) => { 110 + try { 111 + const data = local.getJSON(key) || {}; 112 + delete data[getCurrentAccountNS()]; 113 + return local.setJSON(key, data); 114 + } catch (e) { 115 + console.warn(e); 116 + return null; 117 + } 118 + }, 119 + }; 120 + 121 + export default { local, session, account };