fix: show all tasks in widget (#23) #24
2 changed files with 5 additions and 12 deletions
|
|
@ -4,7 +4,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
|
|||
import { db } from '../db/client';
|
||||
import { tasks, lists } from '../db/schema';
|
||||
import { eq, and, isNull, gte, lte, lt, asc, sql } from 'drizzle-orm';
|
||||
import { startOfDay, endOfDay, addWeeks } from 'date-fns';
|
||||
import { startOfDay } from 'date-fns';
|
||||
import { TaskListWidget } from '../widgets/TaskListWidget';
|
||||
|
||||
export const WIDGET_DATA_KEY = 'widget:tasks';
|
||||
|
|
@ -34,7 +34,6 @@ export async function syncWidgetData(): Promise<void> {
|
|||
try {
|
||||
const now = new Date();
|
||||
const todayStart = startOfDay(now);
|
||||
const twoWeeksEnd = endOfDay(addWeeks(now, 2));
|
||||
|
||||
const selectFields = {
|
||||
id: tasks.id,
|
||||
|
|
@ -48,7 +47,7 @@ export async function syncWidgetData(): Promise<void> {
|
|||
subtaskDoneCount: sql<number>`(SELECT COUNT(*) FROM tasks AS sub WHERE sub.parent_id = ${tasks.id} AND sub.completed = 1)`.as('subtask_done_count'),
|
||||
};
|
||||
|
||||
// Fetch tasks with due date in the next 2 weeks
|
||||
// Fetch all upcoming tasks (today and future)
|
||||
const upcomingTasks = await db
|
||||
.select(selectFields)
|
||||
.from(tasks)
|
||||
|
|
@ -57,8 +56,7 @@ export async function syncWidgetData(): Promise<void> {
|
|||
and(
|
||||
eq(tasks.completed, false),
|
||||
isNull(tasks.parentId),
|
||||
gte(tasks.dueDate, todayStart),
|
||||
lte(tasks.dueDate, twoWeeksEnd)
|
||||
gte(tasks.dueDate, todayStart)
|
||||
)
|
||||
)
|
||||
.orderBy(asc(tasks.dueDate));
|
||||
|
|
|
|||
|
|
@ -380,17 +380,14 @@ function SmallWidget({ tasks, isDark }: { tasks: WidgetTask[]; isDark: boolean }
|
|||
|
||||
function ListWidgetContent({
|
||||
tasks,
|
||||
maxItems,
|
||||
isDark,
|
||||
expandedTaskIds,
|
||||
}: {
|
||||
tasks: WidgetTask[];
|
||||
maxItems: number;
|
||||
isDark: boolean;
|
||||
expandedTaskIds: Set<string>;
|
||||
}) {
|
||||
const c = getColors(isDark);
|
||||
const displayTasks = tasks.slice(0, maxItems);
|
||||
|
||||
return (
|
||||
<FlexWidget
|
||||
|
|
@ -477,14 +474,14 @@ function ListWidgetContent({
|
|||
</FlexWidget>
|
||||
|
||||
{/* Task list */}
|
||||
{displayTasks.length > 0 ? (
|
||||
{tasks.length > 0 ? (
|
||||
<ListWidget
|
||||
style={{
|
||||
height: 'match_parent',
|
||||
width: 'match_parent',
|
||||
}}
|
||||
>
|
||||
{displayTasks.map((task) => (
|
||||
{tasks.map((task) => (
|
||||
<FlexWidget
|
||||
key={task.id}
|
||||
style={{
|
||||
|
|
@ -534,11 +531,9 @@ export function TaskListWidget(props: TaskListWidgetProps) {
|
|||
return <SmallWidget tasks={widgetTasks} isDark={isDark} />;
|
||||
}
|
||||
|
||||
const maxItems = widgetName === 'SimplListeLarge' ? 8 : 4;
|
||||
return (
|
||||
<ListWidgetContent
|
||||
tasks={widgetTasks}
|
||||
maxItems={maxItems}
|
||||
isDark={isDark}
|
||||
expandedTaskIds={expandedTaskIds}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue