-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project-files): update a FileStructureHandler and provide it in …
…ProjectBoard view
- Loading branch information
1 parent
a39e47a
commit a47743c
Showing
9 changed files
with
321 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,85 @@ | ||
import { reactive, readonly, toRefs } from "@vue/reactivity"; | ||
import FileService from "@/server/FileService"; | ||
import { FileStructureHandler } from "@/utils/file-structure"; | ||
|
||
const state = reactive({ | ||
projectFiles: [], | ||
projectFileStructure: {} | ||
}); | ||
|
||
const loadProjectFiles = async project => { | ||
const files = await FileService.fetchDocuments(project); | ||
state.projectFiles = files; | ||
return files; | ||
}; | ||
let fileStructureHandler = null; | ||
|
||
const loadProjectFileStructure = async project => { | ||
const fileStructure = await FileService.fetchFileStructure(project); | ||
state.projectFileStructure = fileStructure; | ||
fileStructureHandler = new FileStructureHandler(fileStructure); | ||
return fileStructure; | ||
}; | ||
|
||
const softUpdateFileStructure = (action, files) => { | ||
for (const file of [files].flat()) { | ||
switch (action) { | ||
case "create": | ||
// TODO | ||
break; | ||
case "update": | ||
// TODO | ||
break; | ||
case "delete": | ||
// TODO | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
const createFolder = async (project, folder) => { | ||
const newFolder = await FileService.createFolder(project, folder); | ||
softUpdateFileStructure("create", newFolder); | ||
return newFolder; | ||
}; | ||
|
||
const updateFolders = async (project, folders) => { | ||
const newFolders = await FileService.updateFolders(project, folders); | ||
softUpdateFileStructure("update", newFolders); | ||
return newFolders; | ||
}; | ||
|
||
const deleteFolders = async (project, folders) => { | ||
await FileService.deleteFolders(project, folders); | ||
softUpdateFileStructure("delete", folders); | ||
return folders; | ||
}; | ||
|
||
const createDocument = async (project, document) => { | ||
const newDocument = await FileService.createDocument(project, document); | ||
softUpdateFileStructure("create", newDocument); | ||
return newDocument; | ||
}; | ||
|
||
const updateDocuments = async (project, documents) => { | ||
const newDocuments = await FileService.updateDocuments(project, documents); | ||
softUpdateFileStructure("update", newDocuments); | ||
return newDocuments; | ||
}; | ||
|
||
const deleteDocuments = async (project, documents) => { | ||
await FileService.deleteDocuments(project, documents); | ||
softUpdateFileStructure("delete", documents); | ||
return documents; | ||
}; | ||
|
||
export function useFiles() { | ||
const readOnlyState = readonly(state); | ||
return { | ||
// References | ||
...toRefs(readOnlyState), | ||
loadProjectFiles, | ||
loadProjectFileStructure | ||
fileStructureHandler: () => fileStructureHandler, | ||
// Methods | ||
loadProjectFileStructure, | ||
createFolder, | ||
updateFolders, | ||
deleteFolders, | ||
createDocument, | ||
updateDocuments, | ||
deleteDocuments | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.