Fix Follow screen

This commit is contained in:
Bojan Mojsilovic 2023-10-13 19:19:41 +02:00
parent aec83dee77
commit f4c86454b8
5 changed files with 103 additions and 14 deletions

View File

@ -131,7 +131,8 @@ export enum Kind {
ImportResponse = 10_000_127,
LinkMetadata = 10_000_128,
FilteringReason = 10_000_131,
UserFollowerCounts= 10_000_133,
UserFollowerCounts = 10_000_133,
SuggestedUsersByCategory = 10_000_134,
}
export const relayConnectingTimeout = 1000;
@ -324,3 +325,30 @@ export const profileContactListPage = 50;
export const pinEncodePrefix = 'prpec';
export const pinEncodeIVSeparator = '?iv=';
export const suggestedUsersToFollow = [
"82341f882b6eabcd2ba7f1ef90aad961cf074af15b9ef44a09f9d2a8fbfbe6a2", //jack
"3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d", //fiatjaf
"e88a691e98d9987c964521dff60025f60700378a4879180dcbbb4a5027850411", //nvk
"fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52", //pablof7z
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245", //jb55
"6e468422dfb74a5738702a8823b9b28168abab8655faacb6853cd0ee15deee93", //gigi
"04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", //odell
"472f440f29ef996e92a186b8d320ff180c855903882e59d50de1b8bd5669301e", //marty bent
"76c71aae3a491f1d9eec47cba17e229cda4113a0bbb6e6ae1776d7643e29cafa", //rabble
"eab0e756d32b80bcd464f3d844b8040303075a13eabc3599a762c9ac7ab91f4f", //lyn alden
"85080d3bad70ccdcd7f74c29a44f55bb85cbcd3dd0cbb957da1d215bdb931204", //preston pysh
"83e818dfbeccea56b0f551576b3fd39a7a50e1d8159343500368fa085ccd964b", //jeff booth
"1b11ed41e815234599a52050a6a40c79bdd3bfa3d65e5d4a2c8d626698835d6d", //andre
"91c9a5e1a9744114c6fe2d61ae4de82629eaaa0fb52f48288093c7e7e036f832", //rockstar
"b0b8fbd9578ac23e782d97a32b7b3a72cda0760761359bd65661d42752b4090a", //guy swann
"3fc5f8553abd753ac47967c4c468cfd08e8cb9dee71b79e12d5adab205bc04d3", //max
"b708f7392f588406212c3882e7b3bc0d9b08d62f95fa170d099127ece2770e5e", //dk
"7fa56f5d6962ab1e3cd424e758c3002b8665f7b0d8dcee9fe9e288d7751ac194", //verbiricha
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", //vitor
"ee11a5dff40c19a555f41fe42b48f00e618c91225622ae37b6c2bb67b76c4e49", //Michael Dilger
"00000000827ffaa94bfea288c3dfce4422c794fbb96625b6b31e9049f729d700", //cameri
"3f770d65d3a764a9c5cb503ae123e62ec7598ad035d836e2a810f3877a745b24", //derek ross
"eda6845cc2269bea10f010744ad79409acb7129d96857d4bf19e027696299292", //brianna
"d61f3bc5b3eb4400efdae6169a5c17cabf3246b514361de939ce4a1a0da6ef4a", //miljan
];

View File

