Formatting / Intl

This commit is contained in:
2023-08-24 16:55:36 +01:00
parent 4b85a16904
commit 9c5d1ea55d
10 changed files with 134 additions and 73 deletions

View File

@ -38,7 +38,9 @@ export function UserPosts(props: { pubkey: string }) {
}
export function MyApp() {
return <SnortContext.Provider value={System}>
<UserPosts pubkey="63fe6318dc58583cfe16810f86dd09e18bfd76aabc24a0081ce2856f330504ed" />
</SnortContext.Provider>;
return (
<SnortContext.Provider value={System}>
<UserPosts pubkey="63fe6318dc58583cfe16810f86dd09e18bfd76aabc24a0081ce2856f330504ed" />
</SnortContext.Provider>
);
}

View File

@ -1,4 +1,4 @@
import { createContext } from "react";
import { NostrSystem, SystemInterface } from "@snort/system";
export const SnortContext = createContext<SystemInterface>(new NostrSystem({}));
export const SnortContext = createContext<SystemInterface>(new NostrSystem({}));

View File

@ -2,4 +2,4 @@ export * from "./useRequestBuilder";
export * from "./useSystemState";
export * from "./useUserProfile";
export * from "./context";
export * from "./useUserSearch";
export * from "./useUserSearch";

View File

@ -7,7 +7,7 @@ import { SnortContext } from "./context";
* Send a query to the relays and wait for data
*/
const useRequestBuilder = <TStore extends NoteStore, TSnapshot = ReturnType<TStore["getSnapshotData"]>>(
type: { new(): TStore },
type: { new (): TStore },
rb: RequestBuilder | null,
) => {
const system = useContext(SnortContext);

View File

@ -6,7 +6,7 @@ import { SnortContext } from "./context";
* Gets a profile from cache or requests it from the relays
*/
export function useUserProfile(pubKey?: HexKey): MetadataCache | undefined {
const system = useContext(SnortContext);
const system = useContext(SnortContext);
return useSyncExternalStore<MetadataCache | undefined>(
h => {
if (pubKey) {

View File

@ -4,34 +4,34 @@ import { fetchNip05Pubkey } from "@snort/shared";
import { SnortContext } from "./context";
export function useUserSearch() {
const system = useContext(SnortContext);
const cache = system.ProfileLoader.Cache as UserProfileCache;
const system = useContext(SnortContext);
const cache = system.ProfileLoader.Cache as UserProfileCache;
async function search(input: string): Promise<Array<string>> {
// try exact match first
if (input.length === 64 && [...input].every(c => !isNaN(parseInt(c, 16)))) {
return [input];
}
if (input.startsWith(NostrPrefix.PublicKey) || input.startsWith(NostrPrefix.Profile)) {
const link = tryParseNostrLink(input);
if (link) {
return [link.id]
}
}
if (input.includes("@")) {
const [name, domain] = input.split("@");
const pk = await fetchNip05Pubkey(name, domain);
if (pk) {
return [pk];
}
}
// search cache
const cacheResults = await cache.search(input);
return cacheResults.map(v => v.pubkey);
async function search(input: string): Promise<Array<string>> {
// try exact match first
if (input.length === 64 && [...input].every(c => !isNaN(parseInt(c, 16)))) {
return [input];
}
return search;
}
if (input.startsWith(NostrPrefix.PublicKey) || input.startsWith(NostrPrefix.Profile)) {
const link = tryParseNostrLink(input);
if (link) {
return [link.id];
}
}
if (input.includes("@")) {
const [name, domain] = input.split("@");
const pk = await fetchNip05Pubkey(name, domain);
if (pk) {
return [pk];
}
}
// search cache
const cacheResults = await cache.search(input);
return cacheResults.map(v => v.pubkey);
}
return search;
}