Skip to content

Commit 65a3255

Browse files
farnabazlarbish
andauthored
feat(medias): initialize feature (#17)
Co-authored-by: Baptiste Leproux <[email protected]>
1 parent 6ed4e98 commit 65a3255

35 files changed

+707
-234
lines changed

src/app/src/App.vue

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<script setup lang="ts">
22
import { useStudio } from './composables/useStudio'
3-
import PanelContent from './components/panel/content/PanelContent.vue'
4-
import PanelMedia from './components/panel/PanelMedia.vue'
5-
import PanelConfig from './components/panel/PanelConfig.vue'
63
import { useSidebar } from './composables/useSidebar'
74
import { watch, ref } from 'vue'
85
import { StudioFeature } from './types'
96
107
const { sidebarWidth } = useSidebar()
11-
const { ui, host, isReady, tree } = useStudio()
8+
const { ui, host, isReady } = useStudio()
129
watch(sidebarWidth, () => {
1310
if (ui.isPanelOpen.value) {
1411
host.ui.updateStyles()
@@ -48,20 +45,10 @@ host.on.mounted(() => {
4845
>
4946
<PanelBase v-model="ui.isPanelOpen.value">
5047
<template #header>
51-
<div class="flex items-center justify-between gap-2">
52-
<ItemBreadcrumb
53-
:current-item="tree.currentItem.value"
54-
:tree="tree.root.value"
55-
/>
56-
<ItemActionsToolbar
57-
:item="tree.currentItem.value"
58-
/>
59-
</div>
48+
<PanelBaseSubHeader />
6049
</template>
6150

62-
<PanelContent v-if="ui.panels.content" />
63-
<PanelMedia v-else-if="ui.panels.media" />
64-
<PanelConfig v-else-if="ui.panels.config" />
51+
<PanelBaseBody />
6552
</PanelBase>
6653

6754
<!-- Floating Files Panel Toggle -->

src/app/src/components/CommitPreviewModal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ref, watch } from 'vue'
33
import ReviewPanel from './ReviewPanel.vue'
44
import { useStudio } from '../composables/useStudio'
5-
import type { DraftFileItem } from '../types'
5+
import type { DraftItem } from '../types'
66
// import { useToast } from '@nuxt/ui/composables/useToast'
77
88
const modelValue = defineModel<any>()
@@ -17,7 +17,7 @@ const preview = useStudio()
1717
// const toast = useToast()
1818
1919
const loading = ref(false)
20-
const filesToReview = ref<DraftFileItem[]>([])
20+
const filesToReview = ref<DraftItem[]>([])
2121
2222
async function prepareReview() {
2323
loading.value = true
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<script setup lang="ts">
2+
import { computed } from 'vue'
3+
import { useStudio } from '../../../composables/useStudio'
4+
import { StudioFeature, StudioItemActionId } from '../../../types'
5+
6+
const { documentTree, mediaTree, draftDocuments, draftMedias, context } = useStudio()
7+
8+
const tree = computed(() => context.feature.value === StudioFeature.Content ? documentTree : mediaTree)
9+
10+
const currentFile = computed(() => context.feature.value === StudioFeature.Content ? draftDocuments.current.value : draftMedias.current.value)
11+
12+
const folderTree = computed(() => (tree.value.current.value || []).filter(f => f.type === 'directory'))
13+
const fileTree = computed(() => (tree.value.current.value || []).filter(f => f.type === 'file'))
14+
15+
const isFileCreationInProgress = computed(() => context.actionInProgress.value === StudioItemActionId.CreateDocument)
16+
const isFolderCreationInProgress = computed(() => context.actionInProgress.value === StudioItemActionId.CreateFolder)
17+
</script>
18+
19+
<template>
20+
<PanelBaseBodyEditor
21+
v-if="tree.currentItem.value.type === 'file' && currentFile"
22+
:draft-item="currentFile"
23+
/>
24+
<div
25+
v-else
26+
class="flex flex-col"
27+
>
28+
<PanelBaseBodyTree
29+
v-if="folderTree?.length > 0 || isFolderCreationInProgress"
30+
class="mb-4"
31+
:tree="folderTree"
32+
:show-creation-form="isFolderCreationInProgress"
33+
type="directory"
34+
/>
35+
<PanelBaseBodyTree
36+
v-if="fileTree?.length > 0 || isFileCreationInProgress"
37+
:tree="fileTree"
38+
:show-creation-form="isFileCreationInProgress"
39+
type="file"
40+
/>
41+
</div>
42+
</template>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script setup lang="ts">
2+
import { type DraftItem, StudioFeature } from '../../../types'
3+
import type { PropType } from 'vue'
4+
import { useStudio } from '../../../composables/useStudio'
5+
6+
defineProps({
7+
draftItem: {
8+
type: Object as PropType<DraftItem>,
9+
required: true,
10+
},
11+
})
12+
13+
const { context } = useStudio()
14+
</script>
15+
16+
<template>
17+
<PanelContentEditor
18+
v-if="context.feature.value === StudioFeature.Content"
19+
:draft-item="draftItem"
20+
/>
21+
<PanelMediaEditor
22+
v-else
23+
:draft-item="draftItem"
24+
/>
25+
</template>

src/app/src/components/panel/content/PanelContentTree.vue renamed to src/app/src/components/panel/base/PanelBaseBodyTree.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script setup lang="ts">
2-
import type { TreeItem } from '../../../types'
3-
import type { PropType } from 'vue'
2+
import { StudioFeature, type TreeItem } from '../../../types'
3+
import { computed, type PropType } from 'vue'
44
import { useStudio } from '../../../composables/useStudio'
55
6-
const { tree: treeApi, context } = useStudio()
6+
const { documentTree, mediaTree, context } = useStudio()
7+
8+
const treeApi = computed(() => context.feature.value === StudioFeature.Content ? documentTree : mediaTree)
79
810
defineProps({
911
type: {

src/app/src/components/panel/base/PanelBaseHeader.vue

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { useStudio } from '../../../composables/useStudio'
33
import { StudioFeature } from '../../../types'
44
import { ROOT_ITEM } from '../../../utils/tree'
55
6-
const { ui, context, tree } = useStudio()
6+
const { ui, context, documentTree, mediaTree } = useStudio()
77
88
const features = [{
99
label: 'Content',
1010
icon: 'i-lucide-files',
1111
onClick: () => {
1212
if (context.feature.value === StudioFeature.Content) {
13-
tree.select(ROOT_ITEM)
13+
documentTree.select(ROOT_ITEM)
1414
return
1515
}
1616
@@ -21,24 +21,12 @@ const features = [{
2121
icon: 'i-lucide-image',
2222
onClick: () => {
2323
if (context.feature.value === StudioFeature.Media) {
24-
tree.select(ROOT_ITEM)
24+
mediaTree.select(ROOT_ITEM)
2525
return
2626
}
2727
2828
ui.openPanel(StudioFeature.Media)
2929
},
30-
},
31-
{
32-
label: 'Config',
33-
icon: 'i-lucide-settings',
34-
onClick: () => {
35-
if (context.feature.value === StudioFeature.Config) {
36-
tree.select(ROOT_ITEM)
37-
return
38-
}
39-
40-
ui.openPanel(StudioFeature.Config)
41-
},
4230
}]
4331
</script>
4432

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script setup lang="ts">
2+
import { StudioFeature } from '../../../types'
3+
import { computed } from 'vue'
4+
import { useStudio } from '../../../composables/useStudio'
5+
6+
const { context, documentTree, mediaTree } = useStudio()
7+
8+
const tree = computed(() => context.feature.value === StudioFeature.Content ? documentTree : mediaTree)
9+
</script>
10+
11+
<template>
12+
<div class="flex items-center justify-between gap-2">
13+
<ItemBreadcrumb
14+
:current-item="tree.currentItem.value"
15+
:tree="tree.root.value"
16+
/>
17+
<ItemActionsToolbar
18+
:item="tree.currentItem.value"
19+
/>
20+
</div>
21+
</template>

src/app/src/components/panel/content/PanelContent.vue

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

src/app/src/components/panel/content/editor/PanelContentEditor.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
import { computed, type PropType, toRaw } from 'vue'
33
import { decompressTree } from '@nuxt/content/runtime'
44
import type { MarkdownRoot } from '@nuxt/content'
5-
import type { DatabasePageItem, DraftFileItem } from '../../../../types'
5+
import type { DatabasePageItem, DraftItem } from '../../../../types'
66
import { useStudio } from '../../../../composables/useStudio'
77
88
const props = defineProps({
99
draftItem: {
10-
type: Object as PropType<DraftFileItem>,
10+
type: Object as PropType<DraftItem>,
1111
required: true,
1212
},
1313
})
1414
15-
const { draftFiles } = useStudio()
15+
const { draftDocuments } = useStudio()
1616
1717
const document = computed<DatabasePageItem>({
1818
get() {
1919
if (!props.draftItem) {
2020
return {} as DatabasePageItem
2121
}
2222
23-
const dbItem = props.draftItem.document as DatabasePageItem
23+
const dbItem = props.draftItem.modified as DatabasePageItem
2424
2525
let result: DatabasePageItem
2626
// TODO: check mdcRoot and markdownRoot types with Ahad
2727
if (dbItem.body?.type === 'minimark') {
2828
result = {
29-
...props.draftItem.document as DatabasePageItem,
29+
...props.draftItem.modified as DatabasePageItem,
3030
// @ts-expect-error todo fix MarkdownRoot/MDCRoot conversion in MDC module
3131
body: decompressTree(dbItem.body) as MarkdownRoot,
3232
}
@@ -38,7 +38,7 @@ const document = computed<DatabasePageItem>({
3838
return result
3939
},
4040
set(value) {
41-
draftFiles.update(props.draftItem.id, {
41+
draftDocuments.update(props.draftItem.id, {
4242
...toRaw(document.value as DatabasePageItem),
4343
...toRaw(value),
4444
})

src/app/src/components/panel/content/editor/PanelContentEditorCode.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script setup lang="ts">
22
import { onMounted, ref, shallowRef, watch } from 'vue'
3-
import type { DatabasePageItem, DraftFileItem } from '../../../../types'
3+
import type { DatabasePageItem, DraftItem } from '../../../../types'
44
import type { PropType } from 'vue'
55
import { setupMonaco, type Editor } from '../../../../utils/monaco'
66
import { generateContentFromDocument, generateDocumentFromContent, pickReservedKeysFromDocument } from '../../../../utils/content'
77
88
const props = defineProps({
99
draftItem: {
10-
type: Object as PropType<DraftFileItem>,
10+
type: Object as PropType<DraftItem>,
1111
required: true,
1212
},
1313
})
@@ -22,7 +22,7 @@ const currentDocumentId = ref<string | null>(null)
2222
// Trigger on action events
2323
watch(() => props.draftItem.status, () => {
2424
if (editor.value) {
25-
setContent(props.draftItem.document as DatabasePageItem)
25+
setContent(props.draftItem.modified as DatabasePageItem)
2626
}
2727
})
2828
@@ -53,7 +53,7 @@ onMounted(async () => {
5353
5454
generateDocumentFromContent(document.value!.id, content.value).then((doc) => {
5555
document.value = {
56-
...pickReservedKeysFromDocument(props.draftItem.originalDatabaseItem as DatabasePageItem || document.value!),
56+
...pickReservedKeysFromDocument(props.draftItem.original as DatabasePageItem || document.value!),
5757
...doc,
5858
} as DatabasePageItem
5959
})

0 commit comments

Comments
 (0)