diff --git a/src/lib/PrimalNostr.ts b/src/lib/PrimalNostr.ts index f7cbc64..7041359 100644 --- a/src/lib/PrimalNostr.ts +++ b/src/lib/PrimalNostr.ts @@ -87,8 +87,6 @@ export const PrimalNostr: (pk?: string) => NostrExtension = (pk?: string) => { sec = await decryptWithPin(currentPin(), sec); } - console.log('SEC: ', sec) - const decoded = nip19.decode(sec); if (decoded.type !== 'nsec' || !decoded.data) { diff --git a/src/pages/CreateAccount.module.scss b/src/pages/CreateAccount.module.scss index 485fa4c..8e47c01 100644 --- a/src/pages/CreateAccount.module.scss +++ b/src/pages/CreateAccount.module.scss @@ -509,7 +509,7 @@ form { } } -.suggestedUsers { +.suggestions { height: calc(100vh - 320px); overflow-y: scroll; margin-bottom: 24px; diff --git a/src/pages/CreateAccount.tsx b/src/pages/CreateAccount.tsx index 0c19571..d8af1fa 100644 --- a/src/pages/CreateAccount.tsx +++ b/src/pages/CreateAccount.tsx @@ -34,9 +34,10 @@ import ButtonFollow from '../components/Buttons/ButtonFollow'; import ButtonTertiary from '../components/Buttons/ButtonTertiary'; import { sendContacts } from '../lib/notes'; import ButtonSecondary from '../components/Buttons/ButtonSecondary'; -import { convertToUser, nip05Verification } from '../stores/profile'; +import { convertToUser, nip05Verification, userName } from '../stores/profile'; import { subscribeTo } from '../sockets'; import { arrayMerge } from '../utils'; +import { stringStyleToObject } from '@solid-primitives/props'; type AutoSizedTextArea = HTMLTextAreaElement & { _baseScrollHeight: number }; @@ -303,36 +304,47 @@ const CreateAccount: Component = () => { const intl = useIntl(); } }; - const [suggestedUsers, setSuggestedUsers] = createStore([]); + type SuggestedUserData = { + users: Record, + groupNames: string[], + groups: Record, + } + + const [suggestedData, setSuggestedData] = createStore({ + users: {}, + groupNames: [], + groups: {}, + }); const getSugestedUsers = () => { const subId = `get_suggested_users_${APP_ID}`; - let users: PrimalUser[] = []; - const unsub = subscribeTo(subId, (type, _, content) => { if (type === 'EVENT') { if (content?.kind === Kind.SuggestedUsersByCategory) { + const list = JSON.parse(content.content); + let groups: Record = {}; + + for(let i=0; i u.pubkey) ]; + } + + setSuggestedData('groups', () => ({...groups})); + setSuggestedData('groupNames', () => Object.keys(groups)); } if (content?.kind === Kind.Metadata) { const userData = content as NostrUserContent; const user = convertToUser(userData); - if (suggestedUsersToFollow.includes(user.pubkey)){ - users.push({ ...user }); - } + !followed.includes(user.pubkey) && setFollowed(followed.length, user.pubkey); + setSuggestedData('users', () => ({ [user.pubkey]: { ...user }})) } } if (type === 'EOSE') { - - setSuggestedUsers(() => [...users]); - - const pks = users.map(x => x.pubkey); - - setFollowed(() => [...pks]); - unsub(); } }); @@ -374,28 +386,38 @@ const CreateAccount: Component = () => { const intl = useIntl(); const [followed, setFollowed] = createStore([]) - const isFollowingAllProminent = () => { - return !suggestedUsers.some((u) => !followed.includes(u.pubkey)); + const isFollowingAllInGroup = (group: string) => { + const pubkeys = suggestedData.groups[group] || []; + return !pubkeys.some((p) => !followed.includes(p)); }; - const onFollowProminent = () => { - const pubkeys = suggestedUsers.map(u => u.pubkey) || []; - setFollowed(() => [ ...pubkeys ]); + const onFollowGroup = (group: string) => { + const pubkeys = suggestedData.groups[group] || []; + let newFollows = pubkeys.filter(p => !followed.includes(p)); + setFollowed((fs) => [ ...fs, ...newFollows ]); }; - const onUnfollowProminent = () => { - setFollowed(() => []); + const onUnfollowGroup = (group: string) => { + const pubkeys = suggestedData.groups[group] || []; + + const newFollows = followed.filter(p => !pubkeys.includes(p)); + + setFollowed(() => [ ...newFollows ]); }; const onFollow = (pubkey: string) => { setFollowed(followed.length, () => pubkey); + console.log('FOL: ', followed); } const onUnfollow = (pubkey: string) => { - const follows = followed.filter(f => f !== pubkey) + const follows = followed.filter(f => f !== pubkey); + console.log('UNFOL: ', follows); setFollowed(() => [...follows]); } + const suggestedUser = (pubkey: string) => suggestedData.users[pubkey]; + return (
@@ -619,57 +641,67 @@ const CreateAccount: Component = () => { const intl = useIntl();
We found some Nostr accounts for you to follow:
-
-
- {intl.formatMessage(tAccount.prominentNostriches)} -
-
+
+ + {(groupName) => ( + <> +
+
+ {groupName} +
+
- - {intl.formatMessage(tAccount.followAll)} - - } - > - - {intl.formatMessage(tAccount.unfollowAll)} - - -
-
-
- - {user => ( -
-
- -
-
- {user.name} -
-
- {nip05Verification(user)} -
+ onFollowGroup(groupName)}> + {intl.formatMessage(tAccount.followAll)} + + } + > + onUnfollowGroup(groupName)}> + {intl.formatMessage(tAccount.unfollowAll)} + +
-
- onFollow(user.pubkey)}> - {intl.formatMessage(tAccount.follow)} - - } - > - onUnfollow(user.pubkey)}> - {intl.formatMessage(tAccount.unfollow)} - - + +
+ + {pubkey => ( +
+
+ +
+
+ {userName(suggestedUser(pubkey))} +
+
+ {nip05Verification(suggestedUser(pubkey))} +
+
+
+
+ onFollow(pubkey)}> + {intl.formatMessage(tAccount.follow)} + + } + > + onUnfollow(pubkey)}> + {intl.formatMessage(tAccount.unfollow)} + + +
+
+ )} +
-
+ )} +