mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-22 13:49:23 +01:00
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
This commit is contained in:
parent
eb2f80162a
commit
e95954a7fd
5 changed files with 58 additions and 18 deletions
|
@ -214,7 +214,7 @@ function App() {
|
||||||
{/* <Route path="/:anything" element={<NotFound />} /> */}
|
{/* <Route path="/:anything" element={<NotFound />} /> */}
|
||||||
</Routes>
|
</Routes>
|
||||||
<Routes>
|
<Routes>
|
||||||
{isLoggedIn && <Route path="/s/:id" element={<Status />} />}
|
<Route path="/s/:id" element={<Status />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
<nav id="tab-bar" hidden>
|
<nav id="tab-bar" hidden>
|
||||||
<li>
|
<li>
|
||||||
|
@ -409,6 +409,7 @@ async function startStream() {
|
||||||
|
|
||||||
const handleNewStatus = debounce((status) => {
|
const handleNewStatus = debounce((status) => {
|
||||||
console.log('UPDATE', status);
|
console.log('UPDATE', status);
|
||||||
|
if (document.visibilityState === 'hidden') return;
|
||||||
|
|
||||||
const inHomeNew = states.homeNew.find((s) => s.id === status.id);
|
const inHomeNew = states.homeNew.find((s) => s.id === status.id);
|
||||||
const inHome = status.id === states.homeLast?.id;
|
const inHome = status.id === states.homeLast?.id;
|
||||||
|
@ -444,7 +445,7 @@ async function startStream() {
|
||||||
const inNotificationsNew = states.notificationsNew.find(
|
const inNotificationsNew = states.notificationsNew.find(
|
||||||
(n) => n.id === notification.id,
|
(n) => n.id === notification.id,
|
||||||
);
|
);
|
||||||
const inNotifications = notification.id === states.notificationLast?.id;
|
const inNotifications = notification.id === states.notificationsLast?.id;
|
||||||
if (!inNotificationsNew && !inNotifications) {
|
if (!inNotificationsNew && !inNotifications) {
|
||||||
states.notificationsNew.unshift(notification);
|
states.notificationsNew.unshift(notification);
|
||||||
}
|
}
|
||||||
|
@ -483,6 +484,7 @@ function startVisibility() {
|
||||||
try {
|
try {
|
||||||
const firstStatusID = states.homeLast?.id;
|
const firstStatusID = states.homeLast?.id;
|
||||||
const firstNotificationID = states.notificationsLast?.id;
|
const firstNotificationID = states.notificationsLast?.id;
|
||||||
|
console.log({ states, firstNotificationID, firstStatusID });
|
||||||
const fetchHome = masto.v1.timelines.listHome({
|
const fetchHome = masto.v1.timelines.listHome({
|
||||||
limit: 5,
|
limit: 5,
|
||||||
...(firstStatusID && { sinceId: firstStatusID }),
|
...(firstStatusID && { sinceId: firstStatusID }),
|
||||||
|
@ -518,7 +520,7 @@ function startVisibility() {
|
||||||
(n) => n.id === notification.id,
|
(n) => n.id === notification.id,
|
||||||
);
|
);
|
||||||
const inNotifications =
|
const inNotifications =
|
||||||
notification.id === states.notificationLast?.id;
|
notification.id === states.notificationsLast?.id;
|
||||||
if (!inNotificationsNew && !inNotifications) {
|
if (!inNotificationsNew && !inNotifications) {
|
||||||
states.notificationsNew.unshift(notification);
|
states.notificationsNew.unshift(notification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,10 @@ render(
|
||||||
document.getElementById('app'),
|
document.getElementById('app'),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Clean up iconify localStorage
|
// Storage cleanup
|
||||||
// TODO: Remove this after few weeks?
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
try {
|
try {
|
||||||
|
// Clean up iconify localStorage
|
||||||
Object.keys(localStorage).forEach((key) => {
|
Object.keys(localStorage).forEach((key) => {
|
||||||
if (key.startsWith('iconify')) {
|
if (key.startsWith('iconify')) {
|
||||||
localStorage.removeItem(key);
|
localStorage.removeItem(key);
|
||||||
|
@ -32,5 +32,8 @@ setTimeout(() => {
|
||||||
sessionStorage.removeItem(key);
|
sessionStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clean up old settings key
|
||||||
|
localStorage.removeItem('settings:boostsCarousel');
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
|
@ -81,7 +81,7 @@ function Notifications() {
|
||||||
const groupedNotifications = groupNotifications(notificationsValues);
|
const groupedNotifications = groupNotifications(notificationsValues);
|
||||||
|
|
||||||
if (firstLoad) {
|
if (firstLoad) {
|
||||||
states.notificationLast = notificationsValues[0];
|
states.notificationsLast = notificationsValues[0];
|
||||||
states.notifications = groupedNotifications;
|
states.notifications = groupedNotifications;
|
||||||
} else {
|
} else {
|
||||||
states.notifications.push(...groupedNotifications);
|
states.notifications.push(...groupedNotifications);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { proxy, subscribe } from 'valtio';
|
import { proxy } from 'valtio';
|
||||||
|
import { subscribeKey } from 'valtio/utils';
|
||||||
|
|
||||||
import store from './store';
|
import store from './store';
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ const states = proxy({
|
||||||
homeLast: null, // Last item in 'home' list
|
homeLast: null, // Last item in 'home' list
|
||||||
homeLastFetchTime: null,
|
homeLastFetchTime: null,
|
||||||
notifications: [],
|
notifications: [],
|
||||||
notificationLast: null, // Last item in 'notifications' list
|
notificationsLast: store.account.get('notificationsLast') || null, // Last item in 'notifications' list
|
||||||
notificationsNew: [],
|
notificationsNew: [],
|
||||||
notificationsLastFetchTime: null,
|
notificationsLastFetchTime: null,
|
||||||
accounts: {},
|
accounts: {},
|
||||||
|
@ -27,20 +28,20 @@ const states = proxy({
|
||||||
showAccount: false,
|
showAccount: false,
|
||||||
showDrafts: false,
|
showDrafts: false,
|
||||||
showMediaModal: false,
|
showMediaModal: false,
|
||||||
composeCharacterCount: 0,
|
// Settings
|
||||||
settings: {
|
settings: {
|
||||||
boostsCarousel: store.local.get('settings:boostsCarousel')
|
boostsCarousel: store.account.get('settings-boostCarousel') ?? true,
|
||||||
? store.local.get('settings:boostsCarousel') === '1'
|
|
||||||
: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default states;
|
export default states;
|
||||||
|
|
||||||
subscribe(states.settings, () => {
|
subscribeKey(states, 'notificationsLast', (v) => {
|
||||||
store.local.set(
|
console.log('CHANGE', v);
|
||||||
'settings:boostsCarousel',
|
store.account.set('notificationsLast', states.notificationsLast);
|
||||||
states.settings.boostsCarousel ? '1' : '0',
|
});
|
||||||
);
|
subscribeKey(states, 'settings-boostCarousel', (v) => {
|
||||||
|
store.account.set('settings-boostCarousel', !!v);
|
||||||
});
|
});
|
||||||
|
|
||||||
export function hideAllModals() {
|
export function hideAllModals() {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { getCurrentAccountNS } from './store-utils';
|
||||||
|
|
||||||
const local = {
|
const local = {
|
||||||
get: (key) => {
|
get: (key) => {
|
||||||
try {
|
try {
|
||||||
|
@ -84,4 +86,36 @@ const session = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default { local, session };
|
// Store with account namespace (id@domain.tld) <- uses id, not username
|
||||||
|
const account = {
|
||||||
|
get: (key) => {
|
||||||
|
try {
|
||||||
|
return local.getJSON(key)[getCurrentAccountNS()];
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
set: (key, value) => {
|
||||||
|
try {
|
||||||
|
const data = local.getJSON(key) || {};
|
||||||
|
data[getCurrentAccountNS()] = value;
|
||||||
|
return local.setJSON(key, data);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
del: (key) => {
|
||||||
|
try {
|
||||||
|
const data = local.getJSON(key) || {};
|
||||||
|
delete data[getCurrentAccountNS()];
|
||||||
|
return local.setJSON(key, data);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default { local, session, account };
|
||||||
|
|
Loading…
Reference in a new issue