Skip to content

Commit

Permalink
docs(commits): restructure store
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Jul 6, 2024
1 parent 43e9587 commit f32ff10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/docs/src/components/app/CommitBtn.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<v-btn
v-if="commits.latest"
:href="`https://github.com/vuetifyjs/vuetify/commit/${commits.latest?.sha}`"
:text="commits.latest?.sha?.slice(0, 7)"
:prepend-icon="commits.latest ? 'mdi-source-commit' : undefined"
:readonly="!commits.latest"
:text="commits.latest?.sha.slice(0, 7)"
class="text-caption"
prepend-icon="mdi-source-commit"
rel="noopener noreferrer"
size="small"
target="_blank"
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/app/settings/LatestCommit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
v-if="commits.latest"
:href="`https://github.com/vuetifyjs/vuetify/commit/${commits.latest?.sha}`"
:label="t('latest-commit')"
:title="commits.latest?.sha?.slice(0, 7)"
:title="commits.latest?.sha.slice(0, 7)"
append-icon="mdi-open-in-new"
min-width="90"
prepend-icon="mdi-source-commit"
Expand Down
10 changes: 7 additions & 3 deletions packages/docs/src/stores/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { components as octokitComponents } from '@octokit/openapi-types'
export type Commit = octokitComponents['schemas']['commit']

export type State = {
latest: Commit | null
commits: Commit[]
isLoading: boolean
}
Expand All @@ -13,7 +12,6 @@ const url = import.meta.env.VITE_API_SERVER_URL

export const useCommitsStore = defineStore('commits', {
state: (): State => ({
latest: null,
commits: [] as Commit[],
isLoading: false,
}),
Expand All @@ -23,7 +21,7 @@ export const useCommitsStore = defineStore('commits', {
this.isLoading = true

try {
this.latest = await fetch(`${url}/github/commits`, {
this.commits = await fetch(`${url}/github/commits`, {
method: 'GET',
credentials: 'include',
}).then(res => res.json())
Expand All @@ -34,4 +32,10 @@ export const useCommitsStore = defineStore('commits', {
this.isLoading = false
},
},

getters: {
latest (state) {
return state.commits[0]
},
},
})

0 comments on commit f32ff10

Please # to comment.