mirror of
https://github.com/lumehq/lume.git
synced 2025-06-28 04:00:51 +02:00
update kind 41
This commit is contained in:
parent
e7bcf6c3f8
commit
62d6f06b39
@ -19,7 +19,12 @@ export default function ChannelsListItem({ data }: { data: any }) {
|
|||||||
pageID === data.event_id ? 'dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800' : ''
|
pageID === data.event_id ? 'dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800' : ''
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="inline-flex h-5 w-5 items-center justify-center rounded bg-zinc-900 group-hover:bg-zinc-800">
|
<div
|
||||||
|
className={twMerge(
|
||||||
|
'inline-flex h-5 w-5 items-center justify-center rounded bg-zinc-900 group-hover:bg-zinc-800',
|
||||||
|
pageID === data.event_id ? 'dark:bg-zinc-800 group-hover:dark:bg-zinc-700' : ''
|
||||||
|
)}
|
||||||
|
>
|
||||||
<span className="text-xs text-zinc-200">#</span>
|
<span className="text-xs text-zinc-200">#</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -11,16 +11,16 @@ export default function ChannelsList() {
|
|||||||
const { data, error }: any = useSWR('channels', fetcher);
|
const { data, error }: any = useSWR('channels', fetcher);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col gap-px">
|
||||||
{!data || error ? (
|
{!data || error ? (
|
||||||
<>
|
<>
|
||||||
<div className="inline-flex h-8 items-center gap-2 rounded-md px-2.5">
|
<div className="inline-flex h-8 items-center gap-2 rounded-md px-2.5">
|
||||||
<div className="relative h-5 w-5 shrink-0 animate-pulse rounded bg-zinc-800"></div>
|
<div className="relative h-5 w-5 shrink-0 animate-pulse rounded bg-zinc-800"></div>
|
||||||
<div className="h-3 w-full animate-pulse bg-zinc-800"></div>
|
<div className="h-3 w-full animate-pulse rounded-sm bg-zinc-800"></div>
|
||||||
</div>
|
</div>
|
||||||
<div className="inline-flex h-8 items-center gap-2 rounded-md px-2.5">
|
<div className="inline-flex h-8 items-center gap-2 rounded-md px-2.5">
|
||||||
<div className="relative h-5 w-5 shrink-0 animate-pulse rounded bg-zinc-800"></div>
|
<div className="relative h-5 w-5 shrink-0 animate-pulse rounded bg-zinc-800"></div>
|
||||||
<div className="h-3 w-full animate-pulse bg-zinc-800"></div>
|
<div className="h-3 w-full animate-pulse rounded-sm bg-zinc-800"></div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
@ -9,7 +9,7 @@ import { DEFAULT_AVATAR, WRITEONLY_RELAYS } from '@stores/constants';
|
|||||||
|
|
||||||
import { dateToUnix } from '@utils/date';
|
import { dateToUnix } from '@utils/date';
|
||||||
import { useActiveAccount } from '@utils/hooks/useActiveAccount';
|
import { useActiveAccount } from '@utils/hooks/useActiveAccount';
|
||||||
import { getChannel, updateChannelMetadata } from '@utils/storage';
|
import { getChannel } from '@utils/storage';
|
||||||
|
|
||||||
import { Dialog, Transition } from '@headlessui/react';
|
import { Dialog, Transition } from '@headlessui/react';
|
||||||
import { getEventHash, signEvent } from 'nostr-tools';
|
import { getEventHash, signEvent } from 'nostr-tools';
|
||||||
@ -58,15 +58,13 @@ export default function ChannelUpdateModal({ id }: { id: string }) {
|
|||||||
created_at: dateToUnix(),
|
created_at: dateToUnix(),
|
||||||
kind: 41,
|
kind: 41,
|
||||||
pubkey: account.pubkey,
|
pubkey: account.pubkey,
|
||||||
tags: [],
|
tags: [['e', id]],
|
||||||
};
|
};
|
||||||
event.id = getEventHash(event);
|
event.id = getEventHash(event);
|
||||||
event.sig = signEvent(event, account.privkey);
|
event.sig = signEvent(event, account.privkey);
|
||||||
|
|
||||||
// publish channel
|
// publish channel
|
||||||
pool.publish(event, WRITEONLY_RELAYS);
|
pool.publish(event, WRITEONLY_RELAYS);
|
||||||
// update channel metadata in database
|
|
||||||
updateChannelMetadata(event.id, event.content);
|
|
||||||
// reset form
|
// reset form
|
||||||
reset();
|
reset();
|
||||||
// close modal
|
// close modal
|
||||||
|
@ -2,10 +2,10 @@ import { RelayContext } from '@shared/relayProvider';
|
|||||||
|
|
||||||
import { READONLY_RELAYS } from '@stores/constants';
|
import { READONLY_RELAYS } from '@stores/constants';
|
||||||
|
|
||||||
import { getChannel } from '@utils/storage';
|
import { getChannel, updateChannelMetadata } from '@utils/storage';
|
||||||
|
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import useSWR from 'swr';
|
import useSWR, { useSWRConfig } from 'swr';
|
||||||
import useSWRSubscription from 'swr/subscription';
|
import useSWRSubscription from 'swr/subscription';
|
||||||
|
|
||||||
const fetcher = async ([, id]) => {
|
const fetcher = async ([, id]) => {
|
||||||
@ -20,39 +20,37 @@ const fetcher = async ([, id]) => {
|
|||||||
export function useChannelProfile(id: string, channelPubkey: string) {
|
export function useChannelProfile(id: string, channelPubkey: string) {
|
||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
|
|
||||||
const { data: cache, isLoading } = useSWR(['channel-cache-profile', id], fetcher);
|
const { mutate } = useSWRConfig();
|
||||||
const { data, error } = useSWRSubscription(
|
const { data, isLoading } = useSWR(['channel-metadata', id], fetcher);
|
||||||
!isLoading && cache ? ['channel-profile', id] : null,
|
|
||||||
([, key], { next }) => {
|
useSWRSubscription(!isLoading && data ? ['channel-metadata', id] : null, ([, key], {}) => {
|
||||||
// subscribe to channel
|
// subscribe to channel
|
||||||
const unsubscribe = pool.subscribe(
|
const unsubscribe = pool.subscribe(
|
||||||
[
|
[
|
||||||
{
|
|
||||||
'#e': [key],
|
|
||||||
authors: [channelPubkey],
|
|
||||||
kinds: [41],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
READONLY_RELAYS,
|
|
||||||
(event: { content: string }) => {
|
|
||||||
next(null, JSON.parse(event.content));
|
|
||||||
},
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
{
|
{
|
||||||
unsubscribeOnEose: true,
|
'#e': [key],
|
||||||
}
|
authors: [channelPubkey],
|
||||||
);
|
kinds: [41],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
READONLY_RELAYS,
|
||||||
|
(event: { content: string }) => {
|
||||||
|
// update in local database
|
||||||
|
updateChannelMetadata(key, event.content);
|
||||||
|
// revaildate
|
||||||
|
mutate(['channel-metadata', key]);
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
unsubscribeOnEose: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
if (!data || error) {
|
return data;
|
||||||
return cache;
|
|
||||||
} else {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user