mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-07-24 07:45:57 +02:00
Add 'Start week on' setting (Monday default / Sunday) for daily and tasks calendars
This commit is contained in:
@@ -1067,6 +1067,7 @@ pub fn set_general_settings(
|
||||
state: State<'_, AppState>,
|
||||
compact_notes: bool,
|
||||
time_format: String,
|
||||
week_start: String,
|
||||
gpu_acceleration: bool,
|
||||
autostart: bool,
|
||||
pdf_preview: bool,
|
||||
@@ -1086,6 +1087,7 @@ pub fn set_general_settings(
|
||||
config.show_note_dates = show_note_dates;
|
||||
config.restore_last_session = restore_last_session;
|
||||
config.time_format = time_format;
|
||||
config.week_start = week_start;
|
||||
config.gpu_acceleration = gpu_acceleration;
|
||||
config.autostart = autostart;
|
||||
config.pdf_preview = pdf_preview;
|
||||
|
||||
@@ -77,6 +77,8 @@ pub struct AppConfig {
|
||||
pub show_note_dates: bool,
|
||||
#[serde(default)]
|
||||
pub time_format: String,
|
||||
#[serde(default = "default_week_start")]
|
||||
pub week_start: String,
|
||||
#[serde(default)]
|
||||
pub gpu_acceleration: bool,
|
||||
#[serde(default)]
|
||||
@@ -172,6 +174,10 @@ fn default_title_mode() -> String {
|
||||
"input".to_string()
|
||||
}
|
||||
|
||||
fn default_week_start() -> String {
|
||||
"monday".to_string()
|
||||
}
|
||||
|
||||
fn default_max_versions() -> u32 {
|
||||
20
|
||||
}
|
||||
@@ -194,6 +200,7 @@ impl Default for AppConfig {
|
||||
compact_notes: false,
|
||||
show_note_dates: true,
|
||||
time_format: "relative".to_string(),
|
||||
week_start: "monday".to_string(),
|
||||
gpu_acceleration: true,
|
||||
autostart: false,
|
||||
pdf_preview: false,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user