mirror of
https://github.com/kennethnym/freya
synced 2026-07-04 15:11:15 +01:00
chore: save wip changes
This commit is contained in:
23
apps/freya-client/src/conversations/conversation-view.tsx
Normal file
23
apps/freya-client/src/conversations/conversation-view.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
useListConversationEntriesQuery,
|
||||
useDefaultConversationQuery,
|
||||
useListConversationsQuery,
|
||||
} from "./queries";
|
||||
|
||||
export function ConversationView() {
|
||||
const { data: conversation } = useQuery(useDefaultConversationQuery());
|
||||
const { data: entries } = useQuery(
|
||||
useListConversationEntriesQuery(conversation?.id),
|
||||
);
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={entries ?? []}
|
||||
keyExtractor={(item) => item.id}
|
||||
renderItem={({ item }) => <div key={item.id}>{item.kind}</div>}
|
||||
/>
|
||||
);
|
||||
}
|
||||
15
apps/freya-client/src/conversations/conversations.ts
Normal file
15
apps/freya-client/src/conversations/conversations.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
ConversationEntryKind,
|
||||
ConversationEntryPayload,
|
||||
ConversationEntryVisibility,
|
||||
} from "@freya/core"
|
||||
import { type } from "arktype"
|
||||
|
||||
export const ConversationEntry = type({
|
||||
id: "string.uuid",
|
||||
sequence: "number",
|
||||
kind: type.enumerated(...Object.values(ConversationEntryKind)),
|
||||
visibility: type.enumerated(...Object.values(ConversationEntryVisibility)),
|
||||
fileId: "string | null",
|
||||
payload: ConversationEntryPayload,
|
||||
})
|
||||
41
apps/freya-client/src/conversations/queries.ts
Normal file
41
apps/freya-client/src/conversations/queries.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { queryOptions, skipToken } from "@tanstack/react-query"
|
||||
import { type } from "arktype"
|
||||
|
||||
import { useApiClient } from "@/api/client"
|
||||
|
||||
import { ConversationEntry } from "./conversations"
|
||||
|
||||
const ConversationQueryResponse = type({
|
||||
entries: ConversationEntry.array(),
|
||||
})
|
||||
|
||||
export function useListConversationsQuery() {
|
||||
const api = useApiClient()
|
||||
return queryOptions({
|
||||
queryKey: ["conversations"],
|
||||
queryFn: async () =>
|
||||
api
|
||||
.request("/conversations", { method: "GET" })
|
||||
.then(([, json]) => ConversationQueryResponse.assert(json)),
|
||||
})
|
||||
}
|
||||
|
||||
export function useDefaultConversationQuery() {
|
||||
return queryOptions({
|
||||
...useListConversationsQuery(),
|
||||
select: (data) => (data.entries.length === 0 ? null : data.entries[0]),
|
||||
})
|
||||
}
|
||||
|
||||
export function useListConversationEntriesQuery(id?: string) {
|
||||
const api = useApiClient()
|
||||
return queryOptions({
|
||||
queryKey: ["conversations", id],
|
||||
queryFn: id
|
||||
? async () =>
|
||||
api
|
||||
.request(`/conversations/${id}/entries`, { method: "GET" })
|
||||
.then(([, json]) => ConversationQueryResponse.assert(json).entries)
|
||||
: skipToken,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user