Formatting / Intl
This commit is contained in:
@ -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>
|
||||
);
|
||||
}
|
||||
|
@ -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({}));
|
||||
|
@ -2,4 +2,4 @@ export * from "./useRequestBuilder";
|
||||
export * from "./useSystemState";
|
||||
export * from "./useUserProfile";
|
||||
export * from "./context";
|
||||
export * from "./useUserSearch";
|
||||
export * from "./useUserSearch";
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user