Skip to content

Commit a05fc80

Browse files
committed
First commit to add a Modal about Linked notes
1 parent 6391c32 commit a05fc80

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubblesContainer.tsx

+31-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import RoundIconButton from '../Button/RoundIconButton'
1616
import VaultNameBadge from '../Vaults/VaultNameBadge'
1717
import LastEditedByBadge from '../Vaults/LastEditedByBadge'
1818
import { useItemVaultInfo } from '@/Hooks/useItemVaultInfo'
19+
import LinkedItemModalView from './LinkedItemModalView'
20+
import Icon from '../Icon/Icon'
1921

2022
type Props = {
2123
linkingController: LinkingController
@@ -124,6 +126,7 @@ const LinkedItemBubblesContainer = ({
124126
)
125127
}
126128

129+
const [showAllItemsModal, setShowAllItemsModal] = useState(false)
127130
const itemsToDisplay = allItemsLinkedToItem.concat(notesLinkingToItem).concat(filesLinkingToItem)
128131
const ItemsToShowWhenCollapsed = 5
129132
const [isCollapsed, setIsCollapsed] = useState(
@@ -206,7 +209,22 @@ const LinkedItemBubblesContainer = ({
206209
readonly={readonly}
207210
/>
208211
))}
209-
{isCollapsed && nonVisibleItems > 0 && <span className="flex-shrink-0">and {nonVisibleItems} more...</span>}
212+
{isCollapsed && nonVisibleItems > 0 && (
213+
<button
214+
onClick={() => setShowAllItemsModal(true)}
215+
className={classNames(
216+
'group h-6 cursor-pointer items-center rounded bg-passive-4-opacity-variant py-2 pl-1 pr-2 align-middle text-sm',
217+
'text-text hover:bg-contrast focus:bg-contrast lg:text-xs', 'inline-flex'
218+
)}
219+
>
220+
<Icon type="more" className={classNames('mr-1 flex-shrink-0', 'text-info')} size="small" />
221+
<span className="flex items-center overflow-hidden overflow-ellipsis whitespace-nowrap">
222+
<span className="flex items-center gap-1">
223+
More ({itemsToDisplay.length})
224+
</span>
225+
</span>
226+
</button>
227+
)}
210228
{!readonly && (
211229
<ItemLinkAutocompleteInput
212230
focusedId={focusedId}
@@ -228,6 +246,18 @@ const LinkedItemBubblesContainer = ({
228246
icon={isCollapsed ? 'chevron-down' : 'chevron-left'}
229247
/>
230248
)}
249+
250+
<LinkedItemModalView
251+
items={itemsToDisplay}
252+
readonly={readonly}
253+
isOpen={showAllItemsModal}
254+
onClose={() => setShowAllItemsModal(false)}
255+
onUnlink={unlinkItem}
256+
onActivate={async (item) => {
257+
await activateItemAndTogglePane(item)
258+
setShowAllItemsModal(false)
259+
}}
260+
/>
231261
</div>
232262
)
233263
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { observer } from 'mobx-react-lite'
2+
import Modal from '../Modal/Modal'
3+
import Icon from '../Icon/Icon'
4+
import ModalOverlay from '../Modal/ModalOverlay'
5+
import { ItemLink } from '@/Utils/Items/Search/ItemLink'
6+
import { LinkableItem } from '@/Utils/Items/Search/LinkableItem'
7+
import LinkedItemMeta from './LinkedItemMeta'
8+
9+
type Props = {
10+
items: ItemLink[]
11+
readonly?: boolean
12+
isOpen: boolean
13+
onClose: () => void
14+
onUnlink: (item: LinkableItem) => void
15+
onActivate: (item: LinkableItem) => Promise<void>
16+
}
17+
18+
const LinkedItemModalView = ({ items, readonly, isOpen, onClose, onUnlink, onActivate }: Props) => {
19+
return (
20+
<ModalOverlay isOpen={isOpen} close={onClose}>
21+
<Modal
22+
title="All linked items"
23+
close={onClose}
24+
actions={[
25+
{
26+
label: 'Done',
27+
onClick: onClose,
28+
type: 'primary',
29+
mobileSlot: 'right'
30+
}
31+
]}
32+
>
33+
<div className="max-h-[60vh] overflow-y-auto px-4 py-4">
34+
<div className="flex flex-col gap-2">
35+
{items.map((link) => (
36+
<div key={link.id} className="flex items-center justify-between gap-4 rounded bg-passive-4-opacity-variant p-2">
37+
<button
38+
className="flex flex-grow items-center gap-2"
39+
onClick={() => onActivate(link.item)}
40+
>
41+
<LinkedItemMeta item={link.item} />
42+
</button>
43+
{!readonly && (
44+
<button
45+
className="rounded-full p-1 hover:bg-contrast"
46+
onClick={() => onUnlink(link.item)}
47+
>
48+
<Icon type="link-off" className="text-danger" size="small" />
49+
</button>
50+
)}
51+
</div>
52+
))}
53+
</div>
54+
</div>
55+
</Modal>
56+
</ModalOverlay>
57+
)
58+
}
59+
60+
export default observer(LinkedItemModalView)

0 commit comments

Comments
 (0)