import { useQuery } from '@tanstack/react-query'; import { useEffect, useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { useStorage } from '@libs/storage/provider'; import { ArrowRightCircleIcon, CheckCircleIcon, LoaderIcon } from '@shared/icons'; import { User } from '@shared/user'; import { useOnboarding } from '@stores/onboarding'; import { useNostr } from '@utils/hooks/useNostr'; import { arrayToNIP02 } from '@utils/transform'; export function OnboardStep1Screen() { const navigate = useNavigate(); const setStep = useOnboarding((state) => state.setStep); const { publish, fetchUserData } = useNostr(); const { db } = useStorage(); const { status, data } = useQuery(['trending-profiles-widget'], async () => { const res = await fetch('https://api.nostr.band/v0/trending/profiles'); if (!res.ok) { throw new Error('Error'); } return res.json(); }); const [loading, setLoading] = useState(false); const [follows, setFollows] = useState([]); // toggle follow state const toggleFollow = (pubkey: string) => { const arr = follows.includes(pubkey) ? follows.filter((i) => i !== pubkey) : [...follows, pubkey]; setFollows(arr); }; const submit = async () => { try { setLoading(true); const tags = arrayToNIP02([...follows, db.account.pubkey]); const event = await publish({ content: '', kind: 3, tags: tags }); // prefetch data const user = await fetchUserData(follows); // redirect to next step if (event && user.status === 'ok') { navigate('/auth/onboarding/step-2', { replace: true }); } else { setLoading(false); } } catch (e) { setLoading(false); console.log('error: ', e); } }; useEffect(() => { // save current step, if user close app and reopen it setStep('/auth/onboarding'); }, []); return (
Choose the account you want to follow. These accounts are trending in the last 24 hours. If none of the accounts interest you, you can explore more options and add them later.