♻️ (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

View File

@@ -35,6 +35,6 @@ export default defineComponent({
.stacked-note { .stacked-note {
text-align: left; text-align: left;
border-left: 1px solid rgba(18, 19, 58, 0.2); border-left: 1px solid rgba(18, 19, 58, 0.2);
padding-left: 1rem; padding: 0 1rem;
} }
</style> </style>

View File

@@ -0,0 +1,16 @@
<template>
<div class="welcome-world"></div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
name: 'WelcomeWord'
})
</script>
<style lang="scss" scoped>
.welcome-world {
}
</style>

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 MarkdownIt from 'markdown-it'
import markdownItClass from '@toycode/markdown-it-class' import markdownItClass from '@toycode/markdown-it-class'
// import sanitizeHtml from 'sanitize-html'
const md = new MarkdownIt().use(markdownItClass, { const md = new MarkdownIt().use(markdownItClass, {
h1: ['title', 'is-1'], h1: ['title', 'is-1'],

View File

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

View File

@@ -4,20 +4,15 @@ import Home from '@/views/Home.vue'
const routes: Array<RouteRecordRaw> = [ const routes: Array<RouteRecordRaw> = [
{ {
path: '/', path: '/:user?/:repo?',
name: 'Home', name: 'Home',
props: true,
component: Home component: Home
}, },
{ {
path: '/about', path: '/about',
name: 'About', name: 'About',
component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue') component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue')
},
{
path: '/note/:user/:repo',
name: 'Note',
props: true,
component: () => import(/* webpackChunkName: "note" */ '@/views/Note.vue')
} }
] ]

View File

@@ -1,31 +1,80 @@
<template> <template>
<div class="home"> <div v-if="!user || !repo">
<p class="note" v-html="readme"></p> Bonjour
<form @submit.prevent>
<div class="columns is-centered is-vcentered">
<div class="column">
<div class="field">
<label class="label">user</label>
<div class="control">
<input class="input" type="text" v-model="userInput" />
</div>
</div>
</div>
<div class="column">/</div>
<div class="column">
<div class="field">
<label class="label">repo</label>
<div class="control">
<input class="input" type="text" v-model="repoInput" />
</div>
</div>
</div>
</div>
<button type="submit" class="button is-primary" @click="submit">
y aller
</button>
</form>
</div>
<div class="home content" v-else>
<hr v-if="notFound" />
<div v-if="notFound" class="columns is-centered">
<div class="column is-one-third notification is-warning" v-if="notFound">
Not found.
</div>
</div>
<div class="columns">
<div class="column">
<h1 class="title is-1">
<router-link :to="{ name: 'Home' }">
{{ repo }}
</router-link>
</h1>
<h2 class="subtitle is-2">{{ user }}</h2>
<p class="note-display" v-html="readme"></p>
</div>
<div
class="column"
v-for="stackedNote in stackedNotes"
:key="stackedNote"
>
<stacked-note :user="user" :repo="repo" :sha="stackedNote" />
</div>
</div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, watch, nextTick } from 'vue' import { defineComponent, defineAsyncComponent } from 'vue'
import { useRepo } from '@/hooks/useRepo.hook' import { useNote } from '@/hooks/useNote.hook'
import { useLinks } from '@/hooks/useLinks.hook' import { useForm } from '@/hooks/useForm.hook'
const StackedNote = defineAsyncComponent(() =>
import('@/components/StackedNote.vue')
)
export default defineComponent({ export default defineComponent({
name: 'Home', name: 'Home',
setup() { components: {
const { readme } = useRepo('jcalixte', 'notes') StackedNote
const { listenToClick } = useLinks('note') },
props: {
watch(readme, () => { user: { type: String, required: false },
if (readme.value) { repo: { type: String, required: false }
nextTick(() => { },
listenToClick() setup(props) {
}) return { ...useNote(props.user, props.repo), ...useForm() }
}
})
return {
readme
}
} }
}) })
</script> </script>

View File

@@ -1,51 +0,0 @@
<template>
<div class="note content">
<hr v-if="notFound" />
<div v-if="notFound" class="columns is-centered">
<div class="column is-one-third notification is-warning" v-if="notFound">
Not found.
</div>
</div>
<div class="columns">
<div class="column">
<h1 class="title is-1">
<router-link :to="{ name: 'Note' }">
{{ repo }}
</router-link>
</h1>
<h2 class="subtitle is-2">{{ user }}</h2>
<p class="note-display" v-html="readme"></p>
</div>
<div
class="column"
v-for="stackedNote in stackedNotes"
:key="stackedNote"
>
<stacked-note :user="user" :repo="repo" :sha="stackedNote" />
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, defineAsyncComponent } from 'vue'
import { useNote } from '@/hooks/useNote.hook'
const StackedNote = defineAsyncComponent(() =>
import('@/components/StackedNote.vue')
)
export default defineComponent({
name: 'Home',
components: {
StackedNote
},
props: {
user: { type: String, required: true },
repo: { type: String, required: true }
},
setup(props) {
return useNote(props.user, props.repo)
}
})
</script>