Skip to content

Commit 953c364

Browse files
farnabazlarbishatinux
authored
feat(dev): enable studio in development mode without auth (#94)
Co-authored-by: Baptiste Leproux <[email protected]> Co-authored-by: Sébastien Chopin <[email protected]>
1 parent 08a21c7 commit 953c364

File tree

15 files changed

+147
-222
lines changed

15 files changed

+147
-222
lines changed

playground/docus/content/2.studio/2.setup.md

Lines changed: 0 additions & 151 deletions
This file was deleted.

src/app/src/components/AppFooter.vue

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { computed } from 'vue'
33
import { useStudio } from '../composables/useStudio'
44
import { useStudioState } from '../composables/useStudioState'
5+
import type { DropdownMenuItem } from '@nuxt/ui'
56
67
const { ui, host, git } = useStudio()
7-
const { preferences, updatePreference, unsetActiveLocation } = useStudioState()
8+
const { devMode, preferences, updatePreference, unsetActiveLocation } = useStudioState()
89
const user = host.user.get()
910
1011
// const showTechnicalMode = computed({
@@ -16,19 +17,19 @@ const user = host.user.get()
1617
1718
const repositoryUrl = computed(() => git.getBranchUrl())
1819
const userMenuItems = computed(() => [
19-
[
20-
// [{
21-
// slot: 'view-mode' as const,
22-
// }
23-
repositoryUrl.value
24-
? {
20+
repositoryUrl.value
21+
? [
22+
// [{
23+
// slot: 'view-mode' as const,
24+
// }
25+
{
2526
label: `${host.repository.owner}/${host.repository.repo}`,
2627
icon: 'i-simple-icons:github',
2728
to: repositoryUrl.value,
2829
target: '_blank',
29-
}
30-
: undefined,
31-
].filter(Boolean),
30+
},
31+
]
32+
: undefined,
3233
[{
3334
label: 'Sign out',
3435
icon: 'i-lucide-log-out',
@@ -38,7 +39,7 @@ const userMenuItems = computed(() => [
3839
})
3940
},
4041
}],
41-
])
42+
].filter(Boolean) as DropdownMenuItem[][])
4243
4344
function closeStudio() {
4445
unsetActiveLocation()
@@ -50,7 +51,14 @@ function closeStudio() {
5051
<div
5152
class="bg-muted/50 border-default border-t-[0.5px] flex items-center justify-between gap-1.5 px-2 py-2"
5253
>
54+
<span
55+
v-if="devMode"
56+
class="ml-2 text-xs text-muted"
57+
>
58+
Using local filesystem
59+
</span>
5360
<UDropdownMenu
61+
v-else
5462
:portal="false"
5563
:items="userMenuItems"
5664
:ui="{ content: 'w-full' }"

src/app/src/components/header/HeaderMain.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useStudioState } from '../../composables/useStudioState'
88
const router = useRouter()
99
const route = useRoute()
1010
const { context } = useStudio()
11-
const { setLocation } = useStudioState()
11+
const { setLocation, devMode } = useStudioState()
1212
1313
const items = [
1414
{
@@ -52,6 +52,7 @@ const current = computed({
5252
/>
5353

5454
<UButton
55+
v-if="!devMode"
5556
label="Review"
5657
color="neutral"
5758
:variant="context.draftCount.value > 0 ? 'solid' : 'soft'"
@@ -66,7 +67,7 @@ const current = computed({
6667
>
6768
<UBadge
6869
:label="context.draftCount.value.toString()"
69-
class="bg-[var(--ui-color-neutral-400)]"
70+
class="bg-neutral-400"
7071
size="xs"
7172
variant="soft"
7273
/>

src/app/src/composables/useContext.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ export const useContext = createSharedComposable((
234234
actionInProgress.value = null
235235
}
236236

237+
function switchFeature(feature: StudioFeature) {
238+
router.push(`/${feature}`)
239+
}
240+
237241
return {
238242
currentFeature,
239243
activeTree,
@@ -246,5 +250,6 @@ export const useContext = createSharedComposable((
246250
draftCount,
247251
isDraftInProgress,
248252
unsetActionInProgress,
253+
switchFeature,
249254
}
250255
})

src/app/src/composables/useDraftBase.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { Storage } from 'unstorage'
22
import { joinURL } from 'ufo'
33
import type { DraftItem, StudioHost, GithubFile, DatabaseItem, MediaItem, BaseItem } from '../types'
44
import { ContentFileExtension } from '../types'
5-
import { studioFlags } from './useStudio'
65
import { DraftStatus } from '../types/draft'
76
import { checkConflict, findDescendantsFromFsPath } from '../utils/draft'
87
import type { useGit } from './useGit'
98
import { useHooks } from './useHooks'
109
import { ref } from 'vue'
10+
import { useStudioState } from './useStudioState'
1111

1212
export function useDraftBase<T extends DatabaseItem | MediaItem>(
1313
type: 'media' | 'document',
@@ -25,6 +25,7 @@ export function useDraftBase<T extends DatabaseItem | MediaItem>(
2525
const areDocumentsEqual = host.document.utils.areEqual
2626

2727
const hooks = useHooks()
28+
const { devMode } = useStudioState()
2829

2930
async function get(fsPath: string): Promise<DraftItem<T> | undefined> {
3031
return list.value.find(item => item.fsPath === fsPath) as DraftItem<T>
@@ -73,40 +74,45 @@ export function useDraftBase<T extends DatabaseItem | MediaItem>(
7374
await storage.removeItem(fsPath)
7475
await hostDb.delete(fsPath)
7576

76-
let deleteDraftItem: DraftItem<T> | null = null
77-
if (existingDraftItem) {
78-
if (existingDraftItem.status === DraftStatus.Deleted) return
77+
if (!devMode.value) {
78+
let deleteDraftItem: DraftItem<T> | null = null
79+
if (existingDraftItem) {
80+
if (existingDraftItem.status === DraftStatus.Deleted) return
7981

80-
if (existingDraftItem.status === DraftStatus.Created) {
81-
list.value = list.value.filter(item => item.fsPath !== fsPath)
82+
if (existingDraftItem.status === DraftStatus.Created) {
83+
list.value = list.value.filter(item => item.fsPath !== fsPath)
84+
}
85+
else {
86+
// TODO: check if gh file has been updated
87+
const githubFile = await git.fetchFile(joinURL('content', fsPath), { cached: true }) as GithubFile
88+
89+
deleteDraftItem = {
90+
fsPath: existingDraftItem.fsPath,
91+
status: DraftStatus.Deleted,
92+
original: existingDraftItem.original,
93+
githubFile,
94+
}
95+
96+
list.value = list.value.map(item => item.fsPath === fsPath ? deleteDraftItem! : item) as DraftItem<T>[]
97+
}
8298
}
8399
else {
100+
// TODO: check if gh file has been updated
101+
const githubFile = await git.fetchFile(joinURL('content', fsPath), { cached: true }) as GithubFile
102+
84103
deleteDraftItem = {
85-
fsPath: existingDraftItem.fsPath,
104+
fsPath,
86105
status: DraftStatus.Deleted,
87-
original: existingDraftItem.original,
88-
githubFile: existingDraftItem.githubFile,
106+
original: originalDbItem,
107+
githubFile,
89108
}
90109

91-
list.value = list.value.map(item => item.fsPath === fsPath ? deleteDraftItem! : item) as DraftItem<T>[]
110+
list.value.push(deleteDraftItem)
92111
}
93-
}
94-
else {
95-
// TODO: check if gh file has been updated
96-
const githubFile = await git.fetchFile(joinURL('content', fsPath), { cached: true }) as GithubFile
97-
98-
deleteDraftItem = {
99-
fsPath,
100-
status: DraftStatus.Deleted,
101-
original: originalDbItem,
102-
githubFile,
103-
}
104-
105-
list.value.push(deleteDraftItem)
106-
}
107112

108-
if (deleteDraftItem) {
109-
await storage.setItem(fsPath, deleteDraftItem)
113+
if (deleteDraftItem) {
114+
await storage.setItem(fsPath, deleteDraftItem)
115+
}
110116
}
111117

112118
if (rerender) {
@@ -215,7 +221,7 @@ export function useDraftBase<T extends DatabaseItem | MediaItem>(
215221
}
216222

217223
function getStatus(modified: BaseItem, original: BaseItem): DraftStatus {
218-
if (studioFlags.dev) {
224+
if (devMode.value) {
219225
return DraftStatus.Pristine
220226
}
221227

0 commit comments

Comments
 (0)