You've already forked obsidian-visualiser
Refactoring search, navigation, canvas and others to fit the new data model
This commit is contained in:
37
composables/useProject.ts
Normal file
37
composables/useProject.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { Project } from "~/server/api/project.get";
|
||||
|
||||
export default function useProject()
|
||||
{
|
||||
const id = useState<number>("projectId", () => 1);
|
||||
const name = useState<string>("projectName", undefined);
|
||||
const owner = useState<number>("projectOwner", undefined);
|
||||
const home = useState<string | null>("projectHomepage", () => null);
|
||||
|
||||
return {
|
||||
id, name, owner, home, get, set
|
||||
}
|
||||
}
|
||||
|
||||
async function get(): Promise<void> {
|
||||
const id = useState<number>("projectId");
|
||||
|
||||
if (!id.value)
|
||||
return;
|
||||
|
||||
try {
|
||||
const result = await $fetch(`/api/project/${id}`) as Project;
|
||||
|
||||
const name = useState<string>("projectName");
|
||||
const owner = useState<number>("projectOwner");
|
||||
const home = useState<string | null>("projectHomepage");
|
||||
|
||||
name.value = result.name;
|
||||
owner.value = result.owner;
|
||||
home.value = result.home;
|
||||
} catch(e) {}
|
||||
}
|
||||
function set(id: number): void {
|
||||
const _id = useState<number>("projectId");
|
||||
|
||||
_id.value = id;
|
||||
}
|
||||
Reference in New Issue
Block a user