Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/views/MonthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export function MonthView() {
const [monthTodos, setMonthTodos] = useState<Todo[]>([]);

const currentMonth = dayjs(selectedDate).startOf("month");
const calendarStart = currentMonth.startOf("week").add(1, "day");
const calendarEnd = currentMonth.endOf("month").endOf("week").add(1, "day");
const calendarStart = currentMonth.startOf("week");
const calendarEnd = currentMonth.endOf("month").endOf("week");

const loadMonthTodos = useCallback(async () => {
const start = calendarStart.format("YYYY-MM-DD");
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/WeekView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function WeekView() {
const { selectedDate, setSelectedDate, setViewMode } = useUiStore();
const [weekTodos, setWeekTodos] = useState<Todo[]>([]);

const weekStart = dayjs(selectedDate).startOf("week").add(1, "day");
const weekStart = dayjs(selectedDate).startOf("week");
const weekDates = Array.from({ length: 7 }, (_, i) =>
weekStart.add(i, "day")
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/YearView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function YearView() {
}, [loadYearTodos]);

// Build weeks grid
const startDate = yearStart.startOf("week").add(1, "day");
const startDate = yearStart.startOf("week");
const weeks: dayjs.Dayjs[][] = [];
let cursor = startDate;
while (cursor.isBefore(yearEnd.add(1, "week"))) {
Expand Down
19 changes: 14 additions & 5 deletions src/stores/todo-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export const useTodoStore = create<TodoState>((set, get) => ({
isLoading: false,

loadTodos: async (dueDate?: string) => {
if (pendingToggles.size > 0) {
await new Promise<void>((resolve) => {
const check = () => {
if (pendingToggles.size === 0) resolve();
else setTimeout(check, 10);
};
check();
});
}
Comment on lines +29 to +37
set({ isLoading: true });
try {
const todos = await fetchTodos(dueDate);
Expand All @@ -47,15 +56,15 @@ export const useTodoStore = create<TodoState>((set, get) => ({

toggleTodo: async (id: string) => {
if (pendingToggles.has(id)) return;
const todo = get().todos.find((t) => t.id === id);
if (!todo) return;
const completed = !todo.completed;
pendingToggles.add(id);
try {
await updateTodo(id, { completed });
const currentTodo = get().todos.find((t) => t.id === id);
if (!currentTodo) return;
const newCompleted = !currentTodo.completed;
await updateTodo(id, { completed: newCompleted });
set((state) => ({
todos: state.todos.map((t) =>
t.id === id ? { ...t, completed, updatedAt: new Date().toISOString() } : t
t.id === id ? { ...t, completed: newCompleted, updatedAt: new Date().toISOString() } : t
),
}));
} catch (error) {
Expand Down