♻️ (store) use a store to store readme and files

This commit is contained in:
2021-03-24 21:23:23 +01:00
parent 165cfb96e7
commit e199c68d68
18 changed files with 202 additions and 229 deletions

View File

@@ -0,0 +1,39 @@
import { RepoFile } from '@/modules/repo/interfaces/RepoFile'
import { getFiles, getMainReadme } from '@/modules/repo/services/repo'
import { defineStore } from 'pinia'
interface State {
user: string
repo: string
files: RepoFile[]
readme: string | null
}
export const useUserRepoStore = defineStore({
id: 'USER_REPO_STATE',
state: (): State => ({
user: '',
repo: '',
files: [],
readme: null
}),
actions: {
async setUserRepo(newUser: string, newRepo: string) {
this.user = newUser
this.repo = newRepo
const [readme, files] = await Promise.all([
getMainReadme(newUser, newRepo),
getFiles(newUser, newRepo)
])
this.readme = readme
this.files = files
},
resetUserRepo() {
this.user = ''
this.repo = ''
this.files = []
this.readme = null
}
}
})