add ndk cache tauri
This commit is contained in:
@@ -189,7 +189,7 @@ export const User = memo(function User({
|
||||
return (
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="h-11 w-11 shrink-0 animate-pulse rounded-lg bg-neutral-300 dark:bg-neutral-700" />
|
||||
<div className="flex w-full flex-col items-start">
|
||||
<div className="flex w-full flex-col items-start gap-1">
|
||||
<div className="h-4 w-36 animate-pulse rounded bg-neutral-300 dark:bg-neutral-700" />
|
||||
<div className="h-4 w-24 animate-pulse rounded bg-neutral-300 dark:bg-neutral-700" />
|
||||
</div>
|
||||
|
||||
@@ -19,19 +19,18 @@ export function EventLoader({ firstTime }: { firstTime: boolean }) {
|
||||
useEffect(() => {
|
||||
async function getEvents() {
|
||||
const events = await getAllEventsSinceLastLogin();
|
||||
console.log('total new events has found: ', events.data.length);
|
||||
console.log('total new events has found: ', events.length);
|
||||
|
||||
const promises = await Promise.all(
|
||||
events.data.map(async (event) => await db.createEvent(event))
|
||||
);
|
||||
|
||||
if (promises) {
|
||||
if (events) {
|
||||
setProgress(100);
|
||||
setIsFetched();
|
||||
|
||||
// invalidate queries
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['local-network-widget']
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ['local-network-widget'],
|
||||
});
|
||||
|
||||
// update last login time, use for next fetch
|
||||
await db.updateLastLogin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { TitleBar } from '@shared/titleBar';
|
||||
import { WidgetWrapper } from '@shared/widgets';
|
||||
|
||||
import { useActivities } from '@stores/activities';
|
||||
import { useWidgets } from '@stores/widgets';
|
||||
|
||||
import { useNostr } from '@utils/hooks/useNostr';
|
||||
import { Widget } from '@utils/types';
|
||||
@@ -23,6 +24,8 @@ export function LocalNotificationWidget({ params }: { params: Widget }) {
|
||||
state.setActivities,
|
||||
]);
|
||||
|
||||
const isFetched = useWidgets((state) => state.isFetched);
|
||||
|
||||
const renderEvent = useCallback(
|
||||
(event: NDKEvent) => {
|
||||
if (event.pubkey === db.account.pubkey) return null;
|
||||
@@ -37,8 +40,8 @@ export function LocalNotificationWidget({ params }: { params: Widget }) {
|
||||
setActivities(events);
|
||||
}
|
||||
|
||||
getActivities();
|
||||
}, []);
|
||||
if (isFetched) getActivities();
|
||||
}, [isFetched]);
|
||||
|
||||
return (
|
||||
<WidgetWrapper>
|
||||
|
||||
Reference in New Issue
Block a user