From 036dc5a80582c2ffc13aeb5a98e667d927012d2e Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Mon, 22 Jul 2024 19:28:39 +0200 Subject: [PATCH] fixes --- dist/index.js | 112 +++++++++++++++------ src/Model/Files/fileModel.ts | 19 ---- src/Model/Files/taskModel.ts | 115 +++++++++++++--------- src/Model/Global/storageModel.ts | 1 - src/View/Components/directoryItemList.tsx | 8 +- 5 files changed, 156 insertions(+), 99 deletions(-) diff --git a/dist/index.js b/dist/index.js index d51f5aeb..6d3f0247 100644 --- a/dist/index.js +++ b/dist/index.js @@ -538,6 +538,9 @@ getBoardFilePath = (boardId) => { return [...this.fileModel.getFilePath(boardId)]; }; + getTaskFilePath = (taskId) => { + return [...this.fileModel.getFilePath(taskId)]; + }; getBoardContainerPath = () => { return [...this.getBasePath(), subDirectories.boards]; }; @@ -547,12 +550,9 @@ getTaskContainerPath = (boardId) => { return [...this.getBoardDirectoryPath(boardId), subDirectories.boardTasks]; }; - getTaskPath = (boardId, fileId) => { + getTaskReferencePath = (boardId, fileId) => { return [...this.getTaskContainerPath(boardId), fileId]; }; - getTaskContentPath = (boardId, fileId, versionId) => { - return [...this.getTaskPath(boardId, fileId), versionId]; - }; // handler handleFileContent = (fileContent) => { if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) { @@ -562,14 +562,32 @@ } }; handleBoard = (boardInfoFileContent) => { - console.log("board", boardInfoFileContent); + this.storeBoard(boardInfoFileContent); }; handleTask = (taskFileContent) => { + this.storeTask(taskFileContent); }; // boards createBoard = (name) => { const boardInfoFileContent = _TaskModel.createBoardInfoFileContent(v4_default(), name, "standard" /* Standard */); - this.createOrUpdateBoard(boardInfoFileContent); + this.updateBoard(boardInfoFileContent); + }; + updateBoard = (boardInfoFileContent) => { + this.storeBoard(boardInfoFileContent); + this.chatModel.sendMessage("", boardInfoFileContent); + }; + storeBoard = (boardInfoFileContent) => { + this.fileModel.addFileContent(boardInfoFileContent); + const boardDirectoryPath = this.getBoardDirectoryPath( + boardInfoFileContent.fileId + ); + this.storageModel.write(boardDirectoryPath, ""); + }; + deleteBoard = (boardId) => { + const boardFilePath = this.getBoardFilePath(boardId); + const boardDirectoryPath = this.getBoardDirectoryPath(boardId); + this.storageModel.removeRecursively(boardFilePath); + this.storageModel.removeRecursively(boardDirectoryPath); }; listBoardIds = () => { const boardContainerPath = this.getBoardContainerPath(); @@ -583,37 +601,42 @@ ); return boardInfoFileContentOrNull; }; - createOrUpdateBoard = (boardInfoFileContent) => { - this.fileModel.addFileContent(boardInfoFileContent); - const boardDirectoryPath = this.getBoardDirectoryPath( - boardInfoFileContent.fileId - ); - this.storageModel.write(boardDirectoryPath, ""); - }; - deleteBoard = (boardId) => { - const boardFilePath = this.getBoardFilePath(boardId); - const boardDirectoryPath = this.getBoardDirectoryPath(boardId); - this.storageModel.removeRecursively(boardFilePath); - this.storageModel.removeRecursively(boardDirectoryPath); - }; //tasks createTask = (boardId, name) => { const taskFileContent = _TaskModel.createTaskFileContent( v4_default(), - boardId, - name + name, + boardId ); - this.fileModel.addFileContent(taskFileContent); + this.updateTask(taskFileContent); }; - listTaskIds = (boardName) => { - const getTaskDirPath = this.getTaskContainerPath(boardName); - const fileIds = this.storageModel.list(getTaskDirPath); + updateTask = (taskFileContent) => { + this.storeTask(taskFileContent); + this.chatModel.sendMessage("", taskFileContent); + }; + storeTask = (taskFileContent) => { + this.fileModel.addFileContent(taskFileContent); + const taskReferencePath = this.getTaskReferencePath( + taskFileContent.boardId, + taskFileContent.fileId + ); + console.log("storing", taskReferencePath); + this.storageModel.write(taskReferencePath, ""); + }; + listTaskIds = (boardId) => { + const taskContainerPath = this.getTaskContainerPath(boardId); + console.log("listing", taskContainerPath); + const fileIds = this.storageModel.list(taskContainerPath); return fileIds; }; - moveTask = (taskFileId, oldBoardId, newBoardId) => { - const sourcePath = this.getTaskPath(oldBoardId, taskFileId); - const destinationPath = this.getTaskPath(newBoardId, taskFileId); - this.storageModel.renameRecursively(sourcePath, destinationPath); + deleteTask = (boardId, taskId) => { + const taskFilePath = this.getTaskFilePath(taskId); + const taskReferencePath = this.getTaskReferencePath( + boardId, + taskId + ); + this.storageModel.removeRecursively(taskFilePath); + this.storageModel.removeRecursively(taskReferencePath); }; // init constructor(storageModel2, chatModel, fileModel) { @@ -758,6 +781,35 @@ this.chatModel = chatModel; this.storageModel = storageModel2; this.taskModel = new TaskModel(this.storageModel, chatModel, this); + this.taskModel.createBoard("Hello"); + const boards = this.taskModel.listBoardIds(); + console.log("boards", boards); + const boardId = boards[0]; + console.log("board id", this.taskModel.getBoardInfo(boardId)); + const newInfo = TaskModel.createBoardInfoFileContent( + boardId, + "renamed", + "coral" /* Coral */ + ); + this.taskModel.updateBoard(newInfo); + console.log("info", this.taskModel.getBoardInfo(boardId)); + this.taskModel.createTask(boardId, "New task"); + const tasks = this.taskModel.listTaskIds(boardId); + console.log("tasks", tasks); + const taskId = tasks[0]; + console.log("task id", taskId); + const newTaskContent = TaskModel.createTaskFileContent( + taskId, + "renamed", + boardId + ); + this.taskModel.updateTask(newTaskContent); + setTimeout(() => { + this.taskModel.deleteTask(boardId, taskId); + }, 2e4); + setTimeout(() => { + this.taskModel.deleteBoard(boardId); + }, 3e4); } // utility static generateFileContentId = (creationDate) => { @@ -2540,7 +2592,7 @@ const path = StorageModel.stringToPathComponents(pathString); const fileName = StorageModel.getFileName(path); const items = new ListState(); - const style = `text-indent: ${path.length * 2}rem`; + const style = `text-indent: ${path.length}rem`; function loadItems() { items.clear(); const directoryItems = storageViewModel2.storageModel.list(path); diff --git a/src/Model/Files/fileModel.ts b/src/Model/Files/fileModel.ts index 631354e0..b23c4233 100644 --- a/src/Model/Files/fileModel.ts +++ b/src/Model/Files/fileModel.ts @@ -138,25 +138,6 @@ export default class FileModel { this.storageModel = storageModel; this.taskModel = new TaskModel(this.storageModel, chatModel, this); - - // DEV - // this.taskModel.createBoard("Hello"); - // const boards = this.taskModel.listBoardIds(); - // console.log(boards); - - // const boardId = boards[0]; - - // const firstBoardInfo = this.taskModel.getBoardInfo(boardId); - // console.log(firstBoardInfo); - - // const newInfo = TaskModel.createBoardInfoFileContent( - // boardId, - // "renamed", - // Color.Coral - // ); - // this.taskModel.createOrUpdateBoard(newInfo); - - // setTimeout(() => this.taskModel.deleteBoard(boardId), 7000); } // utility diff --git a/src/Model/Files/taskModel.ts b/src/Model/Files/taskModel.ts index 776353fc..c6f2b199 100644 --- a/src/Model/Files/taskModel.ts +++ b/src/Model/Files/taskModel.ts @@ -25,6 +25,10 @@ export default class TaskModel { return [...this.fileModel.getFilePath(boardId)]; }; + getTaskFilePath = (taskId: string): string[] => { + return [...this.fileModel.getFilePath(taskId)]; + }; + getBoardContainerPath = (): string[] => { return [...this.getBasePath(), subDirectories.boards]; }; @@ -37,25 +41,17 @@ export default class TaskModel { return [...this.getBoardDirectoryPath(boardId), subDirectories.boardTasks]; }; - getTaskPath = (boardId: string, fileId: string): string[] => { + getTaskReferencePath = (boardId: string, fileId: string): string[] => { return [...this.getTaskContainerPath(boardId), fileId]; }; - getTaskContentPath = ( - boardId: string, - fileId: string, - versionId: string - ): string[] => { - return [...this.getTaskPath(boardId, fileId), versionId]; - }; - // handler handleFileContent = (fileContent: FileContent): void => { if ( checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true ) { - this.handleBoard(fileContent as BoardInfoVersion); + this.handleBoard(fileContent as BoardInfoFileContent); } else if ( checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true ) { @@ -63,35 +59,27 @@ export default class TaskModel { } }; - handleBoard = (boardInfoFileContent: BoardInfoVersion) => { - console.log("board", boardInfoFileContent); + handleBoard = (boardInfoFileContent: BoardInfoFileContent) => { + this.storeBoard(boardInfoFileContent); }; - handleTask = (taskFileContent: TaskFileContent) => {}; + handleTask = (taskFileContent: TaskFileContent) => { + this.storeTask(taskFileContent); + }; // boards createBoard = (name: string): void => { - const boardInfoFileContent: BoardInfoVersion = + const boardInfoFileContent: BoardInfoFileContent = TaskModel.createBoardInfoFileContent(v4(), name, Color.Standard); - this.createOrUpdateBoard(boardInfoFileContent); + this.updateBoard(boardInfoFileContent); }; - listBoardIds = (): string[] => { - const boardContainerPath: string[] = this.getBoardContainerPath(); - const boardNames: string[] = this.storageModel.list(boardContainerPath); - return boardNames; + updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => { + this.storeBoard(boardInfoFileContent); + this.chatModel.sendMessage("", boardInfoFileContent); }; - getBoardInfo = (fileId: string): BoardInfoVersion | null => { - const boardInfoFileContentOrNull: BoardInfoVersion | null = - this.fileModel.getLatestFileContent( - fileId, - BoardInfoFileContentReference - ); - return boardInfoFileContentOrNull; - }; - - createOrUpdateBoard = (boardInfoFileContent: BoardInfoVersion): void => { + storeBoard = (boardInfoFileContent: BoardInfoFileContent): void => { // store info this.fileModel.addFileContent(boardInfoFileContent); @@ -110,30 +98,65 @@ export default class TaskModel { this.storageModel.removeRecursively(boardDirectoryPath); }; + listBoardIds = (): string[] => { + const boardContainerPath: string[] = this.getBoardContainerPath(); + const boardNames: string[] = this.storageModel.list(boardContainerPath); + return boardNames; + }; + + getBoardInfo = (fileId: string): BoardInfoFileContent | null => { + const boardInfoFileContentOrNull: BoardInfoFileContent | null = + this.fileModel.getLatestFileContent( + fileId, + BoardInfoFileContentReference + ); + return boardInfoFileContentOrNull; + }; + //tasks createTask = (boardId: string, name: string): void => { const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent( v4(), - boardId, - name + name, + boardId ); - this.fileModel.addFileContent(taskFileContent); + this.updateTask(taskFileContent); }; - listTaskIds = (boardName: string): string[] => { - const getTaskDirPath: string[] = this.getTaskContainerPath(boardName); - const fileIds: string[] = this.storageModel.list(getTaskDirPath); + updateTask = (taskFileContent: TaskFileContent): void => { + this.storeTask(taskFileContent); + this.chatModel.sendMessage("", taskFileContent); + }; + + storeTask = (taskFileContent: TaskFileContent): void => { + // store info + this.fileModel.addFileContent(taskFileContent); + + // add to board + const taskReferencePath: string[] = this.getTaskReferencePath( + taskFileContent.boardId, + taskFileContent.fileId + ); + console.log("storing", taskReferencePath); + this.storageModel.write(taskReferencePath, ""); + }; + + listTaskIds = (boardId: string): string[] => { + const taskContainerPath: string[] = this.getTaskContainerPath(boardId); + console.log("listing", taskContainerPath); + const fileIds: string[] = this.storageModel.list(taskContainerPath); return fileIds; }; - moveTask = ( - taskFileId: string, - oldBoardId: string, - newBoardId: string - ): void => { - const sourcePath: string[] = this.getTaskPath(oldBoardId, taskFileId); - const destinationPath: string[] = this.getTaskPath(newBoardId, taskFileId); - this.storageModel.renameRecursively(sourcePath, destinationPath); + deleteTask = (boardId: string, taskId: string): void => { + const taskFilePath: string[] = this.getTaskFilePath(taskId); + const taskReferencePath: string[] = this.getTaskReferencePath( + boardId, + taskId + ); + + this.storageModel.removeRecursively(taskFilePath); + this.storageModel.removeRecursively(taskReferencePath); }; // init @@ -152,7 +175,7 @@ export default class TaskModel { fileId: string, name: string, color: Color - ): BoardInfoVersion => { + ): BoardInfoFileContent => { const fileContent: FileContent<"board-info"> = FileModel.createFileContent( fileId, "board-info" @@ -189,7 +212,7 @@ export const subDirectories = { }; // types -export interface BoardInfoVersion extends FileContent<"board-info"> { +export interface BoardInfoFileContent extends FileContent<"board-info"> { name: string; color: Color; } @@ -209,7 +232,7 @@ export interface TaskFileContent extends FileContent<"task"> { } // reference -export const BoardInfoFileContentReference: BoardInfoVersion = { +export const BoardInfoFileContentReference: BoardInfoFileContent = { dataVersion: DATA_VERSION, fileId: "string", diff --git a/src/Model/Global/storageModel.ts b/src/Model/Global/storageModel.ts index 71187f7d..1db59fac 100644 --- a/src/Model/Global/storageModel.ts +++ b/src/Model/Global/storageModel.ts @@ -3,7 +3,6 @@ import { DATA_VERSION, ValidObject, - checkMatchesObjectStructure, } from "../Utility/typeSafety"; import { localeCompare, parseValidObject, stringify } from "../Utility/utility"; diff --git a/src/View/Components/directoryItemList.tsx b/src/View/Components/directoryItemList.tsx index 31b86a23..623cc992 100644 --- a/src/View/Components/directoryItemList.tsx +++ b/src/View/Components/directoryItemList.tsx @@ -1,6 +1,8 @@ import * as React from "bloatless-react"; -import StorageModel, { PATH_COMPONENT_SEPARATOR } from "../../Model/Global/storageModel"; +import StorageModel, { + PATH_COMPONENT_SEPARATOR, +} from "../../Model/Global/storageModel"; import StorageViewModel from "../../ViewModel/storageViewModel"; @@ -18,7 +20,7 @@ export function DirectoryItemList( const fileName = StorageModel.getFileName(path); const items = new React.ListState(); - const style = `text-indent: ${path.length * 2}rem`; + const style = `text-indent: ${path.length}rem`; // methods function loadItems() { @@ -42,7 +44,7 @@ export function DirectoryItemList( if (!items.value.has(lastDeletedItemPath)) return; select(); - setTimeout(() => loadItems(), 50) + setTimeout(() => loadItems(), 50); }); // state