implement day selection

This commit is contained in:
marlon-erler
2024-07-26 03:38:46 +02:00
parent c95dc81870
commit d0131ce3f1
5 changed files with 43 additions and 10 deletions
+18 -4
View File
@@ -1609,6 +1609,7 @@
// state // state
selectedYear = new State(0); selectedYear = new State(0);
selectedMonth = new State(0); selectedMonth = new State(0);
selectedDate = new State(0);
monthGrid = new State(void 0); monthGrid = new State(void 0);
// view // view
getTaskMapState = (taskFileContent) => { getTaskMapState = (taskFileContent) => {
@@ -1638,6 +1639,7 @@
const today = /* @__PURE__ */ new Date(); const today = /* @__PURE__ */ new Date();
this.selectedYear.value = today.getFullYear(); this.selectedYear.value = today.getFullYear();
this.selectedMonth.value = today.getMonth() + 1; this.selectedMonth.value = today.getMonth() + 1;
this.selectedDate.value = today.getDate();
}; };
showPreviousMonth = () => { showPreviousMonth = () => {
this.selectedMonth.value -= 1; this.selectedMonth.value -= 1;
@@ -2495,7 +2497,9 @@
yearInputAudioLabel: "year", yearInputAudioLabel: "year",
monthInputAudioLabel: "month", monthInputAudioLabel: "month",
yearInputPlaceholder: "2000", yearInputPlaceholder: "2000",
monthInputPlaceholder: "01" monthInputPlaceholder: "01",
///
searchEventsHeadline: "Search Events"
} }
} }
}; };
@@ -2506,7 +2510,7 @@
var translations = allTranslations[language] || allTranslations.en; var translations = allTranslations[language] || allTranslations.en;
// src/View/Components/monthGrid.tsx // src/View/Components/monthGrid.tsx
function MonthGrid2(monthGrid) { function MonthGrid2(monthGrid, selectedDate) {
const dayLabels = []; const dayLabels = [];
let currentWeekday = monthGrid.firstDayOfWeek; let currentWeekday = monthGrid.firstDayOfWeek;
while (dayLabels.length < 7) { while (dayLabels.length < 7) {
@@ -2525,7 +2529,14 @@
}; };
return /* @__PURE__ */ createElement("div", { class: "month-grid-wrapper" }, /* @__PURE__ */ createElement("div", { class: "day-labels" }, ...dayLabels), /* @__PURE__ */ createElement("div", { class: "month-grid" }, ...offsetElements, ...Object.entries(monthGrid.days).map((entry) => { return /* @__PURE__ */ createElement("div", { class: "month-grid-wrapper" }, /* @__PURE__ */ createElement("div", { class: "day-labels" }, ...dayLabels), /* @__PURE__ */ createElement("div", { class: "month-grid" }, ...offsetElements, ...Object.entries(monthGrid.days).map((entry) => {
const [date, mapState] = entry; const [date, mapState] = entry;
return /* @__PURE__ */ createElement("button", { class: "tile" }, /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("b", null, date), /* @__PURE__ */ createElement( const isSelected = createProxyState(
[selectedDate],
() => selectedDate.value == parseInt(date)
);
function select() {
selectedDate.value = parseInt(date);
}
return /* @__PURE__ */ createElement("button", { class: "tile", "on:click": select, "toggle:selected": isSelected }, /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("b", null, date), /* @__PURE__ */ createElement(
"div", "div",
{ {
class: "flex-column gap clip", class: "flex-column gap clip",
@@ -2544,7 +2555,10 @@
if (calendarPageViewModel.monthGrid.value == void 0) { if (calendarPageViewModel.monthGrid.value == void 0) {
return /* @__PURE__ */ createElement("div", null); return /* @__PURE__ */ createElement("div", null);
} else { } else {
return MonthGrid2(calendarPageViewModel.monthGrid.value); return MonthGrid2(
calendarPageViewModel.monthGrid.value,
calendarPageViewModel.selectedDate
);
} }
} }
); );
+4 -3
View File
@@ -4,8 +4,6 @@ import * as React from "bloatless-react";
import CalendarPageViewModel from "../../ViewModel/Pages/calendarPageViewModel"; import CalendarPageViewModel from "../../ViewModel/Pages/calendarPageViewModel";
import { MonthGrid } from "../Components/monthGrid"; import { MonthGrid } from "../Components/monthGrid";
import { TaskViewModelToEntry } from "../Components/taskEntry";
import { createPropertyValueIndexState } from "../Components/propertyValueList";
import { translations } from "../translations"; import { translations } from "../translations";
export function CalendarPage(calendarPageViewModel: CalendarPageViewModel) { export function CalendarPage(calendarPageViewModel: CalendarPageViewModel) {
@@ -17,7 +15,10 @@ export function CalendarPage(calendarPageViewModel: CalendarPageViewModel) {
if (calendarPageViewModel.monthGrid.value == undefined) { if (calendarPageViewModel.monthGrid.value == undefined) {
return <div></div>; return <div></div>;
} else { } else {
return MonthGrid(calendarPageViewModel.monthGrid.value); return MonthGrid(
calendarPageViewModel.monthGrid.value,
calendarPageViewModel.selectedDate
);
} }
} }
); );
+14 -2
View File
@@ -5,7 +5,10 @@ import { MonthGrid } from "../../Model/Files/calendarModel";
import TaskViewModel from "../../ViewModel/Pages/taskViewModel"; import TaskViewModel from "../../ViewModel/Pages/taskViewModel";
import { translations } from "../translations"; import { translations } from "../translations";
export function MonthGrid<T>(monthGrid: MonthGrid<React.MapState<T>>) { export function MonthGrid<T>(
monthGrid: MonthGrid<React.MapState<T>>,
selectedDate: React.State<number>
) {
const dayLabels: HTMLElement[] = []; const dayLabels: HTMLElement[] = [];
let currentWeekday = monthGrid.firstDayOfWeek; let currentWeekday = monthGrid.firstDayOfWeek;
while (dayLabels.length < 7) { while (dayLabels.length < 7) {
@@ -37,8 +40,17 @@ export function MonthGrid<T>(monthGrid: MonthGrid<React.MapState<T>>) {
{...Object.entries(monthGrid.days).map((entry) => { {...Object.entries(monthGrid.days).map((entry) => {
const [date, mapState] = entry; const [date, mapState] = entry;
const isSelected = React.createProxyState(
[selectedDate],
() => selectedDate.value == parseInt(date)
);
function select() {
selectedDate.value = parseInt(date);
}
return ( return (
<button class="tile"> <button class="tile" on:click={select} toggle:selected={isSelected}>
<div> <div>
<b>{date}</b> <b>{date}</b>
<div <div
+4
View File
@@ -197,6 +197,10 @@ const englishTranslations = {
yearInputPlaceholder: "2000", yearInputPlaceholder: "2000",
monthInputPlaceholder: "01", monthInputPlaceholder: "01",
///
searchEventsHeadline: "Search Events"
}, },
}, },
}; };
+3 -1
View File
@@ -30,6 +30,7 @@ export default class CalendarPageViewModel {
// state // state
selectedYear: React.State<number> = new React.State(0); selectedYear: React.State<number> = new React.State(0);
selectedMonth: React.State<number> = new React.State(0); selectedMonth: React.State<number> = new React.State(0);
selectedDate: React.State<number> = new React.State(0);
monthGrid: React.State<MonthGrid<React.MapState<TaskViewModel>> | undefined> = monthGrid: React.State<MonthGrid<React.MapState<TaskViewModel>> | undefined> =
new React.State<any>(undefined); new React.State<any>(undefined);
@@ -70,6 +71,7 @@ export default class CalendarPageViewModel {
const today: Date = new Date(); const today: Date = new Date();
this.selectedYear.value = today.getFullYear(); this.selectedYear.value = today.getFullYear();
this.selectedMonth.value = today.getMonth() + 1; this.selectedMonth.value = today.getMonth() + 1;
this.selectedDate.value = today.getDate();
}; };
showPreviousMonth = (): void => { showPreviousMonth = (): void => {
@@ -119,7 +121,7 @@ export default class CalendarPageViewModel {
public coreViewModel: CoreViewModel, public coreViewModel: CoreViewModel,
storageModel: StorageModel, storageModel: StorageModel,
calendarModel: CalendarModel, calendarModel: CalendarModel,
boardAndTasksModel: BoardsAndTasksModel boardAndTasksModel: BoardsAndTasksModel,
) { ) {
this.storageModel = storageModel; this.storageModel = storageModel;
this.calendarModel = calendarModel; this.calendarModel = calendarModel;