Add 'Start week on' setting (Monday default / Sunday) for daily and tasks calendars

This commit is contained in:
Yuri Karamian
2026-06-08 20:56:28 +02:00
parent 5defddb35c
commit 92e8422cb0
7 changed files with 35 additions and 9 deletions
+2
View File
@@ -215,6 +215,7 @@ export async function setNotebookIcon(
export async function setGeneralSettings(
compactNotes: boolean,
timeFormat: string,
weekStart: string,
gpuAcceleration: boolean,
autostart: boolean,
pdfPreview: boolean,
@@ -232,6 +233,7 @@ export async function setGeneralSettings(
return invoke("set_general_settings", {
compactNotes,
timeFormat,
weekStart,
gpuAcceleration,
autostart,
pdfPreview,
+5 -4
View File
@@ -64,14 +64,15 @@
let dailyDates = $state<Set<string>>(new Set());
const calMonthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const calDayNames = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
// 0 = Sunday, 1 = Monday (default). Day names + grid offset follow the setting.
const weekStartsOn = $derived($appConfig?.week_start === 'sunday' ? 0 : 1);
const DOW = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
const calDayNames = $derived([...DOW.slice(weekStartsOn), ...DOW.slice(0, weekStartsOn)]);
function calDays(): Array<{ day: number; date: string; current: boolean }> {
const first = new Date(calYear, calMonth, 1);
const lastDay = new Date(calYear, calMonth + 1, 0).getDate();
// Monday=0 offset
let startDow = first.getDay() - 1;
if (startDow < 0) startDow = 6;
const startDow = (first.getDay() - weekStartsOn + 7) % 7;
const cells: Array<{ day: number; date: string; current: boolean }> = [];
for (let i = 0; i < startDow; i++) cells.push({ day: 0, date: '', current: false });
for (let d = 1; d <= lastDay; d++) {
+12 -1
View File
@@ -460,6 +460,7 @@
let showNoteDates = $state($appConfig?.show_note_dates ?? true);
let restoreLastSession = $state($appConfig?.restore_last_session ?? false);
let timeFormat = $state($appConfig?.time_format ?? 'relative');
let weekStart = $state($appConfig?.week_start ?? 'monday');
let gpuAcceleration = $state($appConfig?.gpu_acceleration ?? true);
let autostart = $state($appConfig?.autostart ?? false);
@@ -517,6 +518,7 @@
$appConfig.show_note_dates = showNoteDates;
$appConfig.restore_last_session = restoreLastSession;
$appConfig.time_format = timeFormat;
$appConfig.week_start = weekStart;
$appConfig.gpu_acceleration = gpuAcceleration;
$appConfig.autostart = autostart;
$appConfig.pdf_preview = pdfPreview;
@@ -529,7 +531,7 @@
$appConfig.close_to_tray = closeToTray;
$appConfig.enable_wiki_links = enableWikiLinks;
}
setGeneralSettings(compactNotes, timeFormat, gpuAcceleration, autostart, pdfPreview, pdfHeight, titleMode, hideTitleInBody, showLineNumbers, defaultViewMode, showTrayIcon, closeToTray, enableWikiLinks, showNoteDates, restoreLastSession)
setGeneralSettings(compactNotes, timeFormat, weekStart, gpuAcceleration, autostart, pdfPreview, pdfHeight, titleMode, hideTitleInBody, showLineNumbers, defaultViewMode, showTrayIcon, closeToTray, enableWikiLinks, showNoteDates, restoreLastSession)
.catch((e) => console.error('Failed to save general settings:', e));
}
@@ -653,6 +655,7 @@
showNoteDates = $appConfig.show_note_dates ?? true;
restoreLastSession = $appConfig.restore_last_session ?? false;
timeFormat = $appConfig.time_format ?? 'relative';
weekStart = $appConfig.week_start ?? 'monday';
gpuAcceleration = $appConfig.gpu_acceleration ?? true;
autostart = $appConfig.autostart ?? false;
pdfPreview = $appConfig.pdf_preview ?? false;
@@ -790,6 +793,14 @@
</div>
</div>
<div class="settings-section">
<h3>Start week on</h3>
<div class="setting-options">
<button class="option-btn" class:active={weekStart === 'monday'} onclick={() => { weekStart = 'monday'; saveGeneralSettings(); }}>Monday</button>
<button class="option-btn" class:active={weekStart === 'sunday'} onclick={() => { weekStart = 'sunday'; saveGeneralSettings(); }}>Sunday</button>
</div>
</div>
{#if isMobile}
<div class="settings-section">
<h3>Vault</h3>
+6 -4
View File
@@ -3,7 +3,7 @@
import { listen } from '@tauri-apps/api/event';
import { getTasks } from '$lib/api';
import { debounce } from '$lib/utils/debounce';
import { tasksLayout } from '$lib/stores/app';
import { tasksLayout, appConfig } from '$lib/stores/app';
import { isAndroid } from '$lib/platform';
import type { TaskItem, FileEvent } from '$lib/types';
@@ -104,7 +104,10 @@
let selectedDate = $state(today);
const calMonthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const calDayNames = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
// 0 = Sunday, 1 = Monday (default). Day names + grid offset follow the setting.
const weekStartsOn = $derived($appConfig?.week_start === 'sunday' ? 0 : 1);
const DOW = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
const calDayNames = $derived([...DOW.slice(weekStartsOn), ...DOW.slice(0, weekStartsOn)]);
// Calendar tasks share the list's hide-completed filter (no sort).
const calBase = $derived(tasks.filter((t) => !hideCompleted || !t.completed));
@@ -133,8 +136,7 @@
);
function calDays() {
// Monday-first: shift so Mon=0 ... Sun=6
const firstWeekday = (new Date(calYear, calMonth, 1).getDay() + 6) % 7;
const firstWeekday = (new Date(calYear, calMonth, 1).getDay() - weekStartsOn + 7) % 7;
const lastDate = new Date(calYear, calMonth + 1, 0).getDate();
const cells: { day: number; date: string; current: boolean }[] = [];
for (let i = 0; i < firstWeekday; i++) cells.push({ day: 0, date: '', current: false });
+1
View File
@@ -58,6 +58,7 @@ export interface AppConfig {
compact_notes: boolean;
show_note_dates: boolean;
time_format: string;
week_start: string;
gpu_acceleration: boolean;
autostart: boolean;
pdf_preview: boolean;