diff --git a/packages/web/components/nav-containers/home.tsx b/packages/web/components/nav-containers/home.tsx
index a20efbe0c..09f435cc9 100644
--- a/packages/web/components/nav-containers/home.tsx
+++ b/packages/web/components/nav-containers/home.tsx
@@ -1,7 +1,7 @@
import * as HoverCard from '@radix-ui/react-hover-card'
import { styled } from '@stitches/react'
import { useRouter } from 'next/router'
-import { useMemo, useState } from 'react'
+import { useCallback, useEffect, useMemo, useReducer, useState } from 'react'
import { Button } from '../elements/Button'
import { AddToLibraryActionIcon } from '../elements/icons/home/AddToLibraryActionIcon'
import { ArchiveActionIcon } from '../elements/icons/home/ArchiveActionIcon'
@@ -198,6 +198,41 @@ const JustAddedHomeSection = (props: HomeSectionProps): JSX.Element => {
}
const TopPicksHomeSection = (props: HomeSectionProps): JSX.Element => {
+ const listReducer = (
+ state: HomeItem[],
+ action: {
+ type: string
+ itemId?: string
+ items?: HomeItem[]
+ }
+ ) => {
+ console.log('handling action: ', action)
+ switch (action.type) {
+ case 'RESET':
+ return action.items ?? []
+ case 'REMOVE_ITEM':
+ return state.filter((item) => item.id !== action.itemId)
+ default:
+ throw new Error()
+ }
+ }
+
+ const [items, dispatchList] = useReducer(listReducer, [])
+
+ function handleDelete(item: HomeItem) {
+ dispatchList({
+ type: 'REMOVE_ITEM',
+ itemId: item.id,
+ })
+ }
+
+ useEffect(() => {
+ dispatchList({
+ type: 'RESET',
+ items: props.homeSection.items,
+ })
+ }, [props])
+
return (
{
(
-
+
)}
/>
@@ -511,9 +550,14 @@ const JustAddedItemView = (props: HomeItemViewProps): JSX.Element => {
)
}
-const TopicPickHomeItemView = (props: HomeItemViewProps): JSX.Element => {
- const router = useRouter()
+type TopPickItemViewProps = {
+ dispatchList: (args: { type: string; itemId?: string }) => void
+}
+const TopicPickHomeItemView = (
+ props: HomeItemViewProps & TopPickItemViewProps
+): JSX.Element => {
+ const router = useRouter()
return (
{
-
- */}
+
+ {props.homeItem.canArchive && (
+ {
+ // archiveItem(props.homeItem)
+ console.log('archiving')
+ props.dispatchList({
+ type: 'REMOVE_ITEM',
+ itemId: props.homeItem.id,
+ })
+ event.preventDefault()
+ event.stopPropagation()
+ }}
+ >
+
+
+ )}
+ {props.homeItem.canDelete && (
+
+
+
+ )}
+ {props.homeItem.canShare && (
+
+
+
+ )}