diff --git a/src/pages/chat/EventListMessagesList.tsx b/src/pages/chat/EventListMessagesList.tsx index 2129b66..bd540d8 100644 --- a/src/pages/chat/EventListMessagesList.tsx +++ b/src/pages/chat/EventListMessagesList.tsx @@ -6,15 +6,16 @@ import {IconArrowDown, IconListSearch, IconMoodPuzzled, IconSpeakerphone} from " import {usePB} from "@/lib/pocketbase.tsx"; import {useDebouncedState} from "@mantine/hooks"; import {useInfiniteQuery} from "@tanstack/react-query"; -import {EventListModel} from "@/models/EventTypes.ts"; +import {EventListModel, EventModel} from "@/models/EventTypes.ts"; -const ListMessagesLink = ({eventList}: { eventList: EventListModel }) => { +const ListMessagesLink = ({eventList, event}: { eventList?: EventListModel, event?: EventModel }) => { + if (!eventList || !event) return null return { ({isActive}) => <>
- {eventList.name} ({eventList.expand?.event.name}) + {eventList.name} ({event.name})
} @@ -43,15 +44,15 @@ const AnnouncementsLink = () => { export default function EventListMessagesList() { const {user, pb} = usePB() - const [eventListNameQuery, setEventListNameQuery] = useDebouncedState("", 200) + const [chatEntriesQuery, setChatEntriesQuery] = useDebouncedState("", 200) const query = useInfiniteQuery({ - queryKey: ["eventLists", eventListNameQuery], + queryKey: ["chatEntries", chatEntriesQuery], queryFn: async ({pageParam}) => ( - await pb.collection("eventLists").getList(pageParam, 100, { - filter: `enableChat=true&&name~'${eventListNameQuery}'`, - sort: "-messages_via_eventList.created,name", - expand: "event" + await pb.collection("eventListSlotEntriesWithUser").getList(pageParam, 100, { + filter: `user='${user?.id}'&&eventList.enableChat=true&&listName~'${chatEntriesQuery}'`, + sort: "created", + expand: "event,eventList" }) ), getNextPageParam: (lastPage) => @@ -60,7 +61,7 @@ export default function EventListMessagesList() { enabled: !!user, }) - const eventLists = query.data?.pages.flatMap(t => t.items) || [] + const chatEntries = query.data?.pages.flatMap(t => t.items) || [] return
@@ -70,22 +71,26 @@ export default function EventListMessagesList() { } rightSection={query.isPending ? : undefined} - defaultValue={eventListNameQuery} - onChange={(e) => setEventListNameQuery(e.currentTarget.value)} + defaultValue={chatEntriesQuery} + onChange={(e) => setChatEntriesQuery(e.currentTarget.value)} placeholder={"Nach Listen suchen..."} /> - {eventLists.length === 0 ? + {chatEntries.length === 0 ? - {eventListNameQuery ? "Keine Listen gefunden" : "Keine Listen"} + {chatEntriesQuery ? "Keine Listen gefunden" : "Keine Listen"} : (
- {eventLists.map(list => )} + {chatEntries.map(entry => )} {query.hasNextPage && (