Dev merge main #9
@@ -8,17 +8,21 @@ import { useSubtasks } from '@/hooks/useSubtasks';
|
|||||||
import { useTaskModals } from '@/hooks/useTaskModals';
|
import { useTaskModals } from '@/hooks/useTaskModals';
|
||||||
import { useSettings } from '@/theme';
|
import { useSettings } from '@/theme';
|
||||||
import { useCategories } from '@/hooks/useDatabase';
|
import { useCategories } from '@/hooks/useDatabase';
|
||||||
import { confirmAndToggleTaskComplete } from '@/utils/taskActions';
|
import { useICalImport } from '@/hooks/useICalImport';
|
||||||
|
import { confirmAndToggleTaskComplete, toggleSubtaskComplete } from '@/utils/taskActions';
|
||||||
import { QuickAddBar } from '@/components/QuickAddBar';
|
import { QuickAddBar } from '@/components/QuickAddBar';
|
||||||
import { OptionPickerModal } from '@/components/OptionPickerModal';
|
import { OptionPickerModal } from '@/components/OptionPickerModal';
|
||||||
|
import { TaskItem } from '@/components/TaskItem';
|
||||||
|
import { SubtaskItem } from '@/components/SubtaskItem';
|
||||||
import Task from '@/models/Task';
|
import Task from '@/models/Task';
|
||||||
import { format, addMonths, addDays, startOfMonth, isSameDay, isSameMonth, isToday } from 'date-fns';
|
import { format, addMonths, addDays, startOfMonth, isSameDay, isSameMonth, isToday } from 'date-fns';
|
||||||
import Svg, { Path, Circle } from 'react-native-svg';
|
import Svg, { Path } from 'react-native-svg';
|
||||||
import { desaturate } from '@/theme';
|
|
||||||
import type { ThemeColors } from '@/theme';
|
import type { ThemeColors } from '@/theme';
|
||||||
|
import type { TaskData, SubtaskData } from '@/types';
|
||||||
|
|
||||||
const WIDTH = Dimensions.get('window').width;
|
const WIDTH = Dimensions.get('window').width;
|
||||||
const GERMAN_WEEKDAYS = ['mo', 'di', 'mi', 'do', 'fr', 'sa', 'so'];
|
const GERMAN_WEEKDAYS = ['mo', 'di', 'mi', 'do', 'fr', 'sa', 'so'];
|
||||||
|
const PRIORITY_RANK: Record<string, number> = { none: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
||||||
const MONTH_NAMES = [
|
const MONTH_NAMES = [
|
||||||
'January', 'February', 'March', 'April', 'May', 'June',
|
'January', 'February', 'March', 'April', 'May', 'June',
|
||||||
'July', 'August', 'September', 'October', 'November', 'December',
|
'July', 'August', 'September', 'October', 'November', 'December',
|
||||||
@@ -26,9 +30,16 @@ const MONTH_NAMES = [
|
|||||||
|
|
||||||
export default function CalendarScreen() {
|
export default function CalendarScreen() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { theme } = useSettings();
|
const { theme, sortBy } = useSettings();
|
||||||
const styles = React.useMemo(() => createStyles(theme), [theme]);
|
const styles = React.useMemo(() => createStyles(theme), [theme]);
|
||||||
const categories = useCategories();
|
const categories = useCategories();
|
||||||
|
const categoryColors = useMemo(() => {
|
||||||
|
const map = new Map<string, string>();
|
||||||
|
for (const c of categories) {
|
||||||
|
map.set(c.id, c.color);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, [categories]);
|
||||||
const { modals, openTaskEdit } = useTaskModals();
|
const { modals, openTaskEdit } = useTaskModals();
|
||||||
|
|
||||||
const [visibleMonth, setVisibleMonth] = useState(() => new Date());
|
const [visibleMonth, setVisibleMonth] = useState(() => new Date());
|
||||||
@@ -55,6 +66,25 @@ export default function CalendarScreen() {
|
|||||||
const monthTasks = useTasksInMonth(visibleMonth);
|
const monthTasks = useTasksInMonth(visibleMonth);
|
||||||
const refreshMonthTasks = monthTasks.refresh;
|
const refreshMonthTasks = monthTasks.refresh;
|
||||||
|
|
||||||
|
const sortedDayTasks = useMemo(() => {
|
||||||
|
const sorted = [...selectedDayTasks];
|
||||||
|
switch (sortBy) {
|
||||||
|
case 'date':
|
||||||
|
sorted.sort((a, b) => (a.dueDate || Number.MAX_SAFE_INTEGER) - (b.dueDate || Number.MAX_SAFE_INTEGER));
|
||||||
|
break;
|
||||||
|
case 'priority':
|
||||||
|
sorted.sort((a, b) => PRIORITY_RANK[b.priority] - PRIORITY_RANK[a.priority]);
|
||||||
|
break;
|
||||||
|
case 'alpha':
|
||||||
|
sorted.sort((a, b) => a.title.localeCompare(b.title));
|
||||||
|
break;
|
||||||
|
case 'created':
|
||||||
|
sorted.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return sorted;
|
||||||
|
}, [selectedDayTasks, sortBy]);
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
refreshDayTasks();
|
refreshDayTasks();
|
||||||
@@ -165,6 +195,27 @@ export default function CalendarScreen() {
|
|||||||
});
|
});
|
||||||
}, [refreshDayTasks, refreshMonthTasks, refreshSubtasks]);
|
}, [refreshDayTasks, refreshMonthTasks, refreshSubtasks]);
|
||||||
|
|
||||||
|
const [expandedTasks, setExpandedTasks] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
|
const toggleExpand = useCallback((taskId: string) => {
|
||||||
|
setExpandedTasks((prev) => {
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (next.has(taskId)) {
|
||||||
|
next.delete(taskId);
|
||||||
|
} else {
|
||||||
|
next.add(taskId);
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleSubtaskToggle = useCallback(async (subtaskId: string) => {
|
||||||
|
await toggleSubtaskComplete(subtaskId);
|
||||||
|
refreshDayTasks();
|
||||||
|
refreshMonthTasks();
|
||||||
|
refreshSubtasks();
|
||||||
|
}, [refreshDayTasks, refreshMonthTasks, refreshSubtasks]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={[styles.container, { backgroundColor: theme.background }]}>
|
<SafeAreaView style={[styles.container, { backgroundColor: theme.background }]}>
|
||||||
<Header title="Calendar" showLogo={false} />
|
<Header title="Calendar" showLogo={false} />
|
||||||
@@ -244,78 +295,41 @@ export default function CalendarScreen() {
|
|||||||
|
|
||||||
<View style={styles.panelHeader}>
|
<View style={styles.panelHeader}>
|
||||||
<Text style={[styles.panelDate, { color: theme.text }]}>{format(selectedDate, 'EEEE, MMMM d')}</Text>
|
<Text style={[styles.panelDate, { color: theme.text }]}>{format(selectedDate, 'EEEE, MMMM d')}</Text>
|
||||||
{selectedDayTasks.length > 0 && (
|
{sortedDayTasks.length > 0 && (
|
||||||
<Text style={[styles.panelCount, { color: theme.textFaint }]}>
|
<Text style={[styles.panelCount, { color: theme.textFaint }]}>
|
||||||
{selectedDayTasks.length} event{selectedDayTasks.length === 1 ? '' : 's'}
|
{sortedDayTasks.length} event{sortedDayTasks.length === 1 ? '' : 's'}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{selectedDayTasks.length === 0 ? (
|
{sortedDayTasks.length === 0 ? (
|
||||||
<View style={styles.emptyState}>
|
<View style={styles.emptyState}>
|
||||||
<Text style={[styles.emptyText, { color: theme.textSecondary }]}>No events on this day</Text>
|
<Text style={[styles.emptyText, { color: theme.textSecondary }]}>No events on this day</Text>
|
||||||
<Text style={[styles.emptySubtext, { color: theme.textMuted }]}>Tap a date or use the bar below</Text>
|
<Text style={[styles.emptySubtext, { color: theme.textMuted }]}>Tap a date or use the bar below</Text>
|
||||||
</View>
|
</View>
|
||||||
) : (
|
) : (
|
||||||
selectedDayTasks.map((task) => (
|
sortedDayTasks.map((task) => {
|
||||||
<View key={task.id} style={[styles.eventCard, { backgroundColor: theme.card, borderColor: theme.border }]}>
|
const isExpanded = expandedTasks.has(task.id);
|
||||||
<View style={styles.eventRow}>
|
const itemSubtasks = subtasksByTask.get(task.id) ?? [];
|
||||||
<TouchableOpacity
|
return (
|
||||||
style={styles.checkCircle}
|
<View key={task.id} style={styles.eventCard}>
|
||||||
onPress={() => handleToggleComplete(task.id)}
|
<CalendarTaskRow
|
||||||
activeOpacity={0.7}
|
task={task}
|
||||||
>
|
expanded={isExpanded}
|
||||||
<Svg width={30} height={30} viewBox="0 0 24 24">
|
subtasks={itemSubtasks}
|
||||||
{task.completed ? (
|
categoryColor={categoryColors.get(task.categoryId)}
|
||||||
<>
|
onToggle={() => handleToggleComplete(task.id)}
|
||||||
<Circle cx={12} cy={12} r={10} fill={theme.accent} />
|
onPress={(id) =>
|
||||||
<Path d="M7 12l3 3 7-7" stroke="#FFFFFF" strokeWidth={2.5} strokeLinecap="round" strokeLinejoin="round" fill="none" />
|
expandedTasks.has(id)
|
||||||
</>
|
? router.push({ pathname: '/task-detail', params: { id } })
|
||||||
) : (
|
: toggleExpand(id)
|
||||||
<Circle cx={12} cy={12} r={10} stroke={theme.textSecondary} strokeWidth={2.5} fill="none" />
|
}
|
||||||
)}
|
onMenuOpen={(id) => openTaskEdit(id)}
|
||||||
</Svg>
|
onSubtaskToggle={handleSubtaskToggle}
|
||||||
</TouchableOpacity>
|
/>
|
||||||
|
|
||||||
<TouchableOpacity
|
|
||||||
style={styles.eventTitleTouch}
|
|
||||||
onPress={() => router.push({ pathname: '/task-detail', params: { id: task.id } })}
|
|
||||||
activeOpacity={0.7}
|
|
||||||
>
|
|
||||||
<Text
|
|
||||||
style={[styles.eventTitle, { color: theme.text }, task.completed && styles.eventCompleted]}
|
|
||||||
numberOfLines={1}
|
|
||||||
>
|
|
||||||
{task.title}
|
|
||||||
</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
<TouchableOpacity style={styles.menuButton} onPress={() => openTaskEdit(task.id)} activeOpacity={0.7} accessibilityRole="button" accessibilityLabel={`Edit ${task.title}`}>
|
|
||||||
<Svg width={20} height={20} viewBox="0 0 24 24">
|
|
||||||
<Path d="M9 6l6 6-6 6" stroke={theme.textSecondary} strokeWidth={2.5} strokeLinecap="round" strokeLinejoin="round" fill="none" />
|
|
||||||
</Svg>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
</View>
|
||||||
|
);
|
||||||
{(subtasksByTask.get(task.id) ?? []).length > 0 && (
|
})
|
||||||
<View style={styles.bullets}>
|
|
||||||
{(subtasksByTask.get(task.id) ?? []).map((sub) => (
|
|
||||||
<View key={sub.id} style={styles.bulletRow}>
|
|
||||||
<Svg width={5} height={5} viewBox="0 0 6 6" style={styles.bulletDot as any}>
|
|
||||||
<Circle cx={3} cy={3} r={3} fill={theme.textMuted} />
|
|
||||||
</Svg>
|
|
||||||
<Text
|
|
||||||
style={[styles.bulletText, { color: theme.textFaint }, sub.completed && styles.bulletCompleted]}
|
|
||||||
numberOfLines={1}
|
|
||||||
>
|
|
||||||
{sub.title}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
))}
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
))
|
|
||||||
)}
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
@@ -351,6 +365,60 @@ function byDayOf(byDay: Record<number, Task[]>, day: Date): Task[] {
|
|||||||
return byDay[day.getDate()] ?? [];
|
return byDay[day.getDate()] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CalendarTaskRowProps {
|
||||||
|
task: Task;
|
||||||
|
expanded: boolean;
|
||||||
|
subtasks: SubtaskData[];
|
||||||
|
categoryColor?: string;
|
||||||
|
onToggle: (taskId: string) => void | Promise<void>;
|
||||||
|
onPress: (taskId: string) => void;
|
||||||
|
onMenuOpen: (taskId: string) => void;
|
||||||
|
onSubtaskToggle: (subtaskId: string) => void | Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CalendarTaskRow = React.memo(function CalendarTaskRow({
|
||||||
|
task,
|
||||||
|
expanded,
|
||||||
|
subtasks,
|
||||||
|
categoryColor,
|
||||||
|
onToggle,
|
||||||
|
onPress,
|
||||||
|
onMenuOpen,
|
||||||
|
onSubtaskToggle,
|
||||||
|
}: CalendarTaskRowProps) {
|
||||||
|
const { theme } = useSettings();
|
||||||
|
const styles = React.useMemo(() => createStyles(theme), [theme]);
|
||||||
|
const sortedSubtasks = useMemo(
|
||||||
|
() => subtasks.slice().sort((a, b) => a.order - b.order),
|
||||||
|
[subtasks]
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<TaskItem
|
||||||
|
task={task as unknown as TaskData}
|
||||||
|
onToggle={() => onToggle(task.id)}
|
||||||
|
onPress={() => onPress(task.id)}
|
||||||
|
onMenuOpen={() => onMenuOpen(task.id)}
|
||||||
|
expanded={expanded}
|
||||||
|
categoryColor={categoryColor}
|
||||||
|
/>
|
||||||
|
{expanded && sortedSubtasks.length > 0 && (
|
||||||
|
<View style={styles.subtaskList}>
|
||||||
|
{sortedSubtasks.map((sub) => (
|
||||||
|
<SubtaskItem
|
||||||
|
key={sub.id}
|
||||||
|
subtask={sub}
|
||||||
|
depth={1}
|
||||||
|
categoryColor={categoryColor}
|
||||||
|
onToggle={() => onSubtaskToggle(sub.id)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
function cellTitle(tasks: Task[]): string | null {
|
function cellTitle(tasks: Task[]): string | null {
|
||||||
if (tasks.length === 0) return null;
|
if (tasks.length === 0) return null;
|
||||||
if (tasks.length === 1) return tasks[0].title;
|
if (tasks.length === 1) return tasks[0].title;
|
||||||
@@ -359,8 +427,7 @@ function cellTitle(tasks: Task[]): string | null {
|
|||||||
|
|
||||||
function cellColor(tasks: Task[], categories: { id: string; color: string }[], theme: ThemeColors): string {
|
function cellColor(tasks: Task[], categories: { id: string; color: string }[], theme: ThemeColors): string {
|
||||||
if (tasks.length === 0) return theme.textMuted;
|
if (tasks.length === 0) return theme.textMuted;
|
||||||
const cat = categories.find((c) => c.id === tasks[0].categoryId);
|
return theme.accent;
|
||||||
return cat ? desaturate(cat.color, 0.3) : theme.textMuted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DayCellProps {
|
interface DayCellProps {
|
||||||
@@ -545,55 +612,10 @@ const createStyles = (theme: ThemeColors) => StyleSheet.create({
|
|||||||
eventCard: {
|
eventCard: {
|
||||||
marginHorizontal: 16,
|
marginHorizontal: 16,
|
||||||
marginTop: 6,
|
marginTop: 6,
|
||||||
borderRadius: 16,
|
|
||||||
borderWidth: 1,
|
|
||||||
paddingHorizontal: 14,
|
|
||||||
paddingVertical: 12,
|
|
||||||
},
|
},
|
||||||
eventRow: {
|
subtaskList: {
|
||||||
flexDirection: 'row',
|
paddingLeft: 8,
|
||||||
alignItems: 'center',
|
paddingRight: 4,
|
||||||
},
|
paddingTop: 4,
|
||||||
checkCircle: {
|
|
||||||
width: 30,
|
|
||||||
marginRight: 12,
|
|
||||||
},
|
|
||||||
eventTitleTouch: {
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
eventTitle: {
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: '500',
|
|
||||||
},
|
|
||||||
eventCompleted: {
|
|
||||||
textDecorationLine: 'line-through',
|
|
||||||
color: theme.textMuted,
|
|
||||||
},
|
|
||||||
menuButton: {
|
|
||||||
padding: 4,
|
|
||||||
marginLeft: 6,
|
|
||||||
},
|
|
||||||
bullets: {
|
|
||||||
marginTop: 8,
|
|
||||||
paddingTop: 8,
|
|
||||||
borderTopWidth: 1,
|
|
||||||
borderTopColor: 'rgba(255,255,255,0.06)',
|
|
||||||
gap: 6,
|
|
||||||
},
|
|
||||||
bulletRow: {
|
|
||||||
flexDirection: 'row',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: 8,
|
|
||||||
},
|
|
||||||
bulletDot: {
|
|
||||||
marginLeft: 8,
|
|
||||||
},
|
|
||||||
bulletText: {
|
|
||||||
flex: 1,
|
|
||||||
fontSize: 13,
|
|
||||||
},
|
|
||||||
bulletCompleted: {
|
|
||||||
textDecorationLine: 'line-through',
|
|
||||||
color: theme.textMuted,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -15,6 +15,8 @@ import { useCategories } from '@/hooks/useDatabase';
|
|||||||
import { getAuthUser, getAuthToken } from '@/services/auth';
|
import { getAuthUser, getAuthToken } from '@/services/auth';
|
||||||
import { checkForUpdates, getCurrentAppVersion } from '@/services/updates';
|
import { checkForUpdates, getCurrentAppVersion } from '@/services/updates';
|
||||||
import { getLastSyncTime } from '@/database/sync';
|
import { getLastSyncTime } from '@/database/sync';
|
||||||
|
import { rescheduleAllReminders } from '@/services/notifications';
|
||||||
|
import { collections } from '@/database';
|
||||||
import Category from '@/models/Category';
|
import Category from '@/models/Category';
|
||||||
import Svg, { Path } from 'react-native-svg';
|
import Svg, { Path } from 'react-native-svg';
|
||||||
import ColorWheel from '@/components/ColorWheel';
|
import ColorWheel from '@/components/ColorWheel';
|
||||||
@@ -22,9 +24,10 @@ import { getLastVisitedTab, tabHref } from '@/utils/tabHistory';
|
|||||||
|
|
||||||
export default function SettingsScreen() {
|
export default function SettingsScreen() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { theme, notifications, setNotifications, defaultCategoryId, setDefaultCategoryId, sortBy, setSortBy, reminderPreference, setReminderPreference, apiUrl, accentColor, setAccentColor, todoAheadDays, setTodoAheadDays, showCompleted, setShowCompleted } = useSettings();
|
const { theme, notifications, setNotifications, defaultCategoryId, setDefaultCategoryId, sortBy, setSortBy, reminderPreference, setReminderPreference, tagReminderPreferences, setTagReminderPreferences, apiUrl, accentColor, setAccentColor, todoAheadDays, setTodoAheadDays, showCompleted, setShowCompleted, deleteBySwipe, setDeleteBySwipe } = useSettings();
|
||||||
const categories = useCategories();
|
const categories = useCategories();
|
||||||
const [picker, setPicker] = useState<null | 'category' | 'sort' | 'reminder' | 'todoAhead'>(null);
|
const [picker, setPicker] = useState<null | 'category' | 'sort' | 'reminder' | 'todoAhead'>(null);
|
||||||
|
const [reminderTagPicker, setReminderTagPicker] = useState<Category | null>(null);
|
||||||
const [editingCategory, setEditingCategory] = useState<Category | null | 'new'>(null);
|
const [editingCategory, setEditingCategory] = useState<Category | null | 'new'>(null);
|
||||||
const [syncVisible, setSyncVisible] = useState(false);
|
const [syncVisible, setSyncVisible] = useState(false);
|
||||||
const [friendsVisible, setFriendsVisible] = useState(false);
|
const [friendsVisible, setFriendsVisible] = useState(false);
|
||||||
@@ -95,6 +98,14 @@ export default function SettingsScreen() {
|
|||||||
const defaultCategoryLabel = defaultCategory?.name ?? 'None';
|
const defaultCategoryLabel = defaultCategory?.name ?? 'None';
|
||||||
const reminderLabel = REMINDER_OPTIONS.find((o) => o.value === reminderPreference)?.label ?? 'No reminder';
|
const reminderLabel = REMINDER_OPTIONS.find((o) => o.value === reminderPreference)?.label ?? 'No reminder';
|
||||||
|
|
||||||
|
const tagReminderLabel = (categoryId: string) => {
|
||||||
|
const selected = tagReminderPreferences[categoryId] ?? [];
|
||||||
|
if (selected.length === 0) return `Default (${reminderLabel})`;
|
||||||
|
return selected
|
||||||
|
.map((v) => REMINDER_OPTIONS.find((o) => o.value === v)?.label ?? v)
|
||||||
|
.join(', ');
|
||||||
|
};
|
||||||
|
|
||||||
const openCustomAccent = () => {
|
const openCustomAccent = () => {
|
||||||
setDraftAccent(accentColor);
|
setDraftAccent(accentColor);
|
||||||
setCustomAccentVisible(true);
|
setCustomAccentVisible(true);
|
||||||
@@ -108,6 +119,20 @@ export default function SettingsScreen() {
|
|||||||
setReminderPreference((Array.isArray(value) ? value[0] : value) as typeof reminderPreference);
|
setReminderPreference((Array.isArray(value) ? value[0] : value) as typeof reminderPreference);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleTagReminderPreference = async (categoryId: string, value: string | string[]) => {
|
||||||
|
const selected = (Array.isArray(value) ? value : [value]).filter(
|
||||||
|
(v): v is typeof reminderPreference => v !== 'none'
|
||||||
|
);
|
||||||
|
setTagReminderPreferences({ ...tagReminderPreferences, [categoryId]: selected });
|
||||||
|
if (!notifications) return;
|
||||||
|
try {
|
||||||
|
const tasks = await collections.tasks.query().fetch();
|
||||||
|
await rescheduleAllReminders(tasks, notifications, reminderPreference);
|
||||||
|
} catch {
|
||||||
|
// ignore reschedule failures
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleTodoAheadDays = (value: string | string[]) => {
|
const handleTodoAheadDays = (value: string | string[]) => {
|
||||||
setTodoAheadDays(parseInt(Array.isArray(value) ? value[0] : value, 10));
|
setTodoAheadDays(parseInt(Array.isArray(value) ? value[0] : value, 10));
|
||||||
};
|
};
|
||||||
@@ -163,6 +188,18 @@ export default function SettingsScreen() {
|
|||||||
onPress={() => notifications && setPicker('reminder')}
|
onPress={() => notifications && setPicker('reminder')}
|
||||||
showChevron
|
showChevron
|
||||||
/>
|
/>
|
||||||
|
{categories.map((category) => (
|
||||||
|
<ListItem
|
||||||
|
key={`tag-reminder-${category.id}`}
|
||||||
|
title={category.name}
|
||||||
|
subtitle={notifications ? tagReminderLabel(category.id) : 'Enable notifications first'}
|
||||||
|
leftElement={
|
||||||
|
<View style={[styles.categoryDot, { backgroundColor: category.color }]} />
|
||||||
|
}
|
||||||
|
onPress={() => notifications && setReminderTagPicker(category)}
|
||||||
|
showChevron
|
||||||
|
/>
|
||||||
|
))}
|
||||||
<Text style={[styles.sectionTitle, { color: theme.textMuted }]}>Tasks</Text>
|
<Text style={[styles.sectionTitle, { color: theme.textMuted }]}>Tasks</Text>
|
||||||
<ListItem
|
<ListItem
|
||||||
title="Default Tag"
|
title="Default Tag"
|
||||||
@@ -188,6 +225,19 @@ export default function SettingsScreen() {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<ListItem
|
||||||
|
title="Delete by Swiping"
|
||||||
|
subtitle="Swipe right to delete task"
|
||||||
|
rightElement={
|
||||||
|
<Switch
|
||||||
|
value={deleteBySwipe}
|
||||||
|
onValueChange={setDeleteBySwipe}
|
||||||
|
thumbColor="#FFFFFF"
|
||||||
|
trackColor={{ false: theme.borderStrong, true: theme.accent }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
showChevron
|
||||||
|
/>
|
||||||
<ListItem
|
<ListItem
|
||||||
title="Show Calendar Tasks"
|
title="Show Calendar Tasks"
|
||||||
subtitle={todoAheadDays === 0 ? 'Only today' : `Up to ${todoAheadDays} days ahead`}
|
subtitle={todoAheadDays === 0 ? 'Only today' : `Up to ${todoAheadDays} days ahead`}
|
||||||
@@ -294,6 +344,19 @@ export default function SettingsScreen() {
|
|||||||
onClose={() => setPicker(null)}
|
onClose={() => setPicker(null)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{categories.map((category) => (
|
||||||
|
<OptionPickerModal
|
||||||
|
key={`tag-reminder-picker-${category.id}`}
|
||||||
|
visible={reminderTagPicker?.id === category.id}
|
||||||
|
title={`Reminders · ${category.name}`}
|
||||||
|
options={REMINDER_OPTIONS.filter((o) => o.value !== 'none')}
|
||||||
|
selectedValue={tagReminderPreferences[category.id] ?? []}
|
||||||
|
multiSelect
|
||||||
|
onSelect={(value) => handleTagReminderPreference(category.id, value)}
|
||||||
|
onClose={() => setReminderTagPicker(null)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
|
||||||
<OptionPickerModal
|
<OptionPickerModal
|
||||||
visible={picker === 'todoAhead'}
|
visible={picker === 'todoAhead'}
|
||||||
title="Calendar Tasks in Todo"
|
title="Calendar Tasks in Todo"
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ export default function AddTaskScreen() {
|
|||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
keyboardDismissMode="interactive"
|
keyboardDismissMode="interactive"
|
||||||
|
automaticallyAdjustContentInsets={false}
|
||||||
>
|
>
|
||||||
<CategorySelector
|
<CategorySelector
|
||||||
value={tags}
|
value={tags}
|
||||||
|
|||||||
@@ -40,11 +40,14 @@ export default function DayViewScreen() {
|
|||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
const sub = BackHandler.addEventListener('hardwareBackPress', () => false);
|
const sub = BackHandler.addEventListener('hardwareBackPress', () => {
|
||||||
|
router.back();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
refreshSubtasks();
|
refreshSubtasks();
|
||||||
refresh();
|
refresh();
|
||||||
return () => sub.remove();
|
return () => sub.remove();
|
||||||
}, [refreshSubtasks, refresh])
|
}, [router, refreshSubtasks, refresh])
|
||||||
);
|
);
|
||||||
|
|
||||||
const subtasksOnDay = useMemo(() => {
|
const subtasksOnDay = useMemo(() => {
|
||||||
@@ -70,7 +73,7 @@ export default function DayViewScreen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={[styles.container, { backgroundColor: theme.background, paddingBottom: insets.bottom }]}>
|
<SafeAreaView style={[styles.container, { backgroundColor: theme.background, paddingBottom: insets.bottom }]}>
|
||||||
<Header title={format(day, 'EEEE, MMM d')} showLogo={false} />
|
<Header title={format(day, 'EEEE, MMM d')} showLogo={false} rightAction="Back" />
|
||||||
<KeyboardAvoidingView style={styles.kbAvoid} behavior="padding">
|
<KeyboardAvoidingView style={styles.kbAvoid} behavior="padding">
|
||||||
<ScrollView style={styles.scrollBody} contentContainerStyle={styles.scrollContent} showsVerticalScrollIndicator={false}>
|
<ScrollView style={styles.scrollBody} contentContainerStyle={styles.scrollContent} showsVerticalScrollIndicator={false}>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ export default function SubtaskDetailScreen() {
|
|||||||
contentContainerStyle={styles.scrollContent}
|
contentContainerStyle={styles.scrollContent}
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
|
keyboardDismissMode="interactive"
|
||||||
>
|
>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useSettings } from '@/theme';
|
|||||||
import { CATEGORY_COLORS } from '@/constants';
|
import { CATEGORY_COLORS } from '@/constants';
|
||||||
import { createCategory, updateCategory, deleteCategory } from '@/utils/categoryActions';
|
import { createCategory, updateCategory, deleteCategory } from '@/utils/categoryActions';
|
||||||
import { confirmAction } from '@/utils/confirm';
|
import { confirmAction } from '@/utils/confirm';
|
||||||
import ColorPickerInput from '@/components/ColorPickerInput';
|
import ColorWheel from '@/components/ColorWheel';
|
||||||
import Svg, { Path, Circle } from 'react-native-svg';
|
import Svg, { Path, Circle } from 'react-native-svg';
|
||||||
|
|
||||||
interface CategoryEditorModalProps {
|
interface CategoryEditorModalProps {
|
||||||
@@ -129,7 +129,7 @@ export function CategoryEditorModal({ visible, category, categoryCount, onClose
|
|||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
<ColorPickerInput value={color} onChange={setColor} />
|
<ColorWheel color={color} onChange={setColor} />
|
||||||
|
|
||||||
<View style={styles.actions}>
|
<View style={styles.actions}>
|
||||||
{category && (
|
{category && (
|
||||||
|
|||||||
@@ -26,9 +26,12 @@ export default function NativeColorPickerInput({ value, onChange }: ColorPickerI
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.row}>
|
<View style={styles.row}>
|
||||||
<View style={[styles.preview, { backgroundColor: valid ? value : theme.borderStrong, borderColor: theme.borderStrong }]} />
|
<View style={[
|
||||||
<View style={[styles.inputWrap, { backgroundColor: theme.inputBg, borderColor: theme.borderStrong }]}>
|
styles.preview,
|
||||||
<Text style={[styles.hash, { color: theme.textMuted }]}>#</Text>
|
{ backgroundColor: valid ? value : theme.accentSoft, borderColor: theme.accent },
|
||||||
|
]} />
|
||||||
|
<View style={styles.inputWrap}>
|
||||||
|
<Text style={styles.hash}>#{/**/}</Text>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={[styles.input, { color: theme.text }]}
|
style={[styles.input, { color: theme.text }]}
|
||||||
value={hex}
|
value={hex}
|
||||||
@@ -40,7 +43,7 @@ export default function NativeColorPickerInput({ value, onChange }: ColorPickerI
|
|||||||
maxLength={6}
|
maxLength={6}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<Text style={[styles.hint, { color: theme.textMuted }]}>Hex code</Text>
|
<Text style={styles.hint}>{/**/}Hex code</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ export default function WebColorPickerInput({ value, onChange }: ColorPickerInpu
|
|||||||
width: 44,
|
width: 44,
|
||||||
height: 44,
|
height: 44,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
border: `1px solid ${theme.borderStrong}`,
|
border: `1px solid ${theme.accent}`,
|
||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
backgroundColor: 'transparent',
|
backgroundColor: 'transparent',
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
},
|
},
|
||||||
})}
|
})}
|
||||||
<Text style={[styles.hexText, { color: theme.textSecondary }]}>{normalized}</Text>
|
<Text style={[styles.hexText, { color: theme.accent }]}>{normalized}</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ interface TaskItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const TaskItem = React.memo(function TaskItem({ task, onToggle, onDelete, onPress, onLongPress, onMenuOpen, selected, selectionMode, completedSection, draggable, hovered, onDragStart, onDragUpdate, onDragEnd, onReorderStart, onReorderUpdate, onReorderEnd, expanded, indented, depth = 0, categoryColor, categoryColors }: TaskItemProps) {
|
export const TaskItem = React.memo(function TaskItem({ task, onToggle, onDelete, onPress, onLongPress, onMenuOpen, selected, selectionMode, completedSection, draggable, hovered, onDragStart, onDragUpdate, onDragEnd, onReorderStart, onReorderUpdate, onReorderEnd, expanded, indented, depth = 0, categoryColor, categoryColors }: TaskItemProps) {
|
||||||
const { theme } = useSettings();
|
const { theme, deleteBySwipe } = useSettings();
|
||||||
const styles = React.useMemo(() => createStyles(theme), [theme]);
|
const styles = React.useMemo(() => createStyles(theme), [theme]);
|
||||||
const [opacityAnim] = React.useState(new Animated.Value(task.completed ? 0.5 : 1));
|
const [opacityAnim] = React.useState(new Animated.Value(task.completed ? 0.5 : 1));
|
||||||
const [dragTranslateX] = React.useState(new Animated.Value(0));
|
const [dragTranslateX] = React.useState(new Animated.Value(0));
|
||||||
@@ -176,7 +176,9 @@ const renderLeftActions = (progress: Animated.AnimatedInterpolation<number>) =>
|
|||||||
renderRightActions={renderRightActions}
|
renderRightActions={renderRightActions}
|
||||||
renderLeftActions={renderLeftActions}
|
renderLeftActions={renderLeftActions}
|
||||||
onSwipeableRightOpen={() => {
|
onSwipeableRightOpen={() => {
|
||||||
|
if (deleteBySwipe) {
|
||||||
onDelete?.();
|
onDelete?.();
|
||||||
|
}
|
||||||
swipeableRef.current?.close();
|
swipeableRef.current?.close();
|
||||||
}}
|
}}
|
||||||
onSwipeableLeftOpen={() => {
|
onSwipeableLeftOpen={() => {
|
||||||
|
|||||||
@@ -334,8 +334,8 @@ export function TaskList({ categoryIds = [], showCompleted = false, onSelectionC
|
|||||||
}
|
}
|
||||||
}, [findHoverTarget]);
|
}, [findHoverTarget]);
|
||||||
|
|
||||||
const handleSubtaskDragStart = useCallback(async (subtaskId: string, parentTaskId: string) => {
|
const handleSubtaskDragStart = useCallback(async (subtaskId: string, parentTaskId: string, parentSubtaskId?: string) => {
|
||||||
subtaskDragRef.current = { subtaskId, parentTaskId, ...(await measureAll()) };
|
subtaskDragRef.current = { subtaskId, parentTaskId, parentSubtaskId, ...(await measureAll()) };
|
||||||
}, [measureAll]);
|
}, [measureAll]);
|
||||||
|
|
||||||
const handleSubtaskDragUpdate = useCallback((absoluteY: number) => {
|
const handleSubtaskDragUpdate = useCallback((absoluteY: number) => {
|
||||||
@@ -371,16 +371,15 @@ export function TaskList({ categoryIds = [], showCompleted = false, onSelectionC
|
|||||||
const target = findHoverTarget(absoluteY, state.subtaskId, state.positions, state.subPositions);
|
const target = findHoverTarget(absoluteY, state.subtaskId, state.positions, state.subPositions);
|
||||||
if (target === state.subtaskId) return;
|
if (target === state.subtaskId) return;
|
||||||
|
|
||||||
if (target) {
|
// Only allow dropping on tasks (not subtasks) to match task behavior
|
||||||
if (state.subPositions[target]) {
|
// Check if target exists in main task positions, not subtask positions
|
||||||
await setSubtaskParent(state.subtaskId, target);
|
const isTaskTarget = state.positions && target in state.positions;
|
||||||
} else if (target !== state.parentTaskId) {
|
if (target && isTaskTarget) {
|
||||||
|
// Move subtask to target task - makes it a subtask of that task
|
||||||
|
// If no target or target is a subtask: do nothing (matches task behavior)
|
||||||
await moveSubtaskToTask(state.subtaskId, target);
|
await moveSubtaskToTask(state.subtaskId, target);
|
||||||
}
|
}
|
||||||
} else {
|
}, [findHoverTarget, moveSubtaskToTask]);
|
||||||
await convertSubtaskToTask(state.subtaskId);
|
|
||||||
}
|
|
||||||
}, [findHoverTarget]);
|
|
||||||
|
|
||||||
const renderItem = useCallback(
|
const renderItem = useCallback(
|
||||||
({ item, index }: { item: Task; index: number }) => {
|
({ item, index }: { item: Task; index: number }) => {
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
import { useDatabase } from './useDatabase';
|
||||||
|
import { Q } from '@nozbe/watermelondb';
|
||||||
|
import { useEffect, useState, useCallback } from 'react';
|
||||||
|
import Task from '../models/Task';
|
||||||
|
import parseICal from '../utils/icalParser';
|
||||||
|
import { startOfMonth, endOfMonth, addMonths, format } from 'date-fns';
|
||||||
|
|
||||||
|
function mapICalEventToTask(event: {
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
start: Date;
|
||||||
|
end?: Date;
|
||||||
|
allDay?: boolean;
|
||||||
|
rrule?: string;
|
||||||
|
uid?: string;
|
||||||
|
priority?: number;
|
||||||
|
}): {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
dueDate: number;
|
||||||
|
dueTime: string;
|
||||||
|
endTime: string;
|
||||||
|
allDay: boolean;
|
||||||
|
repeat: string;
|
||||||
|
repeatInterval: number;
|
||||||
|
repeatDays: string;
|
||||||
|
seriesId: string;
|
||||||
|
reminder: string;
|
||||||
|
reminders: string;
|
||||||
|
categoryId: string;
|
||||||
|
tags: string;
|
||||||
|
priority: string;
|
||||||
|
completed: boolean;
|
||||||
|
completedAt: number | null;
|
||||||
|
} {
|
||||||
|
const defaultCategoryId = 'cat_default'; // will be resolved later
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
let dueDate = event.start.getTime();
|
||||||
|
let dueTime = '00:00';
|
||||||
|
let endTime = '00:00';
|
||||||
|
let allDay = event.allDay === true || !event.end;
|
||||||
|
|
||||||
|
if (event.allDay) {
|
||||||
|
dueDate = new Date(event.start.getFullYear(), event.start.getMonth(), event.start.getDate()).getTime();
|
||||||
|
dueTime = '00:00';
|
||||||
|
endTime = '23:59';
|
||||||
|
} else {
|
||||||
|
dueDate = event.start.getTime();
|
||||||
|
dueTime = `${event.start.getHours().toString().padStart(2, '0')}:${event.start.getMinutes().toString().padStart(2, '0')}`;
|
||||||
|
if (event.end) {
|
||||||
|
endTime = `${event.end.getHours().toString().padStart(2, '0')}:${event.end.getMinutes().toString().padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let repeat = 'none';
|
||||||
|
let repeatInterval = 1;
|
||||||
|
let repeatDays = '';
|
||||||
|
let seriesId = event.uid || `${dueDate}-${Math.random().toString(36).substring(2, 9)}`;
|
||||||
|
let reminder = 'none';
|
||||||
|
let reminders = '';
|
||||||
|
|
||||||
|
if (event.rrule) {
|
||||||
|
repeat = 'custom';
|
||||||
|
// Simple RRULE parsing - extract FREQ and INTERVAL
|
||||||
|
const freqMatch = event.rrule.match(/FREQ=([^;:]+)/i);
|
||||||
|
if (freqMatch) {
|
||||||
|
const freq = freqMatch[1].toLowerCase();
|
||||||
|
if (freq === 'daily') {
|
||||||
|
repeat = 'daily';
|
||||||
|
repeatInterval = 1;
|
||||||
|
} else if (freq === 'weekly') {
|
||||||
|
repeat = 'weekly';
|
||||||
|
repeatInterval = 1;
|
||||||
|
} else if (freq === 'monthly') {
|
||||||
|
repeat = 'monthly';
|
||||||
|
repeatInterval = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Extract INTERVAL
|
||||||
|
const intervalMatch = event.rrule.match(/INTERVAL=(\d+)/i);
|
||||||
|
if (intervalMatch) {
|
||||||
|
repeatInterval = parseInt(intervalMatch[1], 10);
|
||||||
|
}
|
||||||
|
// Extract BYDAY for weekly/Monthly
|
||||||
|
const bydayMatch = event.rrule.match(/BYDAY=([^;,]+)/i);
|
||||||
|
if (bydayMatch) {
|
||||||
|
repeatDays = bydayMatch[1].replace(/,/g, ',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map priority (iCal priority: -2=low, 0=normal, 2=high, 3-4=highest, 5=urgent)
|
||||||
|
let priorityValue: string = 'medium';
|
||||||
|
if (event.priority !== undefined) {
|
||||||
|
const p = event.priority;
|
||||||
|
if (p <= -2) priorityValue = 'low';
|
||||||
|
else if (p === 0) priorityValue = 'medium';
|
||||||
|
else if (p === 2) priorityValue = 'high';
|
||||||
|
else if (p >= 5) priorityValue = 'urgent';
|
||||||
|
else priorityValue = 'medium';
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: event.title,
|
||||||
|
description: event.description || '',
|
||||||
|
dueDate,
|
||||||
|
dueTime,
|
||||||
|
endTime,
|
||||||
|
allDay,
|
||||||
|
repeat,
|
||||||
|
repeatInterval,
|
||||||
|
repeatDays,
|
||||||
|
seriesId,
|
||||||
|
reminder,
|
||||||
|
reminders,
|
||||||
|
categoryId: defaultCategoryId,
|
||||||
|
tags: '',
|
||||||
|
priority: priorityValue,
|
||||||
|
completed: false,
|
||||||
|
completedAt: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useICalImport() {
|
||||||
|
const { collections } = useDatabase();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const importICal = useCallback(async (icalContent: string) => {
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const events = parseICal(icalContent);
|
||||||
|
|
||||||
|
if (events.length === 0) {
|
||||||
|
throw new Error('No events found in the iCal data');
|
||||||
|
}
|
||||||
|
|
||||||
|
const taskData = events.map(mapICalEventToTask);
|
||||||
|
|
||||||
|
// Insert tasks into WatermelonDB
|
||||||
|
const subscription = collections.tasks
|
||||||
|
.query()
|
||||||
|
.splice(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
...taskData.map((td) => ({
|
||||||
|
title: td.title,
|
||||||
|
description: td.description,
|
||||||
|
category_id: td.categoryId,
|
||||||
|
tags: td.tags,
|
||||||
|
priority: td.priority,
|
||||||
|
completed: td.completed,
|
||||||
|
completed_at: td.completedAt,
|
||||||
|
due_date: td.dueDate,
|
||||||
|
due_time: td.dueTime,
|
||||||
|
end_time: td.endTime,
|
||||||
|
all_day: td.allDay,
|
||||||
|
repeat: td.repeat,
|
||||||
|
repeat_interval: td.repeatInterval,
|
||||||
|
repeat_days: td.repeatDays,
|
||||||
|
color: '#9E9E9E',
|
||||||
|
series_id: td.seriesId,
|
||||||
|
order: 0,
|
||||||
|
reminder: td.reminder,
|
||||||
|
reminders: td.reminders,
|
||||||
|
assignee_id: null,
|
||||||
|
created_at: now,
|
||||||
|
updated_at: now,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Observe the changes
|
||||||
|
subscription.subscribe({
|
||||||
|
next: (result) => {
|
||||||
|
// Tasks have been imported
|
||||||
|
},
|
||||||
|
error: (err) => {
|
||||||
|
console.error('Import error:', err);
|
||||||
|
setError(err.message);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('ICal import failed:', err);
|
||||||
|
setError(err.message || 'Import failed');
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [collections]);
|
||||||
|
|
||||||
|
return { importICal, loading, error };
|
||||||
|
}
|
||||||
@@ -109,7 +109,9 @@ export async function apiFetch(path: string, options: RequestInit = {}): Promise
|
|||||||
let details: any = null;
|
let details: any = null;
|
||||||
try {
|
try {
|
||||||
const body = JSON.parse(text);
|
const body = JSON.parse(text);
|
||||||
if (body && typeof body.message === 'string') {
|
if (body && typeof body.error?.message === 'string') {
|
||||||
|
message = body.error.message;
|
||||||
|
} else if (body && typeof body.message === 'string') {
|
||||||
message = body.message;
|
message = body.message;
|
||||||
}
|
}
|
||||||
if (body && body.error && body.error.details) {
|
if (body && body.error && body.error.details) {
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import { Reminder, reminderToMinutes, parseReminders, ReminderPreference } from '@/types';
|
import { Reminder, reminderToMinutes, parseReminders, ReminderPreference, parseTaskTags } from '@/types';
|
||||||
|
import { TagReminderPreferences, TAG_REMINDER_PREFERENCES_KEY } from '@/theme';
|
||||||
|
|
||||||
const ID_MAP_KEY = 'notifications:taskIdToNotificationIds';
|
const ID_MAP_KEY = 'notifications:taskIdToNotificationIds';
|
||||||
|
|
||||||
|
async function loadTagPreferences(): Promise<TagReminderPreferences> {
|
||||||
|
try {
|
||||||
|
const raw = await AsyncStorage.getItem(TAG_REMINDER_PREFERENCES_KEY);
|
||||||
|
return raw ? (JSON.parse(raw) as TagReminderPreferences) : {};
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function readIdMap(): Promise<Record<string, string[]>> {
|
async function readIdMap(): Promise<Record<string, string[]>> {
|
||||||
try {
|
try {
|
||||||
const raw = await AsyncStorage.getItem(ID_MAP_KEY);
|
const raw = await AsyncStorage.getItem(ID_MAP_KEY);
|
||||||
@@ -51,7 +61,11 @@ function reminderPreferenceToReminder(pref: ReminderPreference): Reminder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRemindersForTask(task: any, globalPreference: ReminderPreference): Reminder[] {
|
function getRemindersForTask(
|
||||||
|
task: any,
|
||||||
|
globalPreference: ReminderPreference,
|
||||||
|
tagPreferences: TagReminderPreferences = {}
|
||||||
|
): Reminder[] {
|
||||||
const taskReminders: Reminder[] = task.reminders
|
const taskReminders: Reminder[] = task.reminders
|
||||||
? parseReminders(task.reminders)
|
? parseReminders(task.reminders)
|
||||||
: task.reminder && task.reminder !== 'none'
|
: task.reminder && task.reminder !== 'none'
|
||||||
@@ -62,6 +76,17 @@ function getRemindersForTask(task: any, globalPreference: ReminderPreference): R
|
|||||||
return taskReminders;
|
return taskReminders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tagReminders: Reminder[] = [];
|
||||||
|
for (const tagId of parseTaskTags(task.tags, task.categoryId)) {
|
||||||
|
for (const pref of tagPreferences[tagId] ?? []) {
|
||||||
|
if (pref === 'none') continue;
|
||||||
|
if (!tagReminders.includes(pref)) tagReminders.push(pref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tagReminders.length > 0) {
|
||||||
|
return tagReminders;
|
||||||
|
}
|
||||||
|
|
||||||
const globalReminder = reminderPreferenceToReminder(globalPreference);
|
const globalReminder = reminderPreferenceToReminder(globalPreference);
|
||||||
if (globalReminder !== 'none') {
|
if (globalReminder !== 'none') {
|
||||||
return [globalReminder];
|
return [globalReminder];
|
||||||
@@ -92,7 +117,8 @@ export async function scheduleTaskReminder(task: any, notificationsEnabled: bool
|
|||||||
await writeIdMap(idMap);
|
await writeIdMap(idMap);
|
||||||
|
|
||||||
// Determine the set of reminders to schedule
|
// Determine the set of reminders to schedule
|
||||||
const reminders = getRemindersForTask(task, globalReminderPreference);
|
const tagPreferences = await loadTagPreferences();
|
||||||
|
const reminders = getRemindersForTask(task, globalReminderPreference, tagPreferences);
|
||||||
|
|
||||||
if (reminders.length === 0 || !dueDate || !task.dueTime) return;
|
if (reminders.length === 0 || !dueDate || !task.dueTime) return;
|
||||||
|
|
||||||
@@ -195,11 +221,12 @@ export async function rescheduleAllReminders(tasks: any[], notificationsEnabled:
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
const idMap: Record<string, string[]> = {};
|
const idMap: Record<string, string[]> = {};
|
||||||
|
const tagPreferences = await loadTagPreferences();
|
||||||
|
|
||||||
for (const task of tasks) {
|
for (const task of tasks) {
|
||||||
const dueDate = task.dueDate ? new Date(task.dueDate) : null;
|
const dueDate = task.dueDate ? new Date(task.dueDate) : null;
|
||||||
|
|
||||||
const reminders = getRemindersForTask(task, globalReminderPreference);
|
const reminders = getRemindersForTask(task, globalReminderPreference, tagPreferences);
|
||||||
|
|
||||||
if (reminders.length === 0 || !dueDate || !task.dueTime) continue;
|
if (reminders.length === 0 || !dueDate || !task.dueTime) continue;
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ export const REMINDER_OPTIONS: { value: ReminderPreference; label: string }[] =
|
|||||||
{ value: '1440', label: '1 day before' },
|
{ value: '1440', label: '1 day before' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export type TagReminderPreferences = Record<string, ReminderPreference[]>;
|
||||||
|
|
||||||
|
export const TAG_REMINDER_PREFERENCES_KEY = 'settings:tagReminderPreferences';
|
||||||
|
|
||||||
export interface ThemeColors {
|
export interface ThemeColors {
|
||||||
background: string;
|
background: string;
|
||||||
card: string;
|
card: string;
|
||||||
@@ -138,6 +142,8 @@ interface SettingsContextType {
|
|||||||
setSortBy: (value: SortBy) => void;
|
setSortBy: (value: SortBy) => void;
|
||||||
reminderPreference: ReminderPreference;
|
reminderPreference: ReminderPreference;
|
||||||
setReminderPreference: (value: ReminderPreference) => void;
|
setReminderPreference: (value: ReminderPreference) => void;
|
||||||
|
tagReminderPreferences: TagReminderPreferences;
|
||||||
|
setTagReminderPreferences: (value: TagReminderPreferences) => void;
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
setApiUrl: (value: string) => void;
|
setApiUrl: (value: string) => void;
|
||||||
accentColor: string;
|
accentColor: string;
|
||||||
@@ -146,6 +152,8 @@ interface SettingsContextType {
|
|||||||
setTodoAheadDays: (value: number) => void;
|
setTodoAheadDays: (value: number) => void;
|
||||||
showCompleted: boolean;
|
showCompleted: boolean;
|
||||||
setShowCompleted: (value: boolean) => void;
|
setShowCompleted: (value: boolean) => void;
|
||||||
|
deleteBySwipe: boolean;
|
||||||
|
setDeleteBySwipe: (value: boolean) => void;
|
||||||
theme: ThemeColors;
|
theme: ThemeColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,9 +164,11 @@ const STORAGE_KEYS = {
|
|||||||
defaultCategoryId: 'settings:defaultCategoryId',
|
defaultCategoryId: 'settings:defaultCategoryId',
|
||||||
sortBy: 'settings:sortBy',
|
sortBy: 'settings:sortBy',
|
||||||
reminderPreference: 'settings:reminderPreference',
|
reminderPreference: 'settings:reminderPreference',
|
||||||
|
tagReminderPreferences: TAG_REMINDER_PREFERENCES_KEY,
|
||||||
accentColor: 'settings:accentColor',
|
accentColor: 'settings:accentColor',
|
||||||
todoAheadDays: 'settings:todoAheadDays',
|
todoAheadDays: 'settings:todoAheadDays',
|
||||||
showCompleted: 'settings:showCompleted',
|
showCompleted: 'settings:showCompleted',
|
||||||
|
deleteBySwipe: 'settings:deleteBySwipe',
|
||||||
};
|
};
|
||||||
|
|
||||||
const SettingsContext = createContext<SettingsContextType | null>(null);
|
const SettingsContext = createContext<SettingsContextType | null>(null);
|
||||||
@@ -197,10 +207,15 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
STORAGE_KEYS.reminderPreference,
|
STORAGE_KEYS.reminderPreference,
|
||||||
'15',
|
'15',
|
||||||
);
|
);
|
||||||
|
const [tagReminderPreferences, setTagReminderPreferences] = useStoredSetting<TagReminderPreferences>(
|
||||||
|
STORAGE_KEYS.tagReminderPreferences,
|
||||||
|
{},
|
||||||
|
);
|
||||||
const [apiUrl, setApiUrl] = useStoredSetting<string>(API_URL_KEY, DEFAULT_API_BASE_URL);
|
const [apiUrl, setApiUrl] = useStoredSetting<string>(API_URL_KEY, DEFAULT_API_BASE_URL);
|
||||||
const [accentColor, setAccentColor] = useStoredSetting<string>(STORAGE_KEYS.accentColor, DEFAULT_ACCENT);
|
const [accentColor, setAccentColor] = useStoredSetting<string>(STORAGE_KEYS.accentColor, DEFAULT_ACCENT);
|
||||||
const [todoAheadDays, setTodoAheadDays] = useStoredSetting<number>(STORAGE_KEYS.todoAheadDays, DEFAULT_TODO_AHEAD_DAYS);
|
const [todoAheadDays, setTodoAheadDays] = useStoredSetting<number>(STORAGE_KEYS.todoAheadDays, DEFAULT_TODO_AHEAD_DAYS);
|
||||||
const [showCompleted, setShowCompleted] = useStoredSetting<boolean>(STORAGE_KEYS.showCompleted, false);
|
const [showCompleted, setShowCompleted] = useStoredSetting<boolean>(STORAGE_KEYS.showCompleted, false);
|
||||||
|
const [deleteBySwipe, setDeleteBySwipe] = useStoredSetting<boolean>(STORAGE_KEYS.deleteBySwipe, false);
|
||||||
|
|
||||||
const theme = useMemo(() => colors(accentColor), [accentColor]);
|
const theme = useMemo(() => colors(accentColor), [accentColor]);
|
||||||
|
|
||||||
@@ -214,6 +229,8 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
setSortBy,
|
setSortBy,
|
||||||
reminderPreference,
|
reminderPreference,
|
||||||
setReminderPreference,
|
setReminderPreference,
|
||||||
|
tagReminderPreferences,
|
||||||
|
setTagReminderPreferences,
|
||||||
apiUrl,
|
apiUrl,
|
||||||
setApiUrl,
|
setApiUrl,
|
||||||
accentColor,
|
accentColor,
|
||||||
@@ -222,6 +239,8 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
setTodoAheadDays,
|
setTodoAheadDays,
|
||||||
showCompleted,
|
showCompleted,
|
||||||
setShowCompleted,
|
setShowCompleted,
|
||||||
|
deleteBySwipe,
|
||||||
|
setDeleteBySwipe,
|
||||||
theme,
|
theme,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
@@ -233,6 +252,8 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
setSortBy,
|
setSortBy,
|
||||||
reminderPreference,
|
reminderPreference,
|
||||||
setReminderPreference,
|
setReminderPreference,
|
||||||
|
tagReminderPreferences,
|
||||||
|
setTagReminderPreferences,
|
||||||
apiUrl,
|
apiUrl,
|
||||||
setApiUrl,
|
setApiUrl,
|
||||||
accentColor,
|
accentColor,
|
||||||
@@ -241,7 +262,6 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
setTodoAheadDays,
|
setTodoAheadDays,
|
||||||
showCompleted,
|
showCompleted,
|
||||||
setShowCompleted,
|
setShowCompleted,
|
||||||
theme,
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
function parseICal(content: string): Array<{
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
start: Date;
|
||||||
|
end?: Date;
|
||||||
|
allDay?: boolean;
|
||||||
|
rrule?: string;
|
||||||
|
uid?: string;
|
||||||
|
priority?: number;
|
||||||
|
}> {
|
||||||
|
const events: Array<{
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
start: Date;
|
||||||
|
end?: Date;
|
||||||
|
allDay?: boolean;
|
||||||
|
rrule?: string;
|
||||||
|
uid?: string;
|
||||||
|
priority?: number;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
const lines = content.split('\n');
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
|
while (i < lines.length) {
|
||||||
|
const line = lines[i].trim();
|
||||||
|
if (!line) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.startsWith('BEGIN:VEVENT')) {
|
||||||
|
const event: {
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
start: Date;
|
||||||
|
end?: Date;
|
||||||
|
allDay?: boolean;
|
||||||
|
rrule?: string;
|
||||||
|
uid?: string;
|
||||||
|
priority?: number;
|
||||||
|
} = {
|
||||||
|
title: '',
|
||||||
|
start: new Date(0),
|
||||||
|
};
|
||||||
|
|
||||||
|
i++;
|
||||||
|
let inEvent = true;
|
||||||
|
|
||||||
|
while (i < lines.length && inEvent) {
|
||||||
|
const line = lines[i].trim();
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (line === 'END:VEVENT') {
|
||||||
|
inEvent = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.startsWith('END:')) {
|
||||||
|
inEvent = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.startsWith('SUMMARY:')) {
|
||||||
|
event.title = line.substring(8).trim();
|
||||||
|
} else if (line.startsWith('DESCRIPTION:')) {
|
||||||
|
event.description = line.substring(12).trim();
|
||||||
|
} else if (line.startsWith('DTSTART:')) {
|
||||||
|
const dateStr = line.substring(8).trim();
|
||||||
|
event.start = parseICalDateTime(dateStr);
|
||||||
|
} else if (line.startsWith('DTEND:')) {
|
||||||
|
const dateStr = line.substring(6).trim();
|
||||||
|
event.end = parseICalDateTime(dateStr);
|
||||||
|
} else if (line.startsWith('DTSTAMP:')) {
|
||||||
|
// ignore, we use start date
|
||||||
|
} else if (line.startsWith('UID:')) {
|
||||||
|
event.uid = line.substring(4).trim();
|
||||||
|
} else if (line.startsWith('PRIORITY:')) {
|
||||||
|
event.priority = parseInt(line.substring(9).trim(), 10);
|
||||||
|
} else if (line.startsWith('ALL-DAY:')) {
|
||||||
|
event.allDay = line.substring(10).trim().toLowerCase() === 'true';
|
||||||
|
} else if (line.startsWith('RRULE:')) {
|
||||||
|
event.rrule = line.substring(6).trim();
|
||||||
|
} else if (line.startsWith('BEGIN:VALARM')) {
|
||||||
|
// skip alarms
|
||||||
|
i++;
|
||||||
|
let inAlarm = true;
|
||||||
|
while (i < lines.length && inAlarm) {
|
||||||
|
const alarmLine = lines[i].trim();
|
||||||
|
i++;
|
||||||
|
if (alarmLine === 'END:VALARM') {
|
||||||
|
inAlarm = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// skip unrecognized lines
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.title) {
|
||||||
|
events.push(event);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseICalDateTime(dateStr: string): Date {
|
||||||
|
// Handle various iCal date/time formats
|
||||||
|
// Format 1: YYYYMMDDTHHMMSSZ (UTC)
|
||||||
|
// Format 2: YYYYMMDDTHHMMSS (local)
|
||||||
|
// Format 3: YYYYMMDD (date only)
|
||||||
|
// Format 4: TZID:... (with timezone)
|
||||||
|
|
||||||
|
let datePart = '';
|
||||||
|
let timePart = '';
|
||||||
|
let hasTime = false;
|
||||||
|
|
||||||
|
// Check for Z (UTC) indicator
|
||||||
|
const hasZ = dateStr.endsWith('Z');
|
||||||
|
const cleanStr = hasZ ? dateStr.slice(0, -1) : dateStr;
|
||||||
|
|
||||||
|
// Try to split at T
|
||||||
|
const tIndex = cleanStr.indexOf('T');
|
||||||
|
if (tIndex !== -1) {
|
||||||
|
datePart = cleanStr.substring(0, tIndex);
|
||||||
|
timePart = cleanStr.substring(tIndex + 1);
|
||||||
|
hasTime = true;
|
||||||
|
} else {
|
||||||
|
datePart = cleanStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse date (YYYYMMDD)
|
||||||
|
if (datePart.length >= 8) {
|
||||||
|
const year = parseInt(datePart.substring(0, 4), 10);
|
||||||
|
const month = parseInt(datePart.substring(4, 6), 10) - 1; // 0-indexed
|
||||||
|
const day = parseInt(datePart.substring(6, 8), 10);
|
||||||
|
const date = new Date(year, month, day);
|
||||||
|
|
||||||
|
if (hasTime && timePart) {
|
||||||
|
const hour = parseInt(timePart.substring(0, 2), 10);
|
||||||
|
const minute = parseInt(timePart.substring(2, 4), 10);
|
||||||
|
date.setHours(hour, minute, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: try Date.parse
|
||||||
|
return new Date(dateStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default parseICal;
|
||||||
@@ -804,6 +804,19 @@ export async function reorderTasks(taskIds: string[]): Promise<void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function reorderSubtasks(subtaskIds: string[]): Promise<void> {
|
||||||
|
await database.write(async () => {
|
||||||
|
const now = new Date();
|
||||||
|
for (let i = 0; i < subtaskIds.length; i++) {
|
||||||
|
const subtask = await collections.subtasks.find(subtaskIds[i]);
|
||||||
|
await subtask.update((s) => {
|
||||||
|
s.order = i;
|
||||||
|
s.updatedAt = now;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export interface CreateSubtaskData {
|
export interface CreateSubtaskData {
|
||||||
taskId: string;
|
taskId: string;
|
||||||
parentSubtaskId?: string | null;
|
parentSubtaskId?: string | null;
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// https://docs.expo.dev/guides/using-eslint/
|
||||||
|
const { defineConfig } = require('eslint/config');
|
||||||
|
const expoConfig = require("eslint-config-expo/flat");
|
||||||
|
|
||||||
|
module.exports = defineConfig([
|
||||||
|
expoConfig,
|
||||||
|
{
|
||||||
|
ignores: ["dist/*"],
|
||||||
|
}
|
||||||
|
]);
|
||||||
Generated
+3683
-45
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -3,7 +3,6 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Carry Your Live - Desktop App",
|
"description": "Carry Your Live - Desktop App",
|
||||||
"main": "expo-router/entry",
|
"main": "expo-router/entry",
|
||||||
"homepage": "http://localhost:8081",
|
|
||||||
"homepage": "https://gitea.techmos.org/tech08mag/carry-your-live",
|
"homepage": "https://gitea.techmos.org/tech08mag/carry-your-live",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hookform/resolvers": "^5.7.1",
|
"@hookform/resolvers": "^5.7.1",
|
||||||
@@ -26,6 +25,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^41.7.1",
|
"electron": "^41.7.1",
|
||||||
"electron-builder": "^26.15.3",
|
"electron-builder": "^26.15.3",
|
||||||
|
"eslint": "^9.0.0",
|
||||||
|
"eslint-config-expo": "~57.0.1",
|
||||||
"patch-package": "^8.0.1",
|
"patch-package": "^8.0.1",
|
||||||
"typescript": "~6.0.3"
|
"typescript": "~6.0.3"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user