Skip to content

Commit 791af4c

Browse files
atinuxlarbish
andauthored
feat(app): big refactor for great UX (#22)
Co-authored-by: Baptiste Leproux <[email protected]>
1 parent 2c9b969 commit 791af4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+533
-618
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"exports": {
99
".": "./dist/module/module.mjs",
1010
"./app": {
11-
"types": "./dist/app/index.d.ts",
12-
"default": "./dist/app/index.js"
11+
"types": "./dist/app/main.d.ts",
12+
"default": "./dist/app/main.js"
1313
},
1414
"./app/utils": {
1515
"types": "./dist/app/utils.d.ts",
@@ -64,6 +64,7 @@
6464
},
6565
"packageManager": "[email protected]",
6666
"dependencies": {
67+
"@iconify-json/simple-icons": "^1.2.53",
6768
"@nuxtjs/mdc": "https://pkg.pr.new/@nuxtjs/mdc@61af819",
6869
"@nuxtlabs/monarch-mdc": "^0.8.1",
6970
"@unhead/vue": "^2.0.17",

pnpm-lock.yaml

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/src/App.vue

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

src/app/src/app.vue

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<script setup lang="ts">
2+
import { useStudio } from './composables/useStudio'
3+
import { watch, ref } from 'vue'
4+
import { StudioFeature } from './types'
5+
import { defineShortcuts } from '#imports'
6+
import { useRouter } from 'vue-router'
7+
8+
const { host, ui, isReady, documentTree } = useStudio()
9+
const router = useRouter()
10+
11+
defineShortcuts({
12+
'meta_.': () => {
13+
ui.toggle()
14+
},
15+
})
16+
17+
watch(ui.sidebar.sidebarWidth, () => {
18+
if (ui.isOpen.value) {
19+
host.ui.updateStyles()
20+
}
21+
})
22+
const activeDocuments = ref<{ id: string, title: string }[]>([])
23+
24+
function detectActiveDocuments() {
25+
activeDocuments.value = host.document.detectActives().map((content) => {
26+
return {
27+
id: content.id,
28+
title: content.title,
29+
}
30+
})
31+
}
32+
33+
async function editContentFile(id: string) {
34+
await documentTree.selectItemById(id)
35+
ui.open(StudioFeature.Content)
36+
}
37+
38+
const colorModeClass = ref(host.ui.colorMode)
39+
40+
host.on.colorModeChange((colorMode) => {
41+
colorModeClass.value = colorMode
42+
})
43+
44+
host.on.mounted(() => {
45+
detectActiveDocuments()
46+
host.on.routeChange(() => {
47+
setTimeout(() => {
48+
detectActiveDocuments()
49+
}, 100)
50+
})
51+
})
52+
53+
const direction = ref<'left' | 'right'>('left')
54+
const directionOrder = ['content', 'media']
55+
56+
router.beforeEach((to, from) => {
57+
direction.value = directionOrder.indexOf(from.name as string) > directionOrder.indexOf(to.name as string) ? 'left' : 'right'
58+
})
59+
</script>
60+
61+
<template>
62+
<div :class="colorModeClass">
63+
<UApp :toaster="{ portal: false }">
64+
<AppLayout :open="ui.isOpen.value">
65+
<RouterView v-slot="{ Component }">
66+
<Transition
67+
enter-active-class="transition-translate duration-200 absolute"
68+
:enter-from-class="direction === 'right' ? 'translate-x-full' : '-translate-x-full'"
69+
enter-to-class="translate-x-0"
70+
leave-active-class="transition-translate duration-200 absolute"
71+
leave-from-class="translate-x-0"
72+
:leave-to-class="direction === 'right' ? '-translate-x-full' : 'translate-x-full'"
73+
>
74+
<KeepAlive>
75+
<component
76+
:is="Component"
77+
class="w-full h-full"
78+
/>
79+
</KeepAlive>
80+
</Transition>
81+
</RouterView>
82+
</AppLayout>
83+
84+
<!-- Floating Files Panel Toggle -->
85+
<div
86+
class="fixed bottom-2 left-2 flex transition-all"
87+
:class="[isReady && !ui.isOpen.value ? 'opacity-100 duration-200 delay-300 translate-y-0' : 'duration-0 opacity-0 -translate-x-12 pointer-events-none']"
88+
>
89+
<UFieldGroup>
90+
<UTooltip
91+
text="Toggle Studio"
92+
:kbds="['meta', '.']"
93+
>
94+
<UButton
95+
icon="i-lucide-panel-left-open"
96+
size="sm"
97+
color="neutral"
98+
variant="outline"
99+
class="bg-transparent backdrop-blur-md"
100+
@click="ui.open()"
101+
/>
102+
</UTooltip>
103+
<UButton
104+
v-if="activeDocuments.length === 1"
105+
size="sm"
106+
color="neutral"
107+
variant="outline"
108+
class="bg-transparent backdrop-blur-md px-2"
109+
label="Edit this page"
110+
@click="editContentFile(activeDocuments[0].id)"
111+
/>
112+
</UFieldGroup>
113+
</div>
114+
</UApp>
115+
</div>
116+
</template>

src/app/src/assets/css/main.css

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@source inline('ring-red-200 hover:ring-red-300 hover:dark:ring-red-700');
1212
@source inline('ring-green-200 hover:ring-green-300 hover:dark:ring-green-700');
1313

14-
:root {
14+
:root, .light {
1515
--ui-primary: black;
1616
}
1717

@@ -20,11 +20,6 @@
2020
}
2121

2222
@theme static {
23-
--ui-sub-header-height: 45px;
24-
--ui-footer-height: 40px;
25-
26-
--font-sans: 'Public Sans', sans-serif;
27-
2823
--color-green-50: '#EFFDF5';
2924
--color-green-100: '#D9FBE8';
3025
--color-green-200: '#B3F5D1';
Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { computed } from 'vue'
3-
import { useStudio } from '../../../composables/useStudio'
3+
import { useStudio } from '../composables/useStudio'
44
55
const { ui, host } = useStudio()
66
@@ -17,46 +17,43 @@ const repositoryUrl = computed(() => {
1717
1818
const userMenuItems = computed(() => [
1919
[{
20-
label: 'Open Repository',
21-
icon: 'i-lucide-github',
22-
onClick: () => {
23-
window.open(repositoryUrl.value, '_blank')
24-
},
20+
label: `${host.repository.owner}/${host.repository.repo}`,
21+
icon: 'i-simple-icons:github',
22+
to: repositoryUrl.value,
23+
target: '_blank',
2524
}],
2625
[{
2726
label: 'Sign out',
2827
icon: 'i-lucide-log-out',
2928
onClick: () => {
30-
alert('TODO: delete cookie manually')
29+
fetch('/__nuxt_content/studio/auth/session', { method: 'delete' }).then(() => {
30+
document.location.reload()
31+
})
3132
},
3233
}],
3334
])
3435
</script>
3536

3637
<template>
37-
<UFooter
38-
class="h-var(--ui-footer-height) sticky bottom-0 bg-white"
39-
:ui="{ container: 'px-2 sm:px-2 lg:px-2', right: 'gap-0' }"
38+
<div
39+
class="bg-muted/50 border-default border-t-[0.5px] flex items-center justify-between gap-1.5 px-2 py-2"
4040
>
41-
<template #left>
42-
<UDropdownMenu
43-
:portal="false"
44-
:items="userMenuItems"
45-
:ui="{ content: 'w-full' }"
46-
size="xs"
47-
>
48-
<UButton
49-
color="neutral"
50-
variant="ghost"
51-
size="sm"
52-
:avatar="{ src: user?.avatar, alt: user?.name, size: '2xs' }"
53-
class="px-2 font-medium"
54-
:label="user?.name"
55-
/>
56-
</UDropdownMenu>
57-
</template>
41+
<UDropdownMenu
42+
:portal="false"
43+
:items="userMenuItems"
44+
:ui="{ content: 'w-full' }"
45+
>
46+
<UButton
47+
color="neutral"
48+
variant="ghost"
49+
size="sm"
50+
:avatar="{ src: user?.avatar, alt: user?.name, size: '2xs' }"
51+
class="px-2 py-1 font-medium"
52+
:label="user?.name"
53+
/>
54+
</UDropdownMenu>
5855

59-
<template #right>
56+
<div class="flex items-center">
6057
<UTooltip
6158
:text="uiConfig.syncEditorAndRoute ? 'Unlink editor and preview' : 'Link editor and preview'"
6259
:delay-duration="0"
@@ -66,17 +63,15 @@ const userMenuItems = computed(() => [
6663
variant="ghost"
6764
:color="uiConfig.syncEditorAndRoute ? 'info' : 'neutral'"
6865
:class="!uiConfig.syncEditorAndRoute && 'opacity-50'"
69-
size="sm"
7066
@click="uiConfig.syncEditorAndRoute = !uiConfig.syncEditorAndRoute"
7167
/>
7268
</UTooltip>
7369
<UButton
7470
icon="i-lucide-panel-left-close"
7571
variant="ghost"
7672
color="neutral"
77-
size="sm"
78-
@click="ui.closePanels()"
73+
@click="ui.close()"
7974
/>
80-
</template>
81-
</UFooter>
75+
</div>
76+
</div>
8277
</template>

0 commit comments

Comments
 (0)