diff --git a/src/components/Note/Note.tsx b/src/components/Note/Note.tsx index 330bb04..a9942ec 100644 --- a/src/components/Note/Note.tsx +++ b/src/components/Note/Note.tsx @@ -38,14 +38,6 @@ const Note: Component<{ note: PrimalNote, id?: string }> = (props) => { const [openCustomZap, setOpenCustomZap] = createSignal(false); - createEffect(() => { - const n = props.note; - - console.log('NOTE: ', n); - console.log('REPLY: ', n.replyTo); - console.log('------------------------') - }) - return ( void, }> = (props) => { @@ -26,9 +30,8 @@ const ProfileTabs: Component<{ const addToAllowlist = async () => { const pk = profile?.profileKey; - const setP = props.setProfile; - if (pk && setP) { - account?.actions.addToAllowlist(pk, () => { setP(pk) }); + if (pk) { + account?.actions.addToAllowlist(pk); } }; @@ -46,13 +49,12 @@ const ProfileTabs: Component<{ const unMuteProfile = () => { const pk = profile?.profileKey; - const setP = props.setProfile; - if (!account || !pk || !setP) { + if (!account || !pk) { return; } - account.actions.removeFromMuteList(pk, () => setP(pk)); + account.actions.removeFromMuteList(pk); }; const onContactAction = (remove: boolean, pubkey: string) => { @@ -64,221 +66,305 @@ const ProfileTabs: Component<{ } }; - const contacts = () => { - const cts = [...(profile?.contacts || [])]; + const [contactsOffset, setContactsOffset] = createSignal(0); + const [contacts, setContacts] = createStore([]); + + createEffect(() => { + if (!profile || profile.isFetchingContacts) { + return; + } + + const cts = [...(profile.contacts || [])]; cts.sort((a, b) => { - const aFollowers = profile?.profileStats[a.pubkey] || 0; - const bFollowers = profile?.profileStats[b.pubkey] || 0; - - const c = bFollowers >= aFollowers ? 1 : -1; - - return c; + const aFollowers: number = profile.profileStats[a.pubkey] || 0; + const bFollowers: number = profile.profileStats[b.pubkey] || 0; + return bFollowers >= aFollowers ? 1 : -1; }); - return cts; + setContacts((cs) => [ ...cs, ...(cts.slice(contactsOffset(), contactsOffset() + profileContactListPage))]); + + }); + + const loadMoreFollows = () => { + setContactsOffset(contactsOffset() + profileContactListPage); } - const followers = () => { - const fls = [...(profile?.followers || [])]; - fls.sort((a, b) => { - const aFollowers = profile?.profileStats[a.pubkey] || 0; - const bFollowers = profile?.profileStats[b.pubkey] || 0; + const [followersOffset, setFollowersOffset] = createSignal(0); + const [followers, setFollowers] = createStore([]); - const c = bFollowers >= aFollowers ? 1 : -1; + createEffect(() => { + if (!profile || profile.isFetchingFollowers) { + return; + } - return c; + const cts = [...(profile.followers || [])]; + cts.sort((a, b) => { + const aFollowers: number = profile.profileStats[a.pubkey] || 0; + const bFollowers: number = profile.profileStats[b.pubkey] || 0; + + return bFollowers >= aFollowers ? 1 : -1; }); - return fls; + setFollowers((fs) => [ ...fs, ...(cts.slice(followersOffset(), followersOffset() + profileContactListPage))]); + + }); + + const loadMoreFollowers = () => { + setFollowersOffset(followersOffset() + profileContactListPage); } + const onChangeValue = (value: string) => { + if (!props.profile) return; + + switch(value) { + case 'notes': + profile?.notes.length === 0 &&profile?.actions.fetchNotes(props.profile.pubkey); + break; + case 'replies': + profile?.replies.length === 0 && profile?.actions.fetchReplies(props.profile.pubkey); + break; + case 'follows': + profile?.contacts.length === 0 && profile?.actions.fetchContactList(props.profile.pubkey); + break; + case 'followers': + profile?.followers.length === 0 && profile?.actions.fetchFollowerList(props.profile.pubkey); + break; + } + }; + return ( - - - -
-
- {humanizeNumber(profile?.userStats?.note_count || 0)} -
-
- {intl.formatMessage(t.stats.notes)} -
-
-
- - -
-
- {humanizeNumber(profile?.userStats?.reply_count || 0)} -
-
- {intl.formatMessage(t.stats.replies)} -
-
-
- - -
-
- {humanizeNumber(profile?.userStats?.follows_count || 0)} -
-
- {intl.formatMessage(t.stats.follow)} -
-
-
- - -
-
- {humanizeNumber(profile?.userStats?.followers_count || 0)} -
-
- {intl.formatMessage(t.stats.followers)} -
-
-
- - -
- - -
- - + + + + +
+
+ {humanizeNumber(profile?.userStats?.note_count || 0)}
- }> - -
- {intl.formatMessage( - t.isMuted, - { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, - )} - +
+ {intl.formatMessage(t.stats.notes)}
- - -
- {intl.formatMessage(t.isFiltered)} - +
+ + +
+ + +
+
+ {humanizeNumber(profile?.userStats?.reply_count || 0)}
- - -
- {intl.formatMessage( - t.noNotes, - { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, - )} +
+ {intl.formatMessage(t.stats.replies)}
- - 0}> - - {note => ( - - )} +
+ + +
+ + +
+
+ {humanizeNumber(profile?.userStats?.follows_count || 0)} +
+
+ {intl.formatMessage(t.stats.follow)} +
+
+
+ +
+ + +
+
+ {humanizeNumber(profile?.userStats?.followers_count || 0)} +
+
+ {intl.formatMessage(t.stats.followers)} +
+
+
+ + + + + +
+ + +
+ }> + +
+ {intl.formatMessage( + t.isMuted, + { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, + )} + +
+
+ +
+ {intl.formatMessage(t.isFiltered)} + +
+
+ +
+ {intl.formatMessage( + t.noNotes, + { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, + )} +
+
+ 0}> + + {note => ( + + )} + + { + profile?.actions.fetchNextPage(); + }}/> + + +
+ + + +
+ + +
+ }> + +
+ {intl.formatMessage( + t.isMuted, + { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, + )} + +
+
+ +
+ {intl.formatMessage(t.isFiltered)} + +
+
+ +
+ {intl.formatMessage( + t.noNotes, + { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, + )} +
+
+ 0}> + + {reply => ( + + )} + + { + profile?.actions.fetchNextRepliesPage(); + }}/> + + +
+ + + +
+ + +
+ } + > + + {intl.formatMessage( + t.noFollows, + { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, + )} +
+ }> + {contact => +
+ +
} - { - profile?.actions.fetchNextPage(); - }}/> - -
-
-
+ + + + - -
- - -
- }> - -
- {intl.formatMessage( - t.isMuted, - { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, - )} - -
-
- -
- {intl.formatMessage(t.isFiltered)} - -
-
- -
- {intl.formatMessage( - t.noNotes, - { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, - )} -
-
- 0}> - - {reply => ( - - )} + +
+ + +
+ } + > + + {intl.formatMessage( + t.noFollowers, + { name: profile?.userProfile ? userName(profile?.userProfile) : profile?.profileKey }, + )} + + }> + {follower => +
+ +
+ }
- { - profile?.actions.fetchNextRepliesPage(); - }}/> -
- - -
- - - - {contact => -
- -
} -
-
- - - - {follower => -
- -
- } -
-
-
+ + + + + + ); } diff --git a/src/constants.ts b/src/constants.ts index 6027d9e..c4307d5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -299,3 +299,5 @@ export const defaultContentModeration: ContentModeration[] = [ export const algoNpub ='npub1tkpg9lyfgy83c4mgrgkrhzl90t732ekzvt73m6658xva88g5rj6qy6ntw4'; export const specialAlgos = ['primal_spam', 'primal_nsfw']; + +export const profileContactListPage = 50; diff --git a/src/contexts/ProfileContext.tsx b/src/contexts/ProfileContext.tsx index 0d628ee..bdc70da 100644 --- a/src/contexts/ProfileContext.tsx +++ b/src/contexts/ProfileContext.tsx @@ -55,6 +55,7 @@ export type ProfileContextStore = { reply_count: number, time_joined: number, }, + fetchedUserStats: boolean, knownProfiles: VanityProfiles, notes: PrimalNote[], replies: PrimalNote[], @@ -172,11 +173,11 @@ export const ProfileProvider = (props: { children: ContextChildren }) => { // ACTIONS -------------------------------------- -const addContact = (pubkey: string, source: PrimalUser[]) => { - const newContact = source.find(c => c.pubkey === pubkey); + const addContact = (pubkey: string, source: PrimalUser[]) => { + const newContact = source.find(c => c.pubkey === pubkey); - newContact && updateStore('contacts', store.contacts.length, reconcile(newContact)); -}; + newContact && updateStore('contacts', store.contacts.length, reconcile(newContact)); + }; const removeContact = (pubkey: string) => { const newContacts = store.contacts.filter(c => c.pubkey !== pubkey); @@ -248,19 +249,19 @@ const addContact = (pubkey: string, source: PrimalUser[]) => { } }); + updateStore('isFetchingContacts', () => true); + getProfileContactList(pubkey, subIdContacts); }; const fetchFollowerList = (pubkey: string | undefined) => { if (!pubkey) return; - - updateStore('isFetchingFollowers', () => true); - const subIdProfiles = `profile_followers_2_${APP_ID}`; const unsubProfiles = subscribeTo(subIdProfiles, (type, _, content) => { if (type === 'EOSE') { updateStore('isFetchingFollowers', () => false); + console.log('FETCHING FOLLOWERS DONE: ', store.isFetchingFollowers) unsubProfiles(); return; } @@ -289,6 +290,10 @@ const addContact = (pubkey: string, source: PrimalUser[]) => { } }); + updateStore('isFetchingFollowers', () => true); + + console.log('FETCHING FOLLOWERS: ', store.isFetchingFollowers) + getProfileFollowerList(pubkey, subIdProfiles); }; @@ -327,7 +332,7 @@ const addContact = (pubkey: string, source: PrimalUser[]) => { return; } - updateStore('isFetching', () => true); + updateStore('isFetchingReplies', () => true); updateStore('page', () => ({ messages: [], users: {}, postStats: {} })); getUserFeed(account?.publicKey, pubkey, `profile_replies_${APP_ID}`, 'replies', until, limit); } @@ -752,6 +757,7 @@ const addContact = (pubkey: string, source: PrimalUser[]) => { updateStore('filterReason', () => null); updateStore('userProfile', () => undefined); updateStore('userStats', () => ({ ...emptyStats })); + updateStore('fetchedUserStats', () => false); getUserProfileInfo(profileKey, account?.publicKey, `profile_info_${APP_ID}`); getProfileScoredNotes(profileKey, account?.publicKey, `profile_scored_${APP_ID}`, 10); @@ -831,6 +837,7 @@ const addContact = (pubkey: string, source: PrimalUser[]) => { const stats = JSON.parse(content.content); updateStore('userStats', () => ({ ...stats })); + updateStore('fetchedUserStats', () => true); return; } } diff --git a/src/pages/Profile.tsx b/src/pages/Profile.tsx index 75203fe..480e54a 100644 --- a/src/pages/Profile.tsx +++ b/src/pages/Profile.tsx @@ -90,13 +90,8 @@ const Profile: Component = () => { profile?.actions.setProfileKey(hex); profile?.actions.clearNotes(); - profile?.actions.clearReplies(); - profile?.actions.clearContacts(); profile?.actions.fetchNotes(hex); - profile?.actions.fetchReplies(hex); - profile?.actions.fetchContactList(hex); - profile?.actions.fetchFollowerList(hex); } createEffect(() => { @@ -606,7 +601,7 @@ const Profile: Component = () => { - +