mirror of
https://github.com/lumehq/lume.git
synced 2025-03-28 02:31:49 +01:00
fix bugs
This commit is contained in:
parent
d1d0a462f4
commit
edf56bc97b
@ -47,7 +47,8 @@ export function OnboardStep1Screen() {
|
||||
const event = await publish({ content: '', kind: 3, tags: tags });
|
||||
await updateAccount('follows', follows);
|
||||
|
||||
const notes = await fetchNotes();
|
||||
// prefetch notes with current follows
|
||||
const notes = await fetchNotes(follows);
|
||||
|
||||
// redirect to next step
|
||||
if (event && notes) {
|
||||
@ -103,7 +104,7 @@ export function OnboardStep1Screen() {
|
||||
{loading ? (
|
||||
<>
|
||||
<span className="w-5" />
|
||||
<span>Creating...</span>
|
||||
<span>It might take a bit, please patient...</span>
|
||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||
</>
|
||||
) : (
|
||||
|
@ -2,7 +2,7 @@
|
||||
import NDK from '@nostr-dev-kit/ndk';
|
||||
import { ndkAdapter } from '@nostr-fetch/adapter-ndk';
|
||||
import { NostrFetcher } from 'nostr-fetch';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import TauriAdapter from '@libs/ndk/cache';
|
||||
import { getExplicitRelayUrls } from '@libs/storage';
|
||||
@ -10,13 +10,14 @@ import { getExplicitRelayUrls } from '@libs/storage';
|
||||
import { FULL_RELAYS } from '@stores/constants';
|
||||
|
||||
export const NDKInstance = () => {
|
||||
const cacheAdapter = useMemo(() => new TauriAdapter(), []);
|
||||
|
||||
const [ndk, setNDK] = useState<NDK | undefined>(undefined);
|
||||
const [relayUrls, setRelayUrls] = useState<string[]>([]);
|
||||
const [fetcher, setFetcher] = useState<NostrFetcher>(undefined);
|
||||
const [cacheAdapter] = useState(new TauriAdapter());
|
||||
|
||||
useEffect(() => {
|
||||
loadNdk();
|
||||
if (!ndk) loadNdk();
|
||||
|
||||
return () => {
|
||||
cacheAdapter.save();
|
||||
|
@ -34,10 +34,10 @@ export async function getActiveAccount() {
|
||||
if (result.length > 0) {
|
||||
result[0]['follows'] = result[0].follows
|
||||
? JSON.parse(result[0].follows as unknown as string)
|
||||
: [];
|
||||
: null;
|
||||
result[0]['network'] = result[0].network
|
||||
? JSON.parse(result[0].network as unknown as string)
|
||||
: [];
|
||||
: null;
|
||||
return result[0];
|
||||
} else {
|
||||
return null;
|
||||
|
@ -9,14 +9,12 @@ export function AvatarUploader({ setPicture }: { setPicture: any }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const uploadAvatar = async () => {
|
||||
setLoading(true);
|
||||
const image = await upload(null);
|
||||
if (image.url) {
|
||||
// update parent state
|
||||
setPicture(image.url);
|
||||
|
||||
// disable loader
|
||||
setLoading(false);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -9,14 +9,12 @@ export function BannerUploader({ setBanner }: { setBanner: any }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const uploadBanner = async () => {
|
||||
setLoading(true);
|
||||
const image = await upload(null);
|
||||
if (image.url) {
|
||||
// update parent state
|
||||
setBanner(image);
|
||||
|
||||
// disable loader
|
||||
setLoading(false);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -18,22 +18,25 @@ import { nHoursAgo } from '@utils/date';
|
||||
export function useNostr() {
|
||||
const { ndk, relayUrls, fetcher } = useNDK();
|
||||
|
||||
async function fetchNetwork() {
|
||||
async function fetchNetwork(prevFollow?: string[]) {
|
||||
const account = await getActiveAccount();
|
||||
const follows = new Set<string>();
|
||||
const follows = new Set<string>(prevFollow || []);
|
||||
const lruNetwork = new LRUCache<string, string, void>({ max: 300 });
|
||||
|
||||
let network: string[];
|
||||
|
||||
// fetch user's follows
|
||||
const user = ndk.getUser({ hexpubkey: account.pubkey });
|
||||
const list = await user.follows();
|
||||
list.forEach((item: NDKUser) => {
|
||||
follows.add(nip19.decode(item.npub).data as string);
|
||||
});
|
||||
if (!prevFollow) {
|
||||
const user = ndk.getUser({ hexpubkey: account.pubkey });
|
||||
const list = await user.follows();
|
||||
list.forEach((item: NDKUser) => {
|
||||
follows.add(nip19.decode(item.npub).data as string);
|
||||
});
|
||||
}
|
||||
|
||||
// fetch network
|
||||
if (!account.network) {
|
||||
console.log('fetching network...', follows.size);
|
||||
const events = await fetcher.fetchAllEvents(
|
||||
relayUrls,
|
||||
{ kinds: [3], authors: [...follows] },
|
||||
@ -59,9 +62,9 @@ export function useNostr() {
|
||||
return [...new Set([...follows, ...network])];
|
||||
}
|
||||
|
||||
const fetchNotes = async () => {
|
||||
const fetchNotes = async (prevFollow?: string[]) => {
|
||||
try {
|
||||
const network = (await fetchNetwork()) as string[];
|
||||
const network = (await fetchNetwork(prevFollow)) as string[];
|
||||
|
||||
const totalNotes = await countTotalNotes();
|
||||
const lastLogin = await getLastLogin();
|
||||
|
4
src/utils/types.d.ts
vendored
4
src/utils/types.d.ts
vendored
@ -20,8 +20,8 @@ export interface Account extends NDKUserProfile {
|
||||
id: number;
|
||||
npub: string;
|
||||
pubkey: string;
|
||||
follows: string[];
|
||||
network: string[];
|
||||
follows: null | string[];
|
||||
network: null | string[];
|
||||
is_active: number;
|
||||
privkey?: string; // deprecated
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user