You've already forked obsidian-visualiser
Project list and starting editing
This commit is contained in:
@@ -1,37 +1,50 @@
|
||||
import type { Project } from "~/server/api/project.get";
|
||||
import type { Project } from "~/types/api";
|
||||
|
||||
export default function useProject()
|
||||
{
|
||||
const id = useState<number>("projectId", () => 1);
|
||||
const project = useCookie('project');
|
||||
|
||||
const id = useState<number>("projectId", () => parseInt(project.value ?? '0'));
|
||||
const name = useState<string>("projectName", undefined);
|
||||
const owner = useState<number>("projectOwner", undefined);
|
||||
const home = useState<string | null>("projectHomepage", () => null);
|
||||
const summary = useState<string | null>("projectSummary", () => null);
|
||||
|
||||
return {
|
||||
id, name, owner, home, get, set
|
||||
}
|
||||
id, name, owner, home, summary, get, set
|
||||
};
|
||||
}
|
||||
|
||||
async function get(): Promise<void> {
|
||||
async function get(): Promise<boolean> {
|
||||
const id = useState<number>("projectId");
|
||||
|
||||
if (!id.value)
|
||||
return;
|
||||
return false;
|
||||
|
||||
try {
|
||||
const result = await $fetch(`/api/project/${id}`) as Project;
|
||||
const result = await $fetch(`/api/project/${id.value}`) as Project;
|
||||
|
||||
const name = useState<string>("projectName");
|
||||
const owner = useState<number>("projectOwner");
|
||||
const home = useState<string | null>("projectHomepage");
|
||||
const summary = useState<string | null>("projectSummary");
|
||||
|
||||
name.value = result.name;
|
||||
owner.value = result.owner;
|
||||
home.value = result.home;
|
||||
} catch(e) {}
|
||||
summary.value = result.summary;
|
||||
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function set(id: number): void {
|
||||
async function set(id: number): Promise<boolean> {
|
||||
const _id = useState<number>("projectId");
|
||||
|
||||
_id.value = id;
|
||||
const project = useCookie('project');
|
||||
project.value = id.toString();
|
||||
|
||||
return await get();
|
||||
}
|
||||
Reference in New Issue
Block a user