-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathDraftModeControls.tsx
69 lines (59 loc) · 1.77 KB
/
DraftModeControls.tsx
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
'use client'
// import { useDraftModeEnvironment } from 'next-sanity/hooks'
import { usePathname } from 'next/navigation'
import { VscSymbolField, VscBeakerStop } from 'react-icons/vsc'
import { createDataAttribute, stegaClean } from 'next-sanity'
export default function DraftModeControls({
globalModules,
}: {
globalModules?: Sanity.GlobalModule[]
}) {
// const environment = useDraftModeEnvironment()
// if (!['live', 'unknown'].includes(environment)) return null
const pathname = usePathname()
const filteredGlobalModules = globalModules
?.filter(({ path, excludePaths: ex }) => {
const p = stegaClean(path)
const curr = pathname.replace(/^\//, '')
return (
p === '*' ||
(curr.startsWith(p) && !ex?.some((e) => curr.startsWith(e)))
)
})
.sort((a, b) => a.path.localeCompare(b.path))
return (
<details className="frosted-glass fixed right-4 bottom-0 rounded-t bg-amber-200/90 text-xs shadow-xl not-hover:opacity-50 open:opacity-100">
<summary className="p-2">Draft Mode</summary>
<menu className="anim-fade-to-r p-2 pt-0">
{filteredGlobalModules?.map(({ _id, path }) => {
const attr = createDataAttribute({
id: _id,
type: 'global-module',
path: 'path',
})
return (
<li key={_id}>
<button
className="inline-flex items-center gap-1 py-0.5"
data-sanity={attr().toString()}
>
<VscSymbolField className="shrink-0" />
Global modules (<code>{path}</code>)
</button>
</li>
)
})}
<hr className="my-1" />
<li>
<a
className="inline-flex items-center gap-1 py-0.5 hover:underline"
href="/api/draft-mode/disable"
>
<VscBeakerStop className="shrink-0" />
Disable Draft Mode
</a>
</li>
</menu>
</details>
)
}