@ -326,7 +326,11 @@ export const sendAllowList = async (allowlist: string[], date: number, content:
return await sendEvent(event, relays, relaySettings);
};
export const getSuggestions = async () => {
const resp = await fetch('https://media.primal.net/api/suggestions');
console.log('>>>> ', resp)
export const getSuggestions = async (subid: string) => {
sendMessage(JSON.stringify([
"REQ",
subid,
{cache: ["get_suggested_users"]},
]));
};

View File

@ -1,13 +1,13 @@
import { useIntl } from '@cookbook/solid-intl';
import { useNavigate } from '@solidjs/router';
import { Component, createEffect, createSignal, For, onMount, Show } from 'solid-js';
import { Component, createEffect, createMemo, createSignal, For, onMount, Show } from 'solid-js';
import { APP_ID } from '../App';
import Avatar from '../components/Avatar/Avatar';
import Loader from '../components/Loader/Loader';
import PageCaption from '../components/PageCaption/PageCaption';
import PageTitle from '../components/PageTitle/PageTitle';
import { useToastContext } from '../components/Toaster/Toaster';
import { usernameRegex, Kind } from '../constants';
import { usernameRegex, Kind, suggestedUsersToFollow } from '../constants';
import { useAccountContext } from '../contexts/AccountContext';
import { useMediaContext } from '../contexts/MediaContext';
import { useProfileContext } from '../contexts/ProfileContext';
@ -20,7 +20,7 @@ import {
settings as tSettings,
toast as tToast,
} from '../translations';
import { NostrMediaUploaded, NostrRelays } from '../types/primal';
import { NostrMediaUploaded, NostrRelays, NostrUserContent, PrimalUser, UserCategory } from '../types/primal';
import styles from './CreateAccount.module.scss';
import { createStore, reconcile } from 'solid-js/store';
@ -34,7 +34,9 @@ import ButtonFollow from '../components/Buttons/ButtonFollow';
import ButtonTertiary from '../components/Buttons/ButtonTertiary';
import { sendContacts } from '../lib/notes';
import ButtonSecondary from '../components/Buttons/ButtonSecondary';
import { nip05Verification } from '../stores/profile';
import { convertToUser, nip05Verification } from '../stores/profile';
import { subscribeTo } from '../sockets';
import { arrayMerge } from '../utils';
type AutoSizedTextArea = HTMLTextAreaElement & { _baseScrollHeight: number };
@ -297,6 +299,43 @@ const CreateAccount: Component = () => { const intl = useIntl();
}
};
const [suggestedUsers, setSuggestedUsers] = createStore<PrimalUser[]>([]);
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) {
}
if (content?.kind === Kind.Metadata) {
const userData = content as NostrUserContent;
const user = convertToUser(userData);
if (suggestedUsersToFollow.includes(user.pubkey)){
users.push({ ...user });
}
}
}
if (type === 'EOSE') {
setSuggestedUsers(() => [...users]);
const pks = users.map(x => x.pubkey);
setFollowed(() => [...pks]);
unsub();
}
});
getSuggestions(subId);
};
onMount(() => {
const { sec, pubkey } = generateKeys(true);
@ -306,8 +345,7 @@ const CreateAccount: Component = () => { const intl = useIntl();
setTempNsec(nsec);
setCreatedAccount(() => ({ sec: nsec, pubkey }));
getSuggestions();
search?.actions.getRecomendedUsers();
getSugestedUsers();
});
@ -333,11 +371,11 @@ const CreateAccount: Component = () => { const intl = useIntl();
const [followed, setFollowed] = createStore<string[]>([])
const isFollowingAllProminent = () => {
return !search?.users.some((u) => !followed.includes(u.pubkey));
return !suggestedUsers.some((u) => !followed.includes(u.pubkey));
};
const onFollowProminent = () => {
const pubkeys = search?.users.map(u => u.pubkey) || [];
const pubkeys = suggestedUsers.map(u => u.pubkey) || [];
setFollowed(() => [ ...pubkeys ]);
};
@ -566,6 +604,7 @@ const CreateAccount: Component = () => { const intl = useIntl();
/>
</div>
<div class={currentStep() === 'follow' ? '' : 'invisible'}>
<div class={styles.recomendedFollowsCaption}>
<div class={styles.caption}>
@ -588,7 +627,7 @@ const CreateAccount: Component = () => { const intl = useIntl();
</div>
</div>
<div>
<For each={search?.users}>
<For each={suggestedUsers}>
{user => (
<div class={styles.userToFollow}>
<div class={styles.info}>

13
src/types/primal.d.ts vendored
View File

@ -187,6 +187,11 @@ export type NostrUserZaps = {
id: string,
};
export type NostrSuggestedUsers = {
kind: Kind.SuggestedUsersByCategory,
content: string,
};
export type NostrEventContent =
NostrNoteContent |
NostrUserContent |
@ -212,7 +217,8 @@ export type NostrEventContent =
NostrLinkMetadata |
NostrFilteringReason |
NostrUserFollwerCounts |
NostrUserZaps;
NostrUserZaps |
NostrSuggestedUsers;
export type NostrEvent = [
type: "EVENT",
@ -599,3 +605,8 @@ export type ComponentLog = {
domId: string,
props: any,
}
export type UserCategory = {
group: string,
members: { name?: string, pubkey: string }[],
}

View File

@ -68,3 +68,10 @@ export const parseBolt11 = (bolt11: string) => {
return amount;
}
export const arrayMerge: <T, >(a: T[], b: T[], predicate?: (x: T, y: T) => boolean) => T[] = (a, b, predicate = (a, b) => a === b) => {
const c = [...a]; // copy to avoid side effects
// add all items from B to copy C if they're not already present
b.forEach((bItem) => (c.some((cItem) => predicate(bItem, cItem)) ? null : c.push(bItem)))
return c;
}