diff --git a/app/(home-pages)/home/HomeLayout.tsx b/app/(home-pages)/home/HomeLayout.tsx index 4f731b95..0ba95c2f 100644 --- a/app/(home-pages)/home/HomeLayout.tsx +++ b/app/(home-pages)/home/HomeLayout.tsx @@ -31,7 +31,7 @@ import { PublicationBanner, } from "./HomeEmpty/HomeEmpty"; -type Leaflet = { +export type Leaflet = { added_at: string; token: PermissionToken & { leaflets_in_publications?: Exclude< diff --git a/app/(home-pages)/looseleafs/LooseleafsLayout.tsx b/app/(home-pages)/looseleafs/LooseleafsLayout.tsx index 25bba976..1568d8f8 100644 --- a/app/(home-pages)/looseleafs/LooseleafsLayout.tsx +++ b/app/(home-pages)/looseleafs/LooseleafsLayout.tsx @@ -3,9 +3,14 @@ import { DashboardLayout } from "components/PageLayouts/DashboardLayout"; import { useCardBorderHidden } from "components/Pages/useCardBorderHidden"; import { useState } from "react"; import { useDebouncedEffect } from "src/hooks/useDebouncedEffect"; -import { Fact } from "src/replicache"; +import { Fact, PermissionToken } from "src/replicache"; import { Attribute } from "src/replicache/attributes"; import { Actions } from "../home/Actions/Actions"; +import { callRPC } from "app/api/rpc/client"; +import { useIdentityData } from "components/IdentityProvider"; +import useSWR from "swr"; +import { getHomeDocs } from "../home/storage"; +import { Leaflet, LeafletList } from "../home/HomeLayout"; export const LooseleafsLayout = (props: { entityID: string | null; @@ -58,5 +63,53 @@ export const LooseleafList = (props: { searchValue: string; cardBorderHidden: boolean; }) => { - return
hello
; + let { identity } = useIdentityData(); + let { data: initialFacts } = useSWR( + "home-leaflet-data", + async () => { + if (identity) { + let { result } = await callRPC("getFactsFromHomeLeaflets", { + tokens: identity.permission_token_on_homepage.map( + (ptrh) => ptrh.permission_tokens.root_entity, + ), + }); + let titles = { + ...result.titles, + ...identity.permission_token_on_homepage.reduce( + (acc, tok) => { + let title = + tok.permission_tokens.leaflets_in_publications[0]?.title; + if (title) acc[tok.permission_tokens.root_entity] = title; + return acc; + }, + {} as { [k: string]: string }, + ), + }; + return { ...result, titles }; + } + }, + { fallbackData: { facts: props.initialFacts, titles: props.titles } }, + ); + + let leaflets: Leaflet[] = identity + ? identity.permission_token_on_homepage + .filter( + (ptoh) => ptoh.permission_tokens.leaflets_to_documents.length > 0, + ) + .map((ptoh) => ({ + added_at: ptoh.created_at, + token: ptoh.permission_tokens as PermissionToken, + })) + : []; + return ( + + ); };