mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-04-01 00:19:45 +02:00
fix bug with following list
This commit is contained in:
parent
83135a6490
commit
c7de102faf
@ -8,7 +8,6 @@ import {
|
||||
MenuList,
|
||||
MenuOptionGroup,
|
||||
} from "@chakra-ui/react";
|
||||
import { Kind } from "nostr-tools";
|
||||
|
||||
import { usePeopleListContext } from "../../providers/people-list-provider";
|
||||
import useUserLists from "../../hooks/use-user-lists";
|
||||
@ -26,22 +25,22 @@ export default function PeopleListSelection({
|
||||
const account = useCurrentAccount();
|
||||
const lists = useUserLists(account?.pubkey);
|
||||
const { lists: favoriteLists } = useFavoriteLists();
|
||||
const { list, setList, listEvent } = usePeopleListContext();
|
||||
const { selected, setSelected, listEvent } = usePeopleListContext();
|
||||
|
||||
const handleSelect = (value: string | string[]) => {
|
||||
if (typeof value === "string") {
|
||||
setList(value);
|
||||
setSelected(value);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Menu>
|
||||
<MenuButton as={Button} {...props}>
|
||||
{listEvent ? getListName(listEvent) : list === "global" ? "Global" : "Loading..."}
|
||||
{listEvent ? getListName(listEvent) : selected === "global" ? "Global" : "Loading..."}
|
||||
</MenuButton>
|
||||
<MenuList zIndex={100}>
|
||||
<MenuOptionGroup value={list} onChange={handleSelect} type="radio">
|
||||
{account && <MenuItemOption value={`${Kind.Contacts}:${account.pubkey}`}>Following</MenuItemOption>}
|
||||
<MenuOptionGroup value={selected} onChange={handleSelect} type="radio">
|
||||
{account && <MenuItemOption value="following">Following</MenuItemOption>}
|
||||
{!hideGlobalOption && <MenuItemOption value="global">Global</MenuItemOption>}
|
||||
{lists.length > 0 && <MenuDivider />}
|
||||
{lists
|
||||
@ -55,7 +54,7 @@ export default function PeopleListSelection({
|
||||
{favoriteLists.length > 0 && (
|
||||
<>
|
||||
<MenuDivider />
|
||||
<MenuOptionGroup value={list} onChange={handleSelect} type="radio" title="Favorites">
|
||||
<MenuOptionGroup value={selected} onChange={handleSelect} type="radio" title="Favorites">
|
||||
{favoriteLists
|
||||
.filter((l) => l.kind === PEOPLE_LIST_KIND)
|
||||
.map((list) => (
|
||||
|
@ -84,6 +84,7 @@ export default function PublishLog({ ...props }: Omit<FlexProps, "children">) {
|
||||
|
||||
return (
|
||||
<Flex overflow="hidden" direction="column" gap="1" {...props}>
|
||||
{log.length > 0 && <Text>Activity log:</Text>}
|
||||
{log.map((pub) => (
|
||||
<PublishAction key={pub.id} pub={pub} />
|
||||
))}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Flex,
|
||||
Heading,
|
||||
Image,
|
||||
@ -189,11 +190,10 @@ export default function ZapModal({
|
||||
placeholder="Comment"
|
||||
{...register("comment", { maxLength: lnurlMetadata?.commentAllowed ?? 150 })}
|
||||
autoComplete="off"
|
||||
autoFocus={!initialComment}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Flex gap="2" alignItems="center" flexWrap="wrap">
|
||||
<ButtonGroup size="sm" alignItems="center" flexWrap="wrap">
|
||||
{customZapAmounts
|
||||
.split(",")
|
||||
.map((v) => parseInt(v))
|
||||
@ -209,7 +209,7 @@ export default function ZapModal({
|
||||
{amount}
|
||||
</Button>
|
||||
))}
|
||||
</Flex>
|
||||
</ButtonGroup>
|
||||
|
||||
<Flex gap="2">
|
||||
<Input
|
||||
|
@ -9,20 +9,21 @@ import { NostrEvent } from "../types/nostr-event";
|
||||
import { NostrQuery } from "../types/nostr-query";
|
||||
import { searchParamsToJson } from "../helpers/url";
|
||||
|
||||
export type ListId = "global" | string;
|
||||
export type ListId = "following" | "global" | string;
|
||||
export type Person = { pubkey: string; relay?: string };
|
||||
|
||||
export type PeopleListContextType = {
|
||||
list: ListId;
|
||||
selected: ListId;
|
||||
listId?: string;
|
||||
listEvent?: NostrEvent;
|
||||
people: Person[] | undefined;
|
||||
setList: (list: ListId) => void;
|
||||
setSelected: (list: ListId) => void;
|
||||
filter: NostrQuery | undefined;
|
||||
};
|
||||
const PeopleListContext = createContext<PeopleListContextType>({
|
||||
setList: () => {},
|
||||
setSelected: () => {},
|
||||
people: undefined,
|
||||
list: "global",
|
||||
selected: "global",
|
||||
filter: undefined,
|
||||
});
|
||||
|
||||
@ -30,41 +31,52 @@ export function usePeopleListContext() {
|
||||
return useContext(PeopleListContext);
|
||||
}
|
||||
|
||||
function useListCoordinate(listId: ListId) {
|
||||
const account = useCurrentAccount();
|
||||
|
||||
return useMemo(() => {
|
||||
if (listId === "following") return account ? `${Kind.Contacts}:${account.pubkey}` : undefined;
|
||||
if (listId === "global") return undefined;
|
||||
return listId;
|
||||
}, [listId, account]);
|
||||
}
|
||||
|
||||
export type PeopleListProviderProps = PropsWithChildren & {
|
||||
initList?: "following" | "global";
|
||||
initList?: ListId;
|
||||
};
|
||||
export default function PeopleListProvider({ children, initList = "following" }: PeopleListProviderProps) {
|
||||
const account = useCurrentAccount();
|
||||
const [params, setParams] = useSearchParams({
|
||||
people: account && initList === "following" ? `${Kind.Contacts}:${account.pubkey}` : "global",
|
||||
people: initList,
|
||||
});
|
||||
|
||||
const list = params.get("people") as ListId;
|
||||
const setList = useCallback(
|
||||
const selected = params.get("people") as ListId;
|
||||
const setSelected = useCallback(
|
||||
(value: ListId) => {
|
||||
setParams((p) => ({ ...searchParamsToJson(p), people: value }));
|
||||
},
|
||||
[setParams],
|
||||
);
|
||||
|
||||
const listEvent = useReplaceableEvent(list !== "global" ? list : undefined, [], true);
|
||||
const listId = useListCoordinate(selected);
|
||||
const listEvent = useReplaceableEvent(listId, [], true);
|
||||
|
||||
const people = listEvent && getPubkeysFromList(listEvent);
|
||||
|
||||
const filter = useMemo<NostrQuery | undefined>(() => {
|
||||
if (list === "global") return {};
|
||||
if (selected === "global") return {};
|
||||
return people && { authors: people.map((p) => p.pubkey) };
|
||||
}, [people, list]);
|
||||
}, [people, selected]);
|
||||
|
||||
const context = useMemo(
|
||||
() => ({
|
||||
people,
|
||||
list,
|
||||
selected,
|
||||
listId,
|
||||
listEvent,
|
||||
setList,
|
||||
setSelected,
|
||||
filter,
|
||||
}),
|
||||
[list, setList, people, listEvent],
|
||||
[selected, setSelected, people, listEvent],
|
||||
);
|
||||
|
||||
return <PeopleListContext.Provider value={context}>{children}</PeopleListContext.Provider>;
|
||||
|
@ -24,7 +24,7 @@ function HomePage() {
|
||||
);
|
||||
|
||||
const { relays } = useRelaySelectionContext();
|
||||
const { list, filter } = usePeopleListContext();
|
||||
const { listId, filter } = usePeopleListContext();
|
||||
|
||||
const kinds = [Kind.Text, Kind.Repost, 2];
|
||||
const query = useMemo<NostrRequestFilter>(() => {
|
||||
@ -32,7 +32,7 @@ function HomePage() {
|
||||
return { ...filter, kinds };
|
||||
}, [filter]);
|
||||
|
||||
const timeline = useTimelineLoader(`${list}-home-feed`, relays, query, {
|
||||
const timeline = useTimelineLoader(`${listId}-home-feed`, relays, query, {
|
||||
enabled: !!filter,
|
||||
eventFilter,
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ import ListCard from "../components/list-card";
|
||||
import { getEventUID } from "../../../helpers/nostr/events";
|
||||
|
||||
function BrowseListPage() {
|
||||
const { filter, list } = usePeopleListContext();
|
||||
const { filter, listId } = usePeopleListContext();
|
||||
const showEmpty = useDisclosure();
|
||||
const showMute = useDisclosure();
|
||||
const [listKind, setListKind] = useState(PEOPLE_LIST_KIND);
|
||||
@ -42,7 +42,7 @@ function BrowseListPage() {
|
||||
);
|
||||
const readRelays = useReadRelayUrls();
|
||||
const timeline = useTimelineLoader(
|
||||
`${list}-lists`,
|
||||
`${listId}-lists`,
|
||||
readRelays,
|
||||
{ ...filter, kinds: [PEOPLE_LIST_KIND, NOTE_LIST_KIND] },
|
||||
{ enabled: !!filter, eventFilter },
|
||||
|
@ -20,16 +20,16 @@ function StreamsPage() {
|
||||
useAppTitle("Streams");
|
||||
const relays = useRelaySelectionRelays();
|
||||
|
||||
const { filter, list } = usePeopleListContext();
|
||||
const { filter, listId } = usePeopleListContext();
|
||||
const query = useMemo<NostrRequestFilter>(() => {
|
||||
if (list === "global" || !filter) return { kinds: [STREAM_KIND] };
|
||||
if (!listId || !filter) return { kinds: [STREAM_KIND] };
|
||||
return [
|
||||
{ authors: filter.authors, kinds: [STREAM_KIND] },
|
||||
{ "#p": filter.authors, kinds: [STREAM_KIND] },
|
||||
];
|
||||
}, [filter, list]);
|
||||
}, [filter, listId]);
|
||||
|
||||
const timeline = useTimelineLoader(`${list}-streams`, relays, query, { enabled: !!filter });
|
||||
const timeline = useTimelineLoader(`${listId}-streams`, relays, query, { enabled: !!filter });
|
||||
|
||||
useRelaysChanged(relays, () => timeline.reset());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user