🚨 (app)

This commit is contained in:
Julien Calixte
2021-05-08 14:46:12 +02:00
parent 80fe2d6992
commit a9fba33760
5 changed files with 114 additions and 115 deletions

View File

@@ -1,33 +1,33 @@
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { confirmMessage } from '@/utils/notif' import { confirmMessage } from '@/utils/notif'
import { GithubToken } from '@/modules/user/interfaces/GithubToken'
import { getAccessToken, saveAccessToken } from '@/modules/user/service/signIn' import { getAccessToken, saveAccessToken } from '@/modules/user/service/signIn'
import { GithubToken } from '@/modules/user/interfaces/GithubToken'
const username = ref<string | null>(null) const username = ref<string | null>(null)
const accessToken = ref<string | null>(null) const accessToken = ref<string | null>(null)
let init = true let init = true
export const useGitHubLogin = () => { const saveAccessTokenToLocal = async () => {
const saveAccessTokenToLocal = async () => { const response = await getAccessToken()
const response = await getAccessToken() username.value = response?.username || ''
username.value = response?.username || '' accessToken.value = response?.token || ''
accessToken.value = response?.token || '' }
}
const saveCredentials = async (token: GithubToken): Promise<void> => {
const accessToken = await saveAccessToken(token)
await saveAccessTokenToLocal()
confirmMessage(`${accessToken.username} is logged in!`)
}
export const useGitHubLogin = () => {
if (init) { if (init) {
init = false init = false
saveAccessTokenToLocal() saveAccessTokenToLocal()
} }
const saveCredentials = async (githubToken: GithubToken) => {
const accessToken = await saveAccessToken(githubToken)
await saveAccessTokenToLocal()
confirmMessage(`${accessToken.username} is logged in!`)
}
return { return {
isLogged: !!accessToken.value, isLogged: !!accessToken.value,
isReady: computed(() => accessToken.value !== null), isReady: computed(() => accessToken.value !== null),

View File

@@ -29,7 +29,6 @@ export const useUserRepoStore = defineStore({
async setUserRepo(newUser: string, newRepo: string) { async setUserRepo(newUser: string, newRepo: string) {
this.user = newUser this.user = newUser
this.repo = newRepo this.repo = newRepo
await refreshToken()
const [readme, files] = await Promise.all([ const [readme, files] = await Promise.all([
getMainReadme(newUser, newRepo), getMainReadme(newUser, newRepo),
getFiles(newUser, newRepo) getFiles(newUser, newRepo)

View File

@@ -1,47 +1,45 @@
<template> <template>
<div class="draft-notes"> <div class="draft-notes">
<flux-note :user="user" :repo="repo" :content="content" key="draft-notes"> <flux-note key="draft-notes" :user="user" :repo="repo" :content="content">
<h3 class="subtitle is-3"> <h3 class="subtitle is-3">Drafts</h3>
Drafts </flux-note>
</h3> </div>
</flux-note> </template>
</div>
</template> <script lang="ts">
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
<script lang="ts"> import { defineAsyncComponent, defineComponent } from 'vue'
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
import { defineAsyncComponent, defineComponent } from 'vue' const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue')) const DRAFT_FOLDER = ['drafts', '_drafts']
const DRAFT_FOLDER = ['drafts', '_drafts'] export default defineComponent({
name: 'DraftNotes',
export default defineComponent({ components: {
name: 'DraftNotes', FluxNote
components: { },
FluxNote props: {
}, user: { type: String, required: true },
props: { repo: { type: String, required: true }
user: { type: String, required: true }, },
repo: { type: String, required: true } setup() {
}, const { content } = useFolderNotes(DRAFT_FOLDER)
setup() {
const { content } = useFolderNotes(DRAFT_FOLDER) return {
content
return { }
content }
} })
} </script>
})
</script> <style scoped lang="scss">
.draft-notes {
<style scoped lang="scss"> display: flex;
.draft-notes { flex: 1;
display: flex;
flex: 1; .subtitle {
text-align: center;
.subtitle { }
text-align: center; }
} </style>
}
</style>

View File

@@ -1,52 +1,50 @@
<template> <template>
<div class="fleeting-notes"> <div class="fleeting-notes">
<flux-note <flux-note
:user="user" key="fleeting-notes"
:repo="repo" :user="user"
:content="content" :repo="repo"
key="fleeting-notes" :content="content"
> >
<h3 class="subtitle is-3"> <h3 class="subtitle is-3">Inbox</h3>
Inbox </flux-note>
</h3> </div>
</flux-note> </template>
</div>
</template> <script lang="ts">
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
<script lang="ts"> import { defineAsyncComponent, defineComponent } from 'vue'
import { useFolderNotes } from '@/modules/note/hooks/useFolderNotes'
import { defineAsyncComponent, defineComponent } from 'vue' const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue')) const FLEETING_NOTES_FOLDER = ['inbox', '_inbox']
const FLEETING_NOTES_FOLDER = ['inbox', '_inbox'] export default defineComponent({
name: 'FleetingNotes',
export default defineComponent({ components: {
name: 'FleetingNotes', FluxNote
components: { },
FluxNote props: {
}, user: { type: String, required: true },
props: { repo: { type: String, required: true }
user: { type: String, required: true }, },
repo: { type: String, required: true } setup() {
}, const { content } = useFolderNotes(FLEETING_NOTES_FOLDER)
setup() {
const { content } = useFolderNotes(FLEETING_NOTES_FOLDER) return {
content
return { }
content }
} })
} </script>
})
</script> <style scoped lang="scss">
.fleeting-notes {
<style scoped lang="scss"> display: flex;
.fleeting-notes { flex: 1;
display: flex;
flex: 1; .subtitle {
text-align: center;
.subtitle { }
text-align: center; }
} </style>
}
</style>

View File

@@ -8,10 +8,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, defineAsyncComponent, computed } from 'vue' import { defineComponent, defineAsyncComponent, computed, onMounted } from 'vue'
import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook' import { useQueryStackedNotes } from '@/hooks/useQueryStackedNotes.hook'
import NewVersion from '@/components/NewVersion.vue' import NewVersion from '@/components/NewVersion.vue'
import Authorize from '@/components/Authorize.vue' import Authorize from '@/components/Authorize.vue'
import { refreshToken } from '@/modules/user/service/signIn'
const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue')) const FluxNote = defineAsyncComponent(() => import('@/components/FluxNote.vue'))
@@ -33,6 +34,9 @@ export default defineComponent({
}, },
setup(props) { setup(props) {
const { resetStackedNotes } = useQueryStackedNotes() const { resetStackedNotes } = useQueryStackedNotes()
onMounted(() => {
refreshToken()
})
return { return {
resetStackedNotes, resetStackedNotes,