Skip to content

Commit 2dafd00

Browse files
committed
Fix pinned docs in Nuxt build (more)
1 parent 2818fdc commit 2dafd00

File tree

3 files changed

+61
-78
lines changed

3 files changed

+61
-78
lines changed

layouts/dashboard.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { ViewColumnsIcon } from '@heroicons/vue/24/outline'
33
import { CalendarIcon, Cog8ToothIcon, DocumentPlusIcon, HeartIcon, InboxIcon, UserCircleIcon, XMarkIcon } from '@heroicons/vue/24/solid'
44
import { computed, defineComponent, onBeforeUnmount, onMounted } from 'vue'
5-
import { useRouter } from 'vue-router'
65
import { useStore } from 'vuex'
76
import { useMq } from 'vue3-mq'
87
import DiscordIcon from '/assets/discord.svg?component'
@@ -73,9 +72,9 @@ export default defineComponent({
7372
toggleMeta()
7473
})
7574
76-
const handleTabClose = (id: string) => {
75+
const handleTabClose = async (id: string) => {
7776
if (doc.value?.id === id) {
78-
router.push({ path: '/docs/new' })
77+
await router.push({ path: '/docs/new' })
7978
}
8079
8180
unpinDoc(id)

pages/docs/[docId]/index.vue

Lines changed: 57 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
<template>
2-
<Editor
3-
ref="editable"
4-
:appearance="appearance"
5-
:doc="doc"
6-
:key="doc.id"
7-
:initialFocus="initialFocus"
8-
:initialSelections="initialSelections"
9-
:ro="ro"
10-
:settings="settings"
11-
@input="input"
12-
/>
13-
</template>
14-
15-
<script>
16-
import { defineComponent, inject } from 'vue'
1+
<script lang="ts">
2+
import { type Ref, defineComponent, inject } from 'vue'
173
import { useStore } from 'vuex'
184
import Editor from '/components/Editor.vue'
195
import Doc from '/src/models/doc'
206
import { EDIT_DOCUMENT } from '/src/store/actions'
217
import { useRecentDocs } from '/src/stores/useRecentDocs'
228
23-
const formatTags = (tags, delimiter = ', ') => {
9+
const formatTags = (tags: string[], delimiter = ', ') => {
2410
return tags.map((tag) => `#${tag}`).join(delimiter)
2511
}
2612
@@ -33,7 +19,7 @@ export default defineComponent({
3319
initialFocus: {
3420
type: String,
3521
default: () => 'any',
36-
validator: (position) => ['any', 'start', 'end'].includes(position),
22+
validator: (position: string) => ['any', 'start', 'end'].includes(position),
3723
},
3824
initialSelections: {
3925
type: Array,
@@ -43,75 +29,73 @@ export default defineComponent({
4329
type: Boolean,
4430
},
4531
},
46-
data() {
47-
return {
48-
editor: null,
49-
placeholder: new Doc({ text: formatTags(this.$store.state.context.tags, ' ') }),
50-
}
51-
},
5232
setup(props) {
53-
const appearance = inject('appearance')
33+
const appearance = inject<Ref<string>>('appearance', ref('auto'))
34+
const editor = ref()
5435
const router = useRouter()
5536
const store = useStore()
37+
const placeholder = new Doc({ text: formatTags(store.state.context.tags, ' ') })
5638
const settings = computed(() => store.state.settings.editor)
5739
const recentDocs = useRecentDocs()
58-
const docId = computed(() => props.docId || router.currentRoute.value.params.docId)
59-
60-
// Todo: Keep a centralized list of docId exclusions.
61-
if (docId.value && docId.value !== 'new') {
62-
recentDocs.add(docId.value)
63-
}
40+
const docId = computed(() => props.docId || router.currentRoute.value.params.docId as string)
41+
const doc = computed(() => store.getters.decrypted.find((d: Doc) => d.id === docId.value) || placeholder)
42+
const tags = computed(() => doc.value.tags)
43+
const header = computed(() => doc.value.headers[0])
6444
65-
return {
66-
appearance: appearance.value === 'october' ? 'dark' : appearance.value,
67-
settings,
68-
}
69-
},
70-
watch: {
71-
tags: {
72-
deep: true,
73-
handler() {
74-
this.updateTitle()
75-
},
76-
},
77-
header() {
78-
this.updateTitle()
79-
},
80-
},
81-
computed: {
82-
doc() {
83-
return this.$store.getters.decrypted.find((doc) => doc.id === (this.docId || this.$route.params.docId)) || this.placeholder
84-
},
85-
tags() {
86-
return this.doc.tags
87-
},
88-
header() {
89-
return this.doc.headers[0]
90-
},
91-
},
92-
methods: {
93-
input(text) {
94-
if (!this.ro) {
95-
this.$store.commit(EDIT_DOCUMENT, new Doc({ ...this.doc, text }))
45+
const onInput = async (text: string) => {
46+
if (!props.ro) {
47+
store.commit(EDIT_DOCUMENT, new Doc({ ...doc.value, text }))
9648
97-
if (!this.docId) {
98-
this.$router.replace({
99-
path: `/docs/${this.doc.id}`,
49+
if (!docId.value || docId.value === 'new') {
50+
await router.replace({
51+
path: `/docs/${doc.value.id}`,
10052
query: {
101-
p: true,
53+
p: '1',
10254
},
10355
})
56+
57+
recentDocs.add(docId.value)
10458
}
10559
}
106-
},
107-
updateTitle() {
60+
}
61+
62+
onMounted(() => {
63+
// Todo: Keep a centralized list of docId exclusions.
64+
if (docId.value && docId.value !== 'new') {
65+
recentDocs.add(docId.value)
66+
}
67+
})
68+
69+
watchEffect(() => {
10870
useHead({
109-
title: this.header || formatTags(this.doc.tags) || 'Build your second brain',
71+
title: header.value || formatTags(tags.value) || 'Build your second brain',
11072
})
111-
},
112-
},
113-
async mounted() {
114-
this.updateTitle()
73+
})
74+
75+
return {
76+
appearance: appearance.value === 'october' ? 'dark' : appearance.value,
77+
doc,
78+
editor,
79+
header,
80+
onInput,
81+
placeholder,
82+
settings,
83+
tags,
84+
}
11585
},
11686
})
11787
</script>
88+
89+
<template>
90+
<Editor
91+
ref="editable"
92+
:appearance="appearance"
93+
:doc="doc"
94+
:key="doc.id"
95+
:initialFocus="initialFocus"
96+
:initialSelections="initialSelections"
97+
:ro="ro"
98+
:settings="settings"
99+
@input="onInput"
100+
/>
101+
</template>

test/cypress/e2e/editor.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ describe('editor', () => {
33
cy.clearIDB()
44
cy.visit('/docs/new')
55
// Todo: Determine if there is a better way to wait for the initial redirect.
6-
cy.wait(100)
6+
cy.wait(300)
77
cy.visit('/docs/new')
88
})
99

@@ -21,6 +21,6 @@ describe('editor', () => {
2121
it('redirects to /docs/:docId after typing anything', () => {
2222
cy.get('.ink-mde-editor-content').type('a')
2323
cy.url().should('not.match', /\/docs\/new$/)
24-
cy.url().should('match', /\/docs\/.{4,}\?p=true$/)
24+
cy.url().should('match', /\/docs\/.{4,}\?p=1$/)
2525
})
2626
})

0 commit comments

Comments
 (0)