This repository was archived by the owner on Apr 8, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathnote-nav.tsx
More file actions
178 lines (166 loc) Β· 4.88 KB
/
Copy pathnote-nav.tsx
File metadata and controls
178 lines (166 loc) Β· 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import classNames from 'classnames'
import NoteState from 'libs/web/state/note'
import UIState from 'libs/web/state/ui'
import { useCallback, MouseEvent, MutableRefObject } from 'react'
import { CircularProgress, Tooltip } from '@material-ui/core'
import NoteTreeState from 'libs/web/state/tree'
import { Breadcrumbs } from '@material-ui/core'
import Link from 'next/link'
import IconButton from './icon-button'
import HotkeyTooltip from './hotkey-tooltip'
import PortalState from 'libs/web/state/portal'
import { NOTE_SHARED } from 'libs/shared/meta'
import useI18n from 'libs/web/hooks/use-i18n'
import NavButtonGroup from './nav-button-group'
import { EyeIcon } from '@heroicons/react/outline'
const MenuButton = () => {
const { sidebar } = UIState.useContainer()
const onToggle = useCallback(
(e: MouseEvent) => {
e.stopPropagation()
sidebar.toggle()
},
[sidebar]
)
return (
<IconButton
icon="Menu"
className="mr-2 active:bg-gray-400"
onClick={onToggle}
></IconButton>
)
}
type Props = {
explicitSave?: boolean
isSaved?: boolean
saveRef?: MutableRefObject<(() => void) | undefined>
}
const NoteNav = ({ explicitSave, isSaved, saveRef }: Props) => {
const { t } = useI18n()
const { note, loading } = NoteState.useContainer()
const { ua } = UIState.useContainer()
const { getPaths, showItem, checkItemIsShown } = NoteTreeState.useContainer()
const { share, menu } = PortalState.useContainer()
const handleClickShare = useCallback(
(event: MouseEvent) => {
share.setData(note)
share.setAnchor(event.target as Element)
share.open()
},
[note, share]
)
const handleClickMenu = useCallback(
(event: MouseEvent) => {
menu.setData(note)
menu.setAnchor(event.target as Element)
menu.open()
},
[note, menu]
)
const handleClickOpenInTree = useCallback(() => {
if (!note) return
showItem(note)
}, [note, showItem])
const saveNote = useCallback(() => saveRef?.current?.(), [saveRef])
return (
<nav
className={classNames(
'fixed bg-gray-50 z-10 p-2 flex items-center right-0',
{
shadow: ua.isMobileOnly,
}
)}
style={{
width: ua.isMobileOnly ? '100%' : 'inherit',
}}
>
{ua.isMobileOnly ? <MenuButton /> : null}
{ua.isMobileOnly && explicitSave ? (
<IconButton
icon="Save"
className="mr-2 active:bg-gray-400"
onClick={saveNote}
disabled={isSaved}
></IconButton>
) : null}
<NavButtonGroup />
<div className="flex-auto ml-4">
{note && (
<Breadcrumbs
maxItems={2}
className="text-gray-800 leading-none"
aria-label="breadcrumb"
>
{getPaths(note)
.reverse()
.map((path) => (
<Tooltip key={path.id} title={path.title}>
<div>
<Link href={`/${path.id}`} shallow>
<a className="title block hover:bg-gray-200 px-1 py-0.5 rounded text-sm truncate">
{path.title}
</a>
</Link>
</div>
</Tooltip>
))}
<span>
<Tooltip title={note.title}>
<span
className="title inline-block text-gray-600 text-sm truncate select-none align-middle"
aria-current="page"
>
{note.title}
</span>
</Tooltip>
{!checkItemIsShown(note) && (
<Tooltip title={t('Show note in tree')}>
<span>
<EyeIcon
width="20"
className="inline-block cursor-pointer ml-1"
onClick={handleClickOpenInTree}
/>
</span>
</Tooltip>
)}
</span>
</Breadcrumbs>
)}
<style jsx>
{`
.title {
max-width: 120px;
}
`}
</style>
</div>
<div
className={classNames('flex mr-2 transition-opacity delay-100', {
'opacity-0': !loading,
})}
>
<CircularProgress size="14px" color="inherit" />
</div>
<HotkeyTooltip text={t('Share page')}>
<IconButton
onClick={handleClickShare}
className="mr-2"
disabled={!note}
iconClassName={classNames({
'text-blue-500': note?.shared === NOTE_SHARED.PUBLIC,
})}
icon="Share"
/>
</HotkeyTooltip>
<HotkeyTooltip text={t('Settings')}>
<IconButton
disabled={!note}
onClick={handleClickMenu}
icon="DotsHorizontal"
/>
</HotkeyTooltip>
</nav>
)
}
export default NoteNav