diff --git a/web/components/groups/group-overview.tsx b/web/components/groups/group-overview.tsx index 080453ca..d5cdaafa 100644 --- a/web/components/groups/group-overview.tsx +++ b/web/components/groups/group-overview.tsx @@ -145,8 +145,6 @@ function GroupOverviewPinned(props: { }) { const { group, posts, isEditable } = props const [pinned, setPinned] = useState([]) - const [open, setOpen] = useState(false) - const [editMode, setEditMode] = useState(false) useEffect(() => { async function getPinned() { @@ -185,100 +183,127 @@ function GroupOverviewPinned(props: { ...(selectedItems as { itemId: string; type: 'contract' | 'post' }[]), ], }) - setOpen(false) + } + + function onDeleteClicked(index: number) { + const newPinned = group.pinnedItems.filter((item) => { + return item.itemId !== group.pinnedItems[index].itemId + }) + updateGroup(group, { pinnedItems: newPinned }) } return isEditable || (group.pinnedItems && group.pinnedItems.length > 0) ? ( - pinned.length > 0 || isEditable ? ( -
- - - {isEditable && ( - - )} - -
- - {pinned.length == 0 && !editMode && ( -
-

- No pinned items yet. Click the edit button to add some! -

-
- )} - {pinned.map((element, index) => ( -
- {element} + + ) : ( + + ) +} - {editMode && ( - { - const newPinned = group.pinnedItems.filter((item) => { - return item.itemId !== group.pinnedItems[index].itemId - }) - updateGroup(group, { pinnedItems: newPinned }) - }} - /> - )} -
- ))} - {editMode && group.pinnedItems && pinned.length < 6 && ( -
- - - -
+export function PinnedItems(props: { + posts: Post[] + isEditable: boolean + pinned: JSX.Element[] + onDeleteClicked: (index: number) => void + onSubmit: (selectedItems: { itemId: string; type: string }[]) => void + group?: Group + modalMessage: string +}) { + const { + isEditable, + pinned, + onDeleteClicked, + onSubmit, + posts, + group, + modalMessage, + } = props + const [editMode, setEditMode] = useState(false) + const [open, setOpen] = useState(false) + + return pinned.length > 0 || isEditable ? ( +
+ + + {isEditable && ( +
- - Pin posts or markets to the overview of this group. + + )} + +
+ + {pinned.length == 0 && !editMode && ( +
+

+ No pinned items yet. Click the edit button to add some! +

- } - onSubmit={onSubmit} - /> + )} + {pinned.map((element, index) => ( +
+ {element} + + {editMode && onDeleteClicked(index)} />} +
+ ))} + {editMode && pinned.length < 6 && ( +
+ + + +
+ )} +
- ) : ( - - ) + {modalMessage}
+ } + onSubmit={onSubmit} + /> +
) : ( <> ) diff --git a/web/components/pinned-select-modal.tsx b/web/components/pinned-select-modal.tsx index e72deee2..c43c7534 100644 --- a/web/components/pinned-select-modal.tsx +++ b/web/components/pinned-select-modal.tsx @@ -20,8 +20,8 @@ export function PinnedSelectModal(props: { selectedItems: { itemId: string; type: string }[] ) => void | Promise contractSearchOptions?: Partial[0]> - group: Group posts: Post[] + group?: Group }) { const { title, @@ -134,8 +134,8 @@ export function PinnedSelectModal(props: { highlightClassName: '!bg-indigo-100 outline outline-2 outline-indigo-300', }} - additionalFilter={{ groupSlug: group.slug }} - persistPrefix={`group-${group.slug}`} + additionalFilter={group ? { groupSlug: group.slug } : undefined} + persistPrefix={group ? `group-${group.slug}` : undefined} headerClassName="bg-white sticky" {...contractSearchOptions} /> @@ -152,7 +152,7 @@ export function PinnedSelectModal(props: { '!bg-indigo-100 outline outline-2 outline-indigo-300', }} /> - {posts.length === 0 && ( + {posts.length == 0 && (
No posts yet
)}