This commit is contained in:
vadim committed 2026-09-24 15:08:46 +03:00
commit fcec12e5ba
78 files changed
+9569

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import {
type CreateIssueInput,
type Issue,
itemCreate,
itemDelete,
itemGetByKey,
itemsList,
itemStat,
itemUpdate,
type IssueStat,
type Meta,
type UpdateIssueInput,
} from '@/api/issue.api.ts'
export const useIssueStore = defineStore('item', () => {
const issues = ref<Issue[]>([])
const stats = ref<IssueStat>()
const error = ref<string | null>(null)
const lastMeta = ref<Meta>({
page: 1,
totalCount: 0,
totalPages: 0,
})
async function list(params: { page: number; limit: number; text?: string | null; projectId?: string | null }) {
try {
const res = await itemsList(params)
issues.value = res.list
return res
} catch (e) {
error.value = e instanceof Error ? e.message : 'error get list of items'
return { list: [], meta: lastMeta.value }
}
}
async function getByKey(ckey: string) {
try {
const res = await itemGetByKey(ckey)
return res
} catch (e) {
error.value = e instanceof Error ? e.message : 'error get item by key'
}
}
async function create(input: CreateIssueInput) {
try {
return await itemCreate(input)
} catch (e) {
error.value = e instanceof Error ? e.message : 'error creating issue'
}
}
async function update(id: number, input: UpdateIssueInput) {
try {
return await itemUpdate(id, input)
} catch (e) {
error.value = e instanceof Error ? e.message : 'error updating issue'
}
}
async function remove(id: number) {
try {
return await itemDelete(id)
} catch (e) {
error.value = e instanceof Error ? e.message : 'error deleting issue'
return false
}
}
async function getStat(): Promise<IssueStat | undefined> {
try {
stats.value = await itemStat()
return stats.value
} catch (e) {
error.value = e instanceof Error ? e.message : 'error getting issue stat'
}
}
return { stats, list, getByKey, create, update, remove, getStat }
})
+122
View File
@@ -0,0 +1,122 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import {
type CreateProjectInput,
itemCreate,
itemDelete,
itemGetById,
itemsList,
itemUpdate,
type Project,
type UpdateProjectInput,
} from '@/api/project.api.ts'
import type { Meta } from '@/api/issue.api.ts'
const CURRENT_PROJECT_KEY = 'currentProjectId'
function readStoredProjectId(): string | null {
try {
return localStorage.getItem(CURRENT_PROJECT_KEY)
} catch {
// ignore storage errors (e.g. disabled in private mode)
return null
}
}
export const useProjectStore = defineStore('project', () => {
const projects = ref<Project[]>([])
const current = ref<Project | null>(null)
// Seeded synchronously from localStorage so consumers (e.g. the issues list)
// know the selected project id immediately, without waiting for `current`
// to be resolved over the network via restoreCurrent().
const currentProjectId = ref<string | null>(readStoredProjectId())
const error = ref<string | null>(null)
const lastMeta = ref<Meta>({
page: 1,
totalCount: 0,
totalPages: 0,
})
async function list(params: { page: number; limit: number }) {
try {
const res = await itemsList(params)
projects.value = res.list
return res
} catch (e) {
error.value = e instanceof Error ? e.message : 'error get list of projects'
return { list: [], meta: lastMeta.value }
}
}
async function getById(id: string) {
try {
return await itemGetById(id)
} catch (e) {
error.value = e instanceof Error ? e.message : 'error get project by id'
}
}
async function create(input: CreateProjectInput) {
try {
return await itemCreate(input)
} catch (e) {
error.value = e instanceof Error ? e.message : 'error creating project'
}
}
async function update(id: string, input: UpdateProjectInput) {
try {
return await itemUpdate(id, input)
} catch (e) {
error.value = e instanceof Error ? e.message : 'error updating project'
}
}
async function remove(id: string) {
try {
return await itemDelete(id)
} catch (e) {
error.value = e instanceof Error ? e.message : 'error deleting project'
return false
}
}
function clearError() {
error.value = null
}
function select(project: Project | null) {
current.value = project
currentProjectId.value = project?.id ?? null
try {
if (project) localStorage.setItem(CURRENT_PROJECT_KEY, project.id)
else localStorage.removeItem(CURRENT_PROJECT_KEY)
} catch {
// ignore storage errors (e.g. disabled in private mode)
}
}
async function restoreCurrent() {
const id = readStoredProjectId()
if (!id) return
const project = projects.value.find((el) => el.id === id) ?? (await getById(id))
if (project) current.value = project
else select(null) // stored id no longer refers to an existing project
}
return {
projects,
current,
currentProjectId,
error,
list,
getById,
create,
update,
remove,
clearError,
select,
restoreCurrent,
}
})
+13
View File
@@ -0,0 +1,13 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { type Status, statusesList } from '@/api/status.api.ts'
export const useStatusStore = defineStore('counter', () => {
const statuses = ref<Status[]>()
async function list() {
statuses.value = await statusesList()
}
return { statuses, list }
})
+35
View File
@@ -0,0 +1,35 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { itemGetById, itemsList, type User } from '@/api/user.api.ts'
import type { Meta } from '@/api/issue.api.ts'
export const useUserStore = defineStore('user', () => {
const users = ref<User[]>([])
const error = ref<string | null>(null)
const lastMeta = ref<Meta>({
page: 1,
totalCount: 0,
totalPages: 0,
})
async function list(params: { page: number; limit: number }) {
try {
const res = await itemsList(params)
users.value = res.list
return res
} catch (e) {
error.value = e instanceof Error ? e.message : 'error get list of users'
return { list: [], meta: lastMeta.value }
}
}
async function getById(id: string) {
try {
return await itemGetById(id)
} catch (e) {
error.value = e instanceof Error ? e.message : 'error get user by id'
}
}
return { users, error, list, getById }
})