woodpecker/web/src/store/repos.ts
Anbraten 58838f225c
Rewrite of WebUI (#245)
Rewrite of the UI using Typescript, Vue3, Windicss and Vite. The design should  be close to the current one with some changes:
- latest pipeline in a sidebar on the right
- secrets and registry as part of the repo-settings (secrets and registry entries shouldn't be used as much so they can be "hidden" under settings IMO)
- start page shows list of active repositories with button to enable / add new ones (currently you see all repositories and in most cases you only add new repositories once in a while)
2021-11-03 17:40:31 +01:00

44 lines
1 KiB
TypeScript

import { defineStore } from 'pinia';
import { computed, Ref, toRef } from 'vue';
import useApiClient from '~/compositions/useApiClient';
import { Repo } from '~/lib/api/types';
import { repoSlug } from '~/utils/helpers';
const apiClient = useApiClient();
export default defineStore({
id: 'repos',
state: () => ({
repos: {} as Record<string, Repo>,
}),
actions: {
// getter
getRepo(owner: Ref<string>, name: Ref<string>) {
return computed(() => {
const slug = repoSlug(owner.value, name.value);
return toRef(this.repos, slug).value;
});
},
// setter
setRepo(repo: Repo) {
this.repos[repoSlug(repo)] = repo;
},
// loading
async loadRepo(owner: string, name: string) {
const repo = await apiClient.getRepo(owner, name);
this.repos[repoSlug(repo)] = repo;
},
async loadRepos() {
const repos = await apiClient.getRepoList();
repos.forEach((repo) => {
this.repos[repoSlug(repo.owner, repo.name)] = repo;
});
},
},
});