From 88eb4f1f531d7527546a6f0d5afdcba4e7334ba9 Mon Sep 17 00:00:00 2001 From: Gabry848 Date: Thu, 14 May 2026 10:56:28 +0200 Subject: [PATCH 1/4] feat: create service for weekly summary settings API Add weeklySummaryService.ts with functions to: - Get current weekly summary settings - Update weekly summary settings (enabled, day, hour) Co-Authored-By: Claude Sonnet 4.6 --- src/services/weeklySummaryService.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/services/weeklySummaryService.ts diff --git a/src/services/weeklySummaryService.ts b/src/services/weeklySummaryService.ts new file mode 100644 index 0000000..321d79b --- /dev/null +++ b/src/services/weeklySummaryService.ts @@ -0,0 +1,27 @@ +import axiosInstance from './axiosInstance'; + +export interface WeeklySummarySettings { + enabled: boolean; + day: number; // 0-6, dove 0 = Domenica + hour: number; // 0-23 + last_sent_date?: string; + next_scheduled_date?: string; +} + +/** + * Ottiene le impostazioni correnti del riepilogo settimanale + */ +export async function getWeeklySummarySettings(): Promise { + const response = await axiosInstance.get('/notifications/weekly-summary-settings'); + return response.data; +} + +/** + * Aggiorna le impostazioni del riepilogo settimanale + */ +export async function updateWeeklySummarySettings( + settings: Partial +): Promise { + const response = await axiosInstance.put('/notifications/weekly-summary-settings', settings); + return response.data; +} From 5da493d787e7b4c54b6dd237674da6a1531b9a4e Mon Sep 17 00:00:00 2001 From: Gabry848 Date: Thu, 14 May 2026 10:58:21 +0200 Subject: [PATCH 2/4] feat: add weekly summary settings UI to NotificationSettings Add UI section for managing weekly summary settings: - Toggle to enable/disable weekly summaries - Day selector (Dom-Sab) for scheduling - Hour selector (00:00-23:00) for timing - Display next scheduled date when enabled - Integrate with weeklySummaryService API calls Co-Authored-By: Claude Sonnet 4.6 --- .../screens/NotificationSettings.tsx | 226 +++++++++++++++++- 1 file changed, 225 insertions(+), 1 deletion(-) diff --git a/src/navigation/screens/NotificationSettings.tsx b/src/navigation/screens/NotificationSettings.tsx index a458ded..9e136d8 100644 --- a/src/navigation/screens/NotificationSettings.tsx +++ b/src/navigation/screens/NotificationSettings.tsx @@ -22,14 +22,37 @@ import { NotificationSettings, TELEGRAM_REMINDER_OPTIONS, } from '../../services/notificationSettingsService'; +import { + getWeeklySummarySettings, + updateWeeklySummarySettings, + WeeklySummarySettings, +} from '../../services/weeklySummaryService'; import { registerForPushNotificationsAsync, sendTokenToBackend, } from '../../services/notificationService'; +// Costanti per giorni della settimana +const WEEK_DAYS = [ + { value: 0, label: 'Dom' }, + { value: 1, label: 'Lun' }, + { value: 2, label: 'Mar' }, + { value: 3, label: 'Mer' }, + { value: 4, label: 'Gio' }, + { value: 5, label: 'Ven' }, + { value: 6, label: 'Sab' }, +]; + +// Costanti per orari +const HOURS = Array.from({ length: 24 }, (_, i) => ({ + value: i, + label: `${i.toString().padStart(2, '0')}:00`, +})); + export default function NotificationSettingsScreen() { const { t } = useTranslation(); const [settings, setSettings] = useState(null); + const [weeklySummarySettings, setWeeklySummarySettings] = useState(null); const [loading, setLoading] = useState(true); const [syncing, setSyncing] = useState(false); const [syncDone, setSyncDone] = useState(false); @@ -73,8 +96,12 @@ export default function NotificationSettingsScreen() { const loadSettings = useCallback(async () => { try { setLoading(true); - const data = await getNotificationSettings(); + const [data, weeklyData] = await Promise.all([ + getNotificationSettings(), + getWeeklySummarySettings(), + ]); setSettings(data); + setWeeklySummarySettings(weeklyData); } catch (error) { console.error('[NotificationSettings] Errore caricamento:', error); Alert.alert( @@ -164,6 +191,64 @@ export default function NotificationSettingsScreen() { } }; + // Funzioni per riepilogo settimanale + const handleWeeklySummaryToggle = async (enabled: boolean) => { + if (!weeklySummarySettings) return; + + const previous = weeklySummarySettings.enabled; + setWeeklySummarySettings((prev) => prev ? { ...prev, enabled } : prev); + setSavingField('weekly_enabled'); + + try { + const updated = await updateWeeklySummarySettings({ enabled }); + setWeeklySummarySettings(updated); + } catch (error: any) { + setWeeklySummarySettings((prev) => prev ? { ...prev, enabled: previous } : prev); + const detail = error?.response?.data?.detail ?? t('notificationSettings.error.saveFailed'); + Alert.alert(t('notificationSettings.error.title'), detail); + } finally { + setSavingField(null); + } + }; + + const handleWeeklySummaryDay = async (day: number) => { + if (!weeklySummarySettings || weeklySummarySettings.day === day) return; + + const previous = weeklySummarySettings.day; + setWeeklySummarySettings((prev) => prev ? { ...prev, day } : prev); + setSavingField('weekly_day'); + + try { + const updated = await updateWeeklySummarySettings({ day }); + setWeeklySummarySettings(updated); + } catch (error: any) { + setWeeklySummarySettings((prev) => prev ? { ...prev, day: previous } : prev); + const detail = error?.response?.data?.detail ?? t('notificationSettings.error.saveFailed'); + Alert.alert(t('notificationSettings.error.title'), detail); + } finally { + setSavingField(null); + } + }; + + const handleWeeklySummaryHour = async (hour: number) => { + if (!weeklySummarySettings || weeklySummarySettings.hour === hour) return; + + const previous = weeklySummarySettings.hour; + setWeeklySummarySettings((prev) => prev ? { ...prev, hour } : prev); + setSavingField('weekly_hour'); + + try { + const updated = await updateWeeklySummarySettings({ hour }); + setWeeklySummarySettings(updated); + } catch (error: any) { + setWeeklySummarySettings((prev) => prev ? { ...prev, hour: previous } : prev); + const detail = error?.response?.data?.detail ?? t('notificationSettings.error.saveFailed'); + Alert.alert(t('notificationSettings.error.title'), detail); + } finally { + setSavingField(null); + } + }; + if (loading) { return ( @@ -346,6 +431,98 @@ export default function NotificationSettingsScreen() { + {/* ───────────────── WEEKLY SUMMARY ───────────────── */} + + Riepilogo Settimanale + + Ricevi un riepilogo dei tuoi task ogni settimana + + + + {/* Toggle abilitazione */} + + + + + Abilita riepilogo + {weeklySummarySettings?.enabled && weeklySummarySettings.next_scheduled_date && ( + + Prossimo: {new Date(weeklySummarySettings.next_scheduled_date).toLocaleDateString('it-IT', { + weekday: 'long', + day: 'numeric', + month: 'short', + })} alle {weeklySummarySettings.hour}:00 + + )} + + + + + + {/* Selettore giorno - visibile solo se abilitato */} + {weeklySummarySettings?.enabled && ( + <> + + Giorno della settimana + + + + {WEEK_DAYS.map((day) => { + const isSelected = weeklySummarySettings.day === day.value; + const isSaving = savingField === 'weekly_day'; + return ( + handleWeeklySummaryDay(day.value)} + disabled={isSaving} + activeOpacity={0.7} + > + + {day.label} + + + ); + })} + + + + Orario + + + + {HOURS.map((hour) => { + const isSelected = weeklySummarySettings.hour === hour.value; + const isSaving = savingField === 'weekly_hour'; + return ( + handleWeeklySummaryHour(hour.value)} + disabled={isSaving} + activeOpacity={0.7} + > + + {hour.label} + + + ); + })} + + + )} + {/* ───────────────── INFO ───────────────── */} {t('notificationSettings.sections.info')} @@ -492,6 +669,53 @@ const styles = StyleSheet.create({ color: '#ffffff', fontWeight: '600', }, + // Sottosezioni + subSectionHeader: { + paddingHorizontal: 20, + paddingTop: 16, + paddingBottom: 8, + backgroundColor: '#ffffff', + }, + subSectionTitle: { + fontSize: 16, + fontWeight: '600', + color: '#000000', + fontFamily: 'System', + }, + // Hours scroll + hoursScroll: { + borderBottomWidth: 1, + borderBottomColor: '#f0f0f0', + }, + hoursScrollContent: { + paddingHorizontal: 16, + paddingVertical: 16, + gap: 8, + }, + hourPill: { + paddingHorizontal: 16, + paddingVertical: 8, + borderRadius: 16, + borderWidth: 1.5, + borderColor: '#dee2e6', + backgroundColor: '#ffffff', + minWidth: 60, + alignItems: 'center', + }, + hourPillSelected: { + backgroundColor: '#000000', + borderColor: '#000000', + }, + hourPillText: { + fontSize: 14, + color: '#495057', + fontWeight: '500', + fontFamily: 'System', + }, + hourPillTextSelected: { + color: '#ffffff', + fontWeight: '600', + }, // Timezone timezoneRow: { flexDirection: 'row', From 0a9aef31e2cc253f4debb6df581c9074a755c3fe Mon Sep 17 00:00:00 2001 From: Gabry848 Date: Thu, 14 May 2026 11:02:02 +0200 Subject: [PATCH 3/4] feat: add translations for weekly summary settings Add translations for weekly summary section in both Italian and English: - Section titles and descriptions - Enable/disable toggle labels - Day and hour selector labels - Next scheduled date display Update NotificationSettings to use translation keys instead of hardcoded text. Co-Authored-By: Claude Sonnet 4.6 --- src/locales/en.json | 17 ++++++++ src/locales/it.json | 17 ++++++++ .../screens/NotificationSettings.tsx | 39 ++++++++----------- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 1386172..e2bfd99 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -57,6 +57,8 @@ "pushDesc": "Receive notifications directly on this device.", "telegram": "Telegram", "telegramDesc": "Receive automated reminders via the MyTaskly Telegram bot.", + "weeklySummary": "Weekly Summary", + "weeklySummaryDesc": "Receive a weekly summary of your tasks.", "timezone": "Timezone", "timezoneDesc": "Reminders are sent according to this timezone. Keep it in sync with your device.", "info": "Information" @@ -76,6 +78,21 @@ "title": "Reminder advance notice", "desc": "How many minutes before the task deadline should the reminder be sent." }, + "weeklySummary": { + "enable": "Enable summary", + "nextScheduled": "Next: {{date}} at {{time}}", + "day": "Day of week", + "hour": "Time", + "days": { + "0": "Sun", + "1": "Mon", + "2": "Tue", + "3": "Wed", + "4": "Thu", + "5": "Fri", + "6": "Sat" + } + }, "timezone": { "server": "Server", "device": "This device", diff --git a/src/locales/it.json b/src/locales/it.json index 2e357cf..de25566 100644 --- a/src/locales/it.json +++ b/src/locales/it.json @@ -58,6 +58,8 @@ "pushDesc": "Ricevi notifiche direttamente su questo dispositivo.", "telegram": "Telegram", "telegramDesc": "Ricevi promemoria automatici tramite il bot Telegram di MyTaskly.", + "weeklySummary": "Riepilogo Settimanale", + "weeklySummaryDesc": "Ricevi un riepilogo dei tuoi task ogni settimana.", "timezone": "Fuso Orario", "timezoneDesc": "I promemoria vengono inviati in base a questo fuso orario. Mantienilo sincronizzato con il tuo dispositivo.", "info": "Informazioni" @@ -77,6 +79,21 @@ "title": "Anticipo promemoria", "desc": "Quanti minuti prima della scadenza del task deve essere inviato il promemoria." }, + "weeklySummary": { + "enable": "Abilita riepilogo", + "nextScheduled": "Prossimo: {{date}} alle {{time}}", + "day": "Giorno della settimana", + "hour": "Orario", + "days": { + "0": "Dom", + "1": "Lun", + "2": "Mar", + "3": "Mer", + "4": "Gio", + "5": "Ven", + "6": "Sab" + } + }, "timezone": { "server": "Server", "device": "Questo dispositivo", diff --git a/src/navigation/screens/NotificationSettings.tsx b/src/navigation/screens/NotificationSettings.tsx index 9e136d8..24aaa4c 100644 --- a/src/navigation/screens/NotificationSettings.tsx +++ b/src/navigation/screens/NotificationSettings.tsx @@ -32,23 +32,15 @@ import { sendTokenToBackend, } from '../../services/notificationService'; -// Costanti per giorni della settimana -const WEEK_DAYS = [ - { value: 0, label: 'Dom' }, - { value: 1, label: 'Lun' }, - { value: 2, label: 'Mar' }, - { value: 3, label: 'Mer' }, - { value: 4, label: 'Gio' }, - { value: 5, label: 'Ven' }, - { value: 6, label: 'Sab' }, -]; - // Costanti per orari const HOURS = Array.from({ length: 24 }, (_, i) => ({ value: i, label: `${i.toString().padStart(2, '0')}:00`, })); +// Costanti per giorni della settimana (valori 0-6) +const WEEK_DAYS = [0, 1, 2, 3, 4, 5, 6]; + export default function NotificationSettingsScreen() { const { t } = useTranslation(); const [settings, setSettings] = useState(null); @@ -433,9 +425,9 @@ export default function NotificationSettingsScreen() { {/* ───────────────── WEEKLY SUMMARY ───────────────── */} - Riepilogo Settimanale + {t('notificationSettings.sections.weeklySummary')} - Ricevi un riepilogo dei tuoi task ogni settimana + {t('notificationSettings.sections.weeklySummaryDesc')} @@ -444,14 +436,17 @@ export default function NotificationSettingsScreen() { - Abilita riepilogo + {t('notificationSettings.weeklySummary.enable')} {weeklySummarySettings?.enabled && weeklySummarySettings.next_scheduled_date && ( - Prossimo: {new Date(weeklySummarySettings.next_scheduled_date).toLocaleDateString('it-IT', { - weekday: 'long', - day: 'numeric', - month: 'short', - })} alle {weeklySummarySettings.hour}:00 + {t('notificationSettings.weeklySummary.nextScheduled', { + date: new Date(weeklySummarySettings.next_scheduled_date).toLocaleDateString('it-IT', { + weekday: 'long', + day: 'numeric', + month: 'short', + }), + time: `${weeklySummarySettings.hour}:00` + })} )} @@ -469,7 +464,7 @@ export default function NotificationSettingsScreen() { {weeklySummarySettings?.enabled && ( <> - Giorno della settimana + {t('notificationSettings.weeklySummary.day')} @@ -485,7 +480,7 @@ export default function NotificationSettingsScreen() { activeOpacity={0.7} > - {day.label} + {t(`notificationSettings.weeklySummary.days.${day.value}`)} ); @@ -493,7 +488,7 @@ export default function NotificationSettingsScreen() { - Orario + {t('notificationSettings.weeklySummary.hour')} Date: Thu, 14 May 2026 11:04:20 +0200 Subject: [PATCH 4/4] fix: correct WEEK_DAYS array access in weekly summary section Fix missing key prop error by correctly accessing the WEEK_DAYS array. WEEK_DAYS contains simple numbers [0-6], not objects with value property. Co-Authored-By: Claude Sonnet 4.6 --- src/navigation/screens/NotificationSettings.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/navigation/screens/NotificationSettings.tsx b/src/navigation/screens/NotificationSettings.tsx index 24aaa4c..01a1ea1 100644 --- a/src/navigation/screens/NotificationSettings.tsx +++ b/src/navigation/screens/NotificationSettings.tsx @@ -469,18 +469,18 @@ export default function NotificationSettingsScreen() { {WEEK_DAYS.map((day) => { - const isSelected = weeklySummarySettings.day === day.value; + const isSelected = weeklySummarySettings.day === day; const isSaving = savingField === 'weekly_day'; return ( handleWeeklySummaryDay(day.value)} + onPress={() => handleWeeklySummaryDay(day)} disabled={isSaving} activeOpacity={0.7} > - {t(`notificationSettings.weeklySummary.days.${day.value}`)} + {t(`notificationSettings.weeklySummary.days.${day}`)} );