♻️ (notes) home is now the note initial screen with a fo…

This commit is contained in:
2021-03-13 22:38:21 +01:00
parent 8fad931dfd
commit 2286bd5d85
8 changed files with 133 additions and 85 deletions

28
src/hooks/useForm.hook.ts Normal file
View File

@@ -0,0 +1,28 @@
import { ref } from '@vue/reactivity'
import { useRouter } from 'vue-router'
export const useForm = () => {
const userInput = ref('')
const repoInput = ref('')
const { push } = useRouter()
const submit = () => {
if (!userInput.value || !repoInput.value) {
return
}
push({
name: 'Home',
params: {
user: userInput.value,
repo: repoInput.value
}
})
}
return {
userInput,
repoInput,
submit
}
}

View File

@@ -1,6 +1,5 @@
import MarkdownIt from 'markdown-it'
import markdownItClass from '@toycode/markdown-it-class'
// import sanitizeHtml from 'sanitize-html'
const md = new MarkdownIt().use(markdownItClass, {
h1: ['title', 'is-1'],

View File

@@ -13,12 +13,9 @@ const sanitizePath = (path: string) => {
return decodeURIComponent(path)
}
export const useNote = (user: string, repo: string) => {
export const useNote = (user?: string, repo?: string) => {
const { push } = useRouter()
const { readme, notFound, tree } = useRepo(user, repo)
const { listenToClick } = useLinks('note-display')
const { query } = useRoute()
const stackedNotes = ref(
query.stackedNotes
? Array.isArray(query.stackedNotes)
@@ -27,6 +24,17 @@ export const useNote = (user: string, repo: string) => {
: []
)
if (!user || !repo) {
return {
readme: ref(null),
notFound: ref(true),
stackedNotes
}
}
const { readme, notFound, tree } = useRepo(user, repo)
const { listenToClick } = useLinks('note-display')
const unsubscribe = noteEventBus.addEventBusListener(
({ path, currentNoteSHA }) => {
const currentFile = tree.value.find((file) => file.sha === currentNoteSHA)
@@ -68,7 +76,11 @@ export const useNote = (user: string, repo: string) => {
const newStackedNotes = getStackedNotes()
push({
name: 'Note',
name: 'Home',
params: {
user,
repo
},
query: {
stackedNotes: newStackedNotes
}