Skip to content

Commit 3fbfee5

Browse files
committed
feat: defineAppPage
1 parent 33f101a commit 3fbfee5

File tree

12 files changed

+117
-143
lines changed

12 files changed

+117
-143
lines changed

packages/app/src/components/IsAppDrawerMini.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const drawer = defineModel('drawer', {
1212
// links
1313
const links = [
1414
{
15-
to: '/file-explorer',
15+
to: '/app-pages/directory',
1616
icon: 'mdi:folder',
17-
label: 'fileExplorer'
17+
label: 'Explorer'
1818
},
1919
{
2020
to: '/workspace-selector',

packages/app/src/components/IsMarkdownEditor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ whenever(keys.Alt_m, () => {
8383
})
8484
</script>
8585
<template>
86-
<div class="flex flex-wrap min-h-full w-full">
86+
<div class="flex flex-wrap h-screen w-full">
8787
<div class="h-[calc(100%-1.5rem)] w-full">
8888
<transition
8989
enter-active-class="transition duration-200"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface AppPage {
2+
// unique name of the page
3+
name: string
4+
component: any
5+
}
6+
7+
export function defineAppPage(page: AppPage) {
8+
return page
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { DriveEntry } from "./useDrive";
2+
import type { RouteRecordRaw, Router } from 'vue-router'
3+
4+
export interface EntryMiddlewareContext {
5+
entry: DriveEntry
6+
route: RouteRecordRaw
7+
router: Router
8+
}
9+
10+
export interface EntryMiddleware {
11+
(context: EntryMiddlewareContext): Promise<any>
12+
}
13+
14+
export function defineEntryMiddleware(middleware: EntryMiddleware) {
15+
return middleware
16+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<script lang="ts" setup>
2+
3+
import type { AppPage } from '@/composables/defineAppPage'
4+
import Directory from './AppPageDirectory.vue';
5+
6+
const name = defineProp('name', {
7+
type: String,
8+
required: true
9+
})
10+
11+
const pages = shallowRef<AppPage[]>([])
12+
13+
const directoryPage = defineAppPage({
14+
name: 'directory',
15+
component: Directory,
16+
})
17+
18+
pages.value.push(directoryPage)
19+
20+
const current = computed(() => pages.value.find(p => p.name === name.value))
21+
22+
const currentComponent = computed(() => {
23+
if (!current.value) {
24+
return null
25+
}
26+
27+
return current.value.component
28+
})
29+
30+
</script>
31+
32+
<template>
33+
<component v-if="currentComponent" :is="currentComponent" />
34+
35+
<div v-else>
36+
No page found
37+
</div>
38+
</template>

packages/app/src/pages/FileExplorer/FileExplorer.vue renamed to packages/app/src/pages/AppPage/AppPageDirectory.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
import type { DriveEntry } from '@/composables/useDrive';
33
import orderBy from 'lodash/orderBy'
44
5-
6-
const path = defineProp<string>('path', {
7-
type: String,
8-
default: '/'
9-
})
10-
115
const { drive } = useDrive()
126
const router = useRouter()
7+
const route = useRoute()
8+
9+
const path = computed(() => {
10+
return route.query.path as string || '/'
11+
})
1312
1413
const search = ref('')
1514
const entries = ref<DriveEntry[]>([])
@@ -95,7 +94,11 @@ function findIconColor(entry: DriveEntry){
9594
</div>
9695

9796
<div class="flex flex-col overflow-y-auto">
98-
<is-list-item v-for="e in filteredEntries" :key="e.path" @click="onEntryClick(e)">
97+
<is-list-item
98+
v-for="e in filteredEntries"
99+
:key="e.path"
100+
:to="`/entries/${e.path}`"
101+
>
99102
<is-icon
100103
:name="findIcon(e)"
101104
size="xl"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script lang="ts" setup>
2+
3+
import type { AppPage } from '@/composables/defineAppPage'
4+
import type { EntryMiddleware } from '@/composables/defineEntryMiddleware'
5+
6+
const middlewares = ref<EntryMiddleware[]>([])
7+
8+
</script>
9+
10+
<template>
11+
<div>file provider</div>
12+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const directoryMiddleware = defineEntryMiddleware(async ({ entry, router }) => {
2+
if (entry.type !== 'directory') {
3+
return
4+
}
5+
6+
return router.replace(`/app/directory/${entry.path}`)
7+
})

packages/app/src/pages/FileExplorer/components/FileExplorerMarkdownEditor.vue

Lines changed: 0 additions & 126 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts" setup>
2+
3+
const text = ref('')
4+
5+
6+
function save(){
7+
8+
}
9+
10+
</script>
11+
12+
<template>
13+
<is-monaco-editor v-model="text" @keydown.ctrl.s="save" />
14+
</template>

packages/app/src/pages/WorkspaceSelector/WorkspaceSelector.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function select(workspace: Workspace){
4343
4444
setDrive(workspaceDrive)
4545
46-
router.push({ name: 'FileExplorer' })
46+
router.push('/app-pages/directory')
4747
}
4848
4949
</script>

packages/app/src/router/routes.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ const routes: RouteRecordRaw[] = [
1414
},
1515
},
1616
{
17-
path: '/file-explorer',
18-
name: 'FileExplorer',
19-
component: () => import('@/pages/FileExplorer/FileExplorer.vue'),
17+
path: '/entries/:path(.*)*',
18+
name: 'EntryProvider',
19+
props: true,
20+
component: () => import('@/pages/EntryProvider/EntryProvider.vue'),
2021
},
2122
{
22-
path: '/file-explorer/:path(.*)*',
23-
name: 'FileExplorerFolder',
23+
path: '/app-pages/:name',
24+
name: 'AppPageProvider',
2425
props: true,
25-
component: () => import('@/pages/FileExplorer/FileExplorer.vue'),
26+
component: () => import('@/pages/AppPage/AppPage.vue'),
2627
},
2728
{
2829
path: '/cheat-sheet',

0 commit comments

Comments
 (0)