From 982c0e95fcb49ef04c2b4c3765a19e3458eaa3c0 Mon Sep 17 00:00:00 2001 From: celine Date: Wed, 19 Nov 2025 19:14:34 -0500 Subject: [PATCH] added filters for archive on home, filtered archive out of default leaflet list --- app/(home-pages)/home/HomeLayout.tsx | 50 +++++++++++-------- .../home/LeafletList/LeafletInfo.tsx | 30 ++++++----- .../home/LeafletList/LeafletListItem.tsx | 28 +++++++---- components/Layout.tsx | 4 +- components/PageLayouts/DashboardLayout.tsx | 32 +++++++++++- 5 files changed, 96 insertions(+), 48 deletions(-) diff --git a/app/(home-pages)/home/HomeLayout.tsx b/app/(home-pages)/home/HomeLayout.tsx index 498b1820..62fa1962 100644 --- a/app/(home-pages)/home/HomeLayout.tsx +++ b/app/(home-pages)/home/HomeLayout.tsx @@ -71,6 +71,11 @@ export const HomeLayout = (props: { let hasPubs = !identity || identity.publications.length === 0 ? false : true; let hasTemplates = useTemplateState((s) => s.templates).length === 0 ? false : true; + let hasArchived = + identity && + identity.permission_token_on_homepage.filter( + (leaflet) => leaflet.archived === true, + ).length > 0; return ( ), content: ( @@ -287,27 +293,31 @@ function useSearchedLeaflets( }); let allTemplates = useTemplateState((s) => s.templates); - let filteredLeaflets = sortedLeaflets.filter(({ token: leaflet }) => { - let published = !!leaflet.leaflets_in_publications?.find((l) => l.doc); - let drafts = !!leaflet.leaflets_in_publications?.length && !published; - let docs = !leaflet.leaflets_in_publications?.length; - let templates = !!allTemplates.find((t) => t.id === leaflet.id); - // If no filters are active, show all - if ( - !filter.drafts && - !filter.published && - !filter.docs && - !filter.templates - ) - return true; + let filteredLeaflets = sortedLeaflets.filter( + ({ token: leaflet, archived: archived }) => { + let published = !!leaflet.leaflets_in_publications?.find((l) => l.doc); + let drafts = !!leaflet.leaflets_in_publications?.length && !published; + let docs = !leaflet.leaflets_in_publications?.length; + let templates = !!allTemplates.find((t) => t.id === leaflet.id); + // If no filters are active, show all + if ( + !filter.drafts && + !filter.published && + !filter.docs && + !filter.templates && + !filter.archived + ) + return archived === false || archived === null; - return ( - (filter.drafts && drafts) || - (filter.published && published) || - (filter.docs && docs) || - (filter.templates && templates) - ); - }); + return ( + (filter.drafts && drafts) || + (filter.published && published) || + (filter.docs && docs) || + (filter.templates && templates) || + (filter.archived && archived) + ); + }, + ); if (searchValue === "") return filteredLeaflets; let searchedLeaflets = filteredLeaflets.filter(({ token: leaflet }) => { return titles[leaflet.root_entity] diff --git a/app/(home-pages)/home/LeafletList/LeafletInfo.tsx b/app/(home-pages)/home/LeafletList/LeafletInfo.tsx index 53927749..51ba612a 100644 --- a/app/(home-pages)/home/LeafletList/LeafletInfo.tsx +++ b/app/(home-pages)/home/LeafletList/LeafletInfo.tsx @@ -7,6 +7,7 @@ import { theme } from "tailwind.config"; import { TemplateSmall } from "components/Icons/TemplateSmall"; import { timeAgo } from "src/utils/timeAgo"; import { usePublishLink } from "components/ShareOptions"; +import { Separator } from "components/Layout"; export const LeafletInfo = (props: { title?: string; @@ -52,18 +53,23 @@ export const LeafletInfo = (props: { /> - {props.draft || props.published ? ( -
- {props.published - ? `Published ${prettyPublishedAt}` - : `Draft ${prettyCreatedAt}`} -
- ) : ( -
{prettyCreatedAt}
- )} - {props.archived &&
archived
} +
+ {props.archived ? ( +
Archived
+ ) : props.draft || props.published ? ( +
+ {props.published + ? `Published ${prettyPublishedAt}` + : `Draft ${prettyCreatedAt}`} +
+ ) : ( +
+ {prettyCreatedAt} +
+ )} +
{props.isTemplate && props.display === "grid" ? (
- +
{props.showPreview && ( @@ -80,19 +81,20 @@ export const LeafletListItem = (props: { ); return ( - +
@@ -108,11 +110,15 @@ export const LeafletListItem = (props: { ); }; -const LeafletLink = (props: { id: string; children: React.ReactNode }) => { +const LeafletLink = (props: { + id: string; + children: React.ReactNode; + className: string; +}) => { return ( {props.children} diff --git a/components/Layout.tsx b/components/Layout.tsx index 52184571..0caa13c9 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -6,9 +6,7 @@ import { PopoverOpenContext } from "./Popover"; import { useState } from "react"; export const Separator = (props: { classname?: string }) => { - return ( -
- ); + return
; }; export const Menu = (props: { diff --git a/components/PageLayouts/DashboardLayout.tsx b/components/PageLayouts/DashboardLayout.tsx index 291e5b31..d44d3eb6 100644 --- a/components/PageLayouts/DashboardLayout.tsx +++ b/components/PageLayouts/DashboardLayout.tsx @@ -34,6 +34,7 @@ export type DashboardState = { published: boolean; docs: boolean; templates: boolean; + archived: boolean; }; }; @@ -45,7 +46,13 @@ type DashboardStore = { const defaultDashboardState: DashboardState = { display: undefined, sort: undefined, - filter: { drafts: false, published: false, docs: false, templates: false }, + filter: { + drafts: false, + published: false, + docs: false, + templates: false, + archived: false, + }, }; export const useDashboardStore = create((set, get) => ({ @@ -256,6 +263,7 @@ export const HomeDashboardControls = (props: { defaultDisplay: Exclude; hasPubs: boolean; hasTemplates: boolean; + hasArchived: boolean; }) => { let { display, sort } = useDashboardState(); display = display || props.defaultDisplay; @@ -283,6 +291,7 @@ export const HomeDashboardControls = (props: { {" "} @@ -369,7 +378,11 @@ function Tab(props: { ); } -const FilterOptions = (props: { hasPubs: boolean; hasTemplates: boolean }) => { +const FilterOptions = (props: { + hasPubs: boolean; + hasTemplates: boolean; + hasArchived: boolean; +}) => { let { filter } = useDashboardState(); let setState = useSetDashboardState(); let filterCount = Object.values(filter).filter(Boolean).length; @@ -421,6 +434,20 @@ const FilterOptions = (props: { hasPubs: boolean; hasTemplates: boolean }) => { )} + + {props.hasArchived && ( + + setState({ + filter: { ...filter, archived: !!e.target.checked }, + }) + } + > + Archived + + )} { published: false, drafts: false, templates: false, + archived: false, }, }); }} -- 2.51.2