implement creating and listing tasks

This commit is contained in:
marlon-erler
2024-07-24 13:31:28 +02:00
parent 5164e891f6
commit 14212da988
8 changed files with 277 additions and 171 deletions
+25 -2
View File
@@ -6,6 +6,8 @@ import BoardViewModel, {
import { BoardSettingsModal } from "../Modals/boardSettingsModal";
import { BoardViewToggleButton } from "../Components/boardViewToggleButton";
import { TaskSettingsModal } from "../Modals/taskSettingsModal";
import { TaskViewModelToEntry } from "../Components/taskEntry";
import { translations } from "../translations";
export function BoardPage(boardViewModel: BoardViewModel) {
@@ -16,12 +18,32 @@ export function BoardPage(boardViewModel: BoardViewModel) {
() => {
switch (boardViewModel.selectedPage.value) {
default: {
return <div></div>;
return (
<div
class="grid gap"
style="grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr))"
children:append={[
boardViewModel.taskViewModels,
TaskViewModelToEntry,
]}
></div>
);
}
}
}
);
const taskSettingsModal = React.createProxyState(
[boardViewModel.selectedTaskViewModel],
() => {
if (boardViewModel.selectedTaskViewModel.value == undefined) {
return <div></div>;
} else {
return TaskSettingsModal(boardViewModel.selectedTaskViewModel.value);
}
}
);
return (
<div class="pane">
<div class="toolbar">
@@ -72,7 +94,7 @@ export function BoardPage(boardViewModel: BoardViewModel) {
<button
class="ghost"
aria-label={translations.chatPage.task.createTaskButtonAudioLabel}
on:click={boardViewModel.showNewTaskModal}
on:click={boardViewModel.createTask}
>
<span class="icon">add</span>
</button>
@@ -81,6 +103,7 @@ export function BoardPage(boardViewModel: BoardViewModel) {
<div class="content" children:set={mainContent}></div>
{BoardSettingsModal(boardViewModel)}
<div children:set={taskSettingsModal}></div>
</div>
);
}
+2 -2
View File
@@ -2,8 +2,8 @@ import "./taskPage.css";
import * as React from "bloatless-react";
import { BoardInfoToEntry } from "../Components/boardEntry";
import { BoardPage } from "./boardPage";
import { BoardViewModelToEntry } from "../Components/boardEntry";
import TaskPageViewModel from "../../ViewModel/Pages/taskPageViewModel";
import { translations } from "../translations";
@@ -77,7 +77,7 @@ export function TaskPage(taskPageViewModel: TaskPageViewModel) {
style="grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr))"
children:append={[
taskPageViewModel.boardViewModels,
BoardInfoToEntry,
BoardViewModelToEntry,
]}
></div>
</div>
+1 -1
View File
@@ -23,7 +23,7 @@ export function BoardEntry(boardViewModel: BoardViewModel) {
return view;
}
export const BoardInfoToEntry: React.StateItemConverter<
export const BoardViewModelToEntry: React.StateItemConverter<
BoardViewModel
> = (boardViewModel: BoardViewModel) => {
return BoardEntry(boardViewModel);
+19
View File
@@ -0,0 +1,19 @@
import * as React from "bloatless-react";
import TaskViewModel from "../../ViewModel/Pages/taskViewModel";
export function TaskEntry(taskViewModel: TaskViewModel) {
const view = (
<button class="tile">
<b subscribe:innerText={taskViewModel.name}></b>
</button>
);
return view;
}
export const TaskViewModelToEntry: React.StateItemConverter<TaskViewModel> = (
taskViewModel: TaskViewModel
) => {
return TaskEntry(taskViewModel);
};
+26 -27
View File
@@ -4,79 +4,78 @@ import { DangerousActionButton } from "../Components/dangerousActionButton";
import TaskViewModel from "../../ViewModel/Pages/taskViewModel";
import { translations } from "../translations";
export function TaskSettingsModal(taskViewModal: TaskViewModel) {
export function TaskSettingsModal(taskViewModel: TaskViewModel) {
return (
<div class="modal" toggle:open={taskViewModal.isPresentingSettingsModal}>
<div class="modal" open>
<div>
<main>
<h2>{translations.chatPage.task.boardSettingsHeadline}</h2>
<div class="tile flex-no">
<label class="tile flex-no">
<span class="icon">label</span>
<div>
<span>{translations.chatPage.task.taskNameLabel}</span>
<input bind:value={taskViewModal.name}></input>
<input bind:value={taskViewModel.name}></input>
</div>
</div>
</label>
<div class="tile flex-no">
<label class="tile flex-no">
<span class="icon">description</span>
<div>
<span>{translations.chatPage.task.taskDescriptionLabel}</span>
<input bind:value={taskViewModal.description}></input>
<textarea rows="10" bind:value={taskViewModel.description}></textarea>
</div>
</div>
</label>
<hr></hr>
<div class="tile flex-no">
<label class="tile flex-no">
<span class="icon">category</span>
<div>
<span>{translations.chatPage.task.taskCategoryLabel}</span>
<input bind:value={taskViewModal.category}></input>
<input bind:value={taskViewModel.category}></input>
</div>
</div>
</label>
<div class="tile flex-no">
<label class="tile flex-no">
<span class="icon">clock_loader_40</span>
<div>
<span>{translations.chatPage.task.taskStatusLabel}</span>
<input bind:value={taskViewModal.status}></input>
<input bind:value={taskViewModel.status}></input>
</div>
</div>
</label>
<div class="tile flex-no">
<label class="tile flex-no">
<span class="icon">priority_high</span>
<div>
<span>{translations.chatPage.task.taskPriorityLabel}</span>
<input type="number" bind:value={taskViewModal.priority}></input>
<input type="number" bind:value={taskViewModel.priority}></input>
</div>
</div>
</label>
<hr></hr>
<div class="tile flex-no">
<label class="tile flex-no">
<span class="icon">calendar_month</span>
<div>
<span>{translations.chatPage.task.taskDateLabel}</span>
<input type="date" bind:value={taskViewModal.date}></input>
<input type="date" bind:value={taskViewModel.date}></input>
</div>
</div>
</label>
<div class="tile flex-no">
<label class="tile flex-no">
<span class="icon">schedule</span>
<div>
<span>{translations.chatPage.task.taskTimeLabel}</span>
<input type="time" bind:value={taskViewModal.time}></input>
<input type="time" bind:value={taskViewModel.time}></input>
</div>
</div>
</label>
</main>
<div class="flex-row">
<button class="flex-1" on:click={taskViewModal.hideSettings}>
<div class="flex-row width-100">
<button class="flex" on:click={taskViewModel.hideSettings}>
{translations.general.closeButton}
<span class="icon">close</span>
</button>
<button class="flex-1" on:click={taskViewModal.hideSettingsAndSave}>
<button class="flex primary" on:click={taskViewModel.hideSettingsAndSave}>
{translations.general.saveButton}
<span class="icon">save</span>
</button>
+64 -57
View File
@@ -23,18 +23,19 @@ export default class BoardViewModel {
name: React.State<string> = new React.State("");
color: React.State<Color> = new React.State<Color>(Color.Standard);
isSelected: React.State<boolean>;
isPresentingSettingsModal: React.State<boolean> = new React.State(false);
isPresentingFilterModal: React.State<boolean> = new React.State(false);
isPresentingNewTaskModal: React.State<boolean> = new React.State(false);
index: React.State<number> = new React.State(0);
taskViewModels: React.MapState<TaskViewModel> = new React.MapState();
selectedPage: React.State<BoardPageType> = new React.State<BoardPageType>(
BoardPageType.List
);
selectedTaskViewModel: React.State<TaskViewModel | undefined> =
new React.State<TaskViewModel | undefined>(undefined);
index: React.State<number> = new React.State(0);
taskViewModels: React.MapState<TaskViewModel> = new React.MapState();
isSelected: React.State<boolean>;
isPresentingSettingsModal: React.State<boolean> = new React.State(false);
isPresentingFilterModal: React.State<boolean> = new React.State(false);
// paths
getBasePath = (): string[] => {
@@ -45,6 +46,58 @@ export default class BoardViewModel {
return [...this.getBasePath(), BoardViewModelSubPaths.LastUsedView];
};
// settings
saveSettings = (): void => {
const newBoardInfoFileContent: BoardInfoFileContent =
BoardModel.createBoardInfoFileContent(
this.boardInfo.fileId,
this.name.value,
this.color.value
);
this.taskPageViewModel.updateBoard(newBoardInfoFileContent);
};
applyColor = (): void => {
this.taskPageViewModel.chatViewModel.setDisplayedColor(this.color.value);
};
deleteBoard = (): void => {
this.taskPageViewModel.deleteBoard(this.boardInfo);
this.close();
};
// tasks
createTask = (): void => {
const taskFileContent: TaskFileContent = this.boardModel.createTask(
this.boardInfo.fileId
);
const taskViewModel: TaskViewModel = new TaskViewModel(
this.boardModel,
this,
taskFileContent
);
this.selectTask(taskViewModel);
};
trackTask = (taskViewModel: TaskViewModel): void => {
this.taskViewModels.set(taskViewModel.task.fileId, taskViewModel);
};
// storage
storeLastUsedView = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedView: string = this.selectedPage.value;
this.storageModel.write(path, lastUsedView);
};
restoreLastUsedView = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedView: string | null = this.storageModel.read(path);
if (lastUsedView == null) return;
this.selectedPage.value = lastUsedView as BoardPageType;
};
// view
select = (): void => {
this.taskPageViewModel.selectBoard(this);
@@ -71,12 +124,12 @@ export default class BoardViewModel {
this.isPresentingFilterModal.value = false;
};
showNewTaskModal = (): void => {
this.isPresentingNewTaskModal.value = true;
selectTask = (selectedTask: TaskViewModel): void => {
this.selectedTaskViewModel.value = selectedTask;
};
hideNewTaskModal = (): void => {
this.isPresentingNewTaskModal.value = false;
closeTask = () => {
this.selectedTaskViewModel.value = undefined;
};
updateIndex = (): void => {
@@ -85,52 +138,6 @@ export default class BoardViewModel {
this.index.value = index;
};
// settings
saveSettings = (): void => {
const newBoardInfoFileContent: BoardInfoFileContent =
BoardModel.createBoardInfoFileContent(
this.boardInfo.fileId,
this.name.value,
this.color.value
);
this.taskPageViewModel.updateBoard(newBoardInfoFileContent);
};
applyColor = (): void => {
this.taskPageViewModel.chatViewModel.setDisplayedColor(this.color.value);
};
deleteBoard = (): void => {
this.taskPageViewModel.deleteBoard(this.boardInfo);
this.close();
};
// tasks
createTask = (): TaskViewModel => {
const taskFileContent: TaskFileContent = this.boardModel.createTask(this.boardInfo.fileId);
const taskViewModel: TaskViewModel = new TaskViewModel(this.boardModel, this, taskFileContent);
return taskViewModel;
}
trackTask = (taskViewModel: TaskViewModel): void => {
this.taskViewModels.set(taskViewModel.task.fileId, taskViewModel);
}
// storage
storeLastUsedView = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedView: string = this.selectedPage.value;
this.storageModel.write(path, lastUsedView);
};
restoreLastUsedView = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedView: string | null = this.storageModel.read(path);
if (lastUsedView == null) return;
this.selectedPage.value = lastUsedView as BoardPageType;
};
// load
loadListRelevantData = (): void => {
this.name.value = this.boardInfo.name;
+2 -4
View File
@@ -29,15 +29,13 @@ export default class TaskViewModel {
date: React.State<string> = new React.State("");
time: React.State<string> = new React.State("");
isPresentingSettingsModal: React.State<boolean> = new React.State(false);
// view
showSettings = (): void => {
this.isPresentingSettingsModal.value = true;
this.boardViewModel.selectTask(this);
};
hideSettings = (): void => {
this.isPresentingSettingsModal.value = false;
this.boardViewModel.closeTask();
};
hideSettingsAndSave = (): void => {