11<template >
22 <section class =" flex font-poppins flex-col gap-3 w-60 overflow-y-auto" >
3- <div v-for =" (project, key) in projects " :key =" key" class =" flex-col p-2 text-white w-full transition-colors gap-5 hover:bg-theme-background-3" >
3+ <div v-if = " AUTH.user " v- for =" (project, key) in VAULT.libraries " :key =" key" class =" flex-col p-2 text-white w-full transition-colors gap-5 hover:bg-theme-background-3" >
44 <div class =" flex gap-5 w-full" >
55 <p class =" truncate" >{{ project.title }}</p >
6- <p class =" truncate" >{{ project.size }}</p >
76 </div >
8- <div class =" flex justify-between w-full" >
9- <p >Level {{ project.level }}</p >
7+ <div class =" flex justify-end w-full" >
108 <div class =" flex gap-3" >
11- <IconDelete @click =" backend . deleteProject (project .title )" class="wb-icon w-5 h-5"></IconDelete >
12- <IconEnter @click =" backend . getProject (project .title )" class="wb-icon w-5 h-5"></IconEnter >
9+ <IconDelete @click =" onDeleteProject (project .user_id )" class="wb-icon w-5 h-5"></IconDelete >
10+ <IconEnter @click =" onLoadProject (project .user_id )" class="wb-icon w-5 h-5"></IconEnter >
1311 </div >
1412 </div >
1513 </div >
1816
1917<script setup lang="ts">
2018import { useAuthStore } from ' @/store/auth' ;
21- import { useBackend } from ' @/use/backend' ;
22- import type { AuthItem } from ' better-write-types' ;
23- import { onMounted , ref } from ' vue' ;
19+ import { useVaultStore } from ' @/store/vault' ;
20+ import { useEnv } from ' @/use/env' ;
21+ import { useProject } from ' @/use/project' ;
22+ import { onMounted } from ' vue' ;
2423import { useI18n } from ' vue-i18n' ;
24+ import { useToast } from ' vue-toastification' ;
2525
2626const AUTH = useAuthStore ()
27+ const VAULT = useVaultStore ()
2728
28- const backend = useBackend ()
29+ const project = useProject ()
30+ const toast = useToast ()
2931const { t } = useI18n ()
32+ const env = useEnv ()
3033
31- // TODO: Backend here
32- const projects = ref <AuthItem []>([{
33- title: ' Test' ,
34- size: ' 1.6KiB' ,
35- level: 2 ,
36- }])
3734
3835onMounted (() => {
39- // projects.value = backend.getLibraries('0')
36+ if (VAULT .libraries .length === 0 ) {
37+ fetch (` ${env .api ()}/libraries/${AUTH .user .id } ` , { method: ' GET' })
38+ .then (res => res .json ())
39+ .then ((libraries ) => {
40+ VAULT .libraries = libraries
41+
42+ toast .success (t (' backend.vaultLoadSuccess' ))
43+ })
44+ .catch (() => {
45+ toast .error (t (' backend.vaultloadError' ))
46+ })
47+ }
4048})
49+
50+ const onDeleteProject = (id : number ) => {
51+ fetch (` ${env .api ()}/library/${id } ` , { method: ' DELETE' })
52+ .then (res => res .json ())
53+ .then (({ library }) => {
54+ VAULT .libraries = VAULT .libraries .filter (({ id }) => id !== library .id )
55+ toast .error (t (' backend.vault.deleteSuccess' ))
56+ })
57+ .catch (() => {
58+ toast .error (t (' backend.vault.deleteError' ))
59+ })
60+ }
61+
62+ const onLoadProject = (id : number ) => {
63+ fetch (` ${env .api ()}/library/${id } ` , { method: ' GET' })
64+ .then (res => res .json ())
65+ .then (({ vault }) => {
66+ console .log (vault )
67+ project .onLoadProject (vault .content , true ).then (() => {})
68+ })
69+ .catch (() => {
70+ toast .error (t (' backend.vault.loadVaultError' ))
71+ })
72+ }
4173 </script >
0 commit comments