@umituz/react-native-design-system 2.6.62 → 2.6.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/atoms/AtomicIcon.tsx +2 -6
- package/src/atoms/AtomicIcon.types.ts +5 -0
- package/src/atoms/AtomicInput.tsx +34 -154
- package/src/atoms/AtomicPicker.tsx +31 -123
- package/src/atoms/index.ts +6 -4
- package/src/atoms/input/components/InputHelper.tsx +49 -0
- package/src/atoms/input/components/InputIcon.tsx +44 -0
- package/src/atoms/input/components/InputLabel.tsx +20 -0
- package/src/atoms/input/styles/inputStylesHelper.ts +1 -1
- package/src/atoms/input/types.ts +72 -0
- package/src/atoms/picker/hooks/usePickerState.ts +139 -0
- package/src/exports/atoms.ts +69 -0
- package/src/exports/device.ts +58 -0
- package/src/exports/layouts.ts +19 -0
- package/src/exports/molecules.ts +166 -0
- package/src/exports/organisms.ts +9 -0
- package/src/exports/responsive.ts +36 -0
- package/src/exports/safe-area.ts +6 -0
- package/src/exports/theme.ts +47 -0
- package/src/exports/typography.ts +22 -0
- package/src/exports/utilities.ts +6 -0
- package/src/exports/variants.ts +22 -0
- package/src/index.ts +11 -417
- package/src/molecules/avatar/Avatar.constants.ts +103 -0
- package/src/molecules/avatar/Avatar.types.ts +64 -0
- package/src/molecules/avatar/Avatar.utils.ts +8 -160
- package/src/molecules/calendar/index.ts +4 -9
- package/src/molecules/calendar/infrastructure/storage/CalendarStore.ts +101 -301
- package/src/molecules/calendar/infrastructure/storage/CalendarStore.ts.bak +116 -0
- package/src/molecules/calendar/infrastructure/storage/CalendarStore.types.ts +64 -0
- package/src/molecules/calendar/infrastructure/storage/CalendarStore.utils.ts +56 -0
- package/src/molecules/calendar/infrastructure/storage/EventActions.ts +140 -0
- package/src/molecules/calendar/infrastructure/storage/NavigationActions.ts +118 -0
- package/src/molecules/calendar/infrastructure/stores/storageAdapter.ts +34 -0
- package/src/molecules/calendar/infrastructure/stores/useCalendarEvents.ts +168 -0
- package/src/molecules/calendar/infrastructure/stores/useCalendarNavigation.ts +47 -0
- package/src/molecules/calendar/infrastructure/stores/useCalendarView.ts +24 -0
- package/src/molecules/calendar/presentation/hooks/useCalendar.ts +7 -11
- package/src/responsive/compute/computeDeviceInfo.ts +22 -0
- package/src/responsive/compute/computeResponsivePositioning.ts +42 -0
- package/src/responsive/compute/computeResponsiveSizes.ts +48 -0
- package/src/responsive/padding/paddingUtils.ts +65 -0
- package/src/responsive/positioning/positioningUtils.ts +61 -0
- package/src/responsive/responsiveLayout.ts +11 -264
- package/src/responsive/screen/screenLayoutConfig.ts +38 -0
- package/src/responsive/tabbar/tabBarConfig.ts +88 -0
- package/src/responsive/types/responsiveTypes.ts +69 -0
- package/src/responsive/useResponsive.ts +69 -158
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar Store - Combined Hook
|
|
3
|
+
* Convenience hook that combines all calendar stores
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
import { useCalendarEvents } from '../stores/useCalendarEvents';
|
|
8
|
+
import { useCalendarNavigation } from '../stores/useCalendarNavigation';
|
|
9
|
+
import { useCalendarView } from '../stores/useCalendarView';
|
|
10
|
+
import { CalendarService } from '../../services/CalendarService';
|
|
11
|
+
import type { CalendarDay } from '../../../domain/entities/CalendarDay.entity';
|
|
12
|
+
|
|
13
|
+
// Export individual stores
|
|
14
|
+
export { useCalendarEvents } from '../stores/useCalendarEvents';
|
|
15
|
+
export { useCalendarNavigation } from '../stores/useCalendarNavigation';
|
|
16
|
+
export { useCalendarView } from '../stores/useCalendarView';
|
|
17
|
+
|
|
18
|
+
// Export types
|
|
19
|
+
export type { CalendarViewMode } from '../stores/useCalendarView';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Combined calendar hook
|
|
23
|
+
* Use this for convenience, or use individual stores for fine-grained control
|
|
24
|
+
*/
|
|
25
|
+
export const useCalendar = () => {
|
|
26
|
+
const events = useCalendarEvents();
|
|
27
|
+
const navigation = useCalendarNavigation();
|
|
28
|
+
const view = useCalendarView();
|
|
29
|
+
|
|
30
|
+
// Utility functions for backward compatibility
|
|
31
|
+
const getEventsForDate = (date: Date) => {
|
|
32
|
+
return events.events.filter(event => {
|
|
33
|
+
const eventDate = new Date(event.date);
|
|
34
|
+
return eventDate.toDateString() === date.toDateString();
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getEventsForMonth = (year: number, month: number) => {
|
|
39
|
+
return events.events.filter(event => {
|
|
40
|
+
const eventDate = new Date(event.date);
|
|
41
|
+
return eventDate.getFullYear() === year && eventDate.getMonth() === month;
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
// Events state and actions
|
|
47
|
+
events: events.events,
|
|
48
|
+
isLoading: events.isLoading,
|
|
49
|
+
error: events.error,
|
|
50
|
+
loadEvents: events.loadEvents,
|
|
51
|
+
addEvent: events.addEvent,
|
|
52
|
+
updateEvent: events.updateEvent,
|
|
53
|
+
deleteEvent: events.deleteEvent,
|
|
54
|
+
completeEvent: events.completeEvent,
|
|
55
|
+
uncompleteEvent: events.uncompleteEvent,
|
|
56
|
+
clearError: events.clearError,
|
|
57
|
+
clearAllEvents: events.clearAllEvents,
|
|
58
|
+
|
|
59
|
+
// Navigation state and actions
|
|
60
|
+
selectedDate: navigation.selectedDate,
|
|
61
|
+
currentMonth: navigation.currentMonth,
|
|
62
|
+
setSelectedDate: navigation.setSelectedDate,
|
|
63
|
+
goToToday: navigation.goToToday,
|
|
64
|
+
navigateMonth: navigation.navigateMonth,
|
|
65
|
+
setCurrentMonth: navigation.setCurrentMonth,
|
|
66
|
+
|
|
67
|
+
// View state and actions
|
|
68
|
+
viewMode: view.viewMode,
|
|
69
|
+
setViewMode: view.setViewMode,
|
|
70
|
+
|
|
71
|
+
// Utility functions
|
|
72
|
+
getEventsForDate,
|
|
73
|
+
getEventsForMonth,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Legacy alias for backward compatibility
|
|
79
|
+
* @deprecated Use useCalendar instead
|
|
80
|
+
*/
|
|
81
|
+
export const useCalendarStore = () => {
|
|
82
|
+
const calendar = useCalendar();
|
|
83
|
+
|
|
84
|
+
const days = useMemo(() => {
|
|
85
|
+
const year = calendar.currentMonth.getFullYear();
|
|
86
|
+
const month = calendar.currentMonth.getMonth();
|
|
87
|
+
return CalendarService.getMonthDays(year, month, calendar.events);
|
|
88
|
+
}, [calendar.currentMonth, calendar.events]);
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
events: calendar.events,
|
|
92
|
+
selectedDate: calendar.selectedDate,
|
|
93
|
+
currentMonth: calendar.currentMonth,
|
|
94
|
+
viewMode: calendar.viewMode,
|
|
95
|
+
isLoading: calendar.isLoading,
|
|
96
|
+
error: calendar.error,
|
|
97
|
+
actions: {
|
|
98
|
+
loadEvents: calendar.loadEvents,
|
|
99
|
+
addEvent: calendar.addEvent,
|
|
100
|
+
updateEvent: calendar.updateEvent,
|
|
101
|
+
deleteEvent: calendar.deleteEvent,
|
|
102
|
+
completeEvent: calendar.completeEvent,
|
|
103
|
+
uncompleteEvent: calendar.uncompleteEvent,
|
|
104
|
+
setSelectedDate: calendar.setSelectedDate,
|
|
105
|
+
goToToday: calendar.goToToday,
|
|
106
|
+
navigateMonth: calendar.navigateMonth,
|
|
107
|
+
setCurrentMonth: calendar.setCurrentMonth,
|
|
108
|
+
setViewMode: calendar.setViewMode,
|
|
109
|
+
getEventsForDate: calendar.getEventsForDate,
|
|
110
|
+
getEventsForMonth: calendar.getEventsForMonth,
|
|
111
|
+
clearError: calendar.clearError,
|
|
112
|
+
clearAllEvents: calendar.clearAllEvents,
|
|
113
|
+
},
|
|
114
|
+
days,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar Store Types
|
|
3
|
+
* Type definitions for calendar store
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { CalendarEvent, CreateCalendarEventRequest, UpdateCalendarEventRequest } from '../../domain/entities/CalendarEvent.entity';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Calendar view mode
|
|
10
|
+
*/
|
|
11
|
+
export type CalendarViewMode = 'month' | 'week' | 'day' | 'list';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Calendar state (data only)
|
|
15
|
+
*/
|
|
16
|
+
export interface CalendarState {
|
|
17
|
+
events: CalendarEvent[];
|
|
18
|
+
selectedDate: Date;
|
|
19
|
+
currentMonth: Date;
|
|
20
|
+
viewMode: CalendarViewMode;
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
error: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Calendar actions
|
|
27
|
+
*/
|
|
28
|
+
export interface CalendarActions {
|
|
29
|
+
// Event CRUD
|
|
30
|
+
loadEvents: () => Promise<void>;
|
|
31
|
+
addEvent: (request: CreateCalendarEventRequest) => Promise<void>;
|
|
32
|
+
updateEvent: (request: UpdateCalendarEventRequest) => Promise<void>;
|
|
33
|
+
deleteEvent: (id: string) => Promise<void>;
|
|
34
|
+
completeEvent: (id: string) => Promise<void>;
|
|
35
|
+
uncompleteEvent: (id: string) => Promise<void>;
|
|
36
|
+
|
|
37
|
+
// Navigation
|
|
38
|
+
setSelectedDate: (date: Date) => void;
|
|
39
|
+
goToToday: () => void;
|
|
40
|
+
navigateMonth: (direction: 'prev' | 'next') => void;
|
|
41
|
+
navigateWeek: (direction: 'prev' | 'next') => void;
|
|
42
|
+
setCurrentMonth: (date: Date) => void;
|
|
43
|
+
|
|
44
|
+
// View mode
|
|
45
|
+
setViewMode: (mode: CalendarViewMode) => void;
|
|
46
|
+
|
|
47
|
+
// Utilities
|
|
48
|
+
getEventsForDate: (date: Date) => CalendarEvent[];
|
|
49
|
+
getEventsForMonth: (year: number, month: number) => CalendarEvent[];
|
|
50
|
+
clearError: () => void;
|
|
51
|
+
clearAllEvents: () => Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Initial state
|
|
56
|
+
*/
|
|
57
|
+
export const initialState: CalendarState = {
|
|
58
|
+
events: [],
|
|
59
|
+
selectedDate: new Date(),
|
|
60
|
+
currentMonth: new Date(),
|
|
61
|
+
viewMode: 'month',
|
|
62
|
+
isLoading: false,
|
|
63
|
+
error: null,
|
|
64
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar Store Utilities
|
|
3
|
+
* Helper functions for calendar store operations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { CalendarEvent } from '../../domain/entities/CalendarEvent.entity';
|
|
7
|
+
import type { CalendarState } from './CalendarStore.types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Storage key for calendar events
|
|
11
|
+
*/
|
|
12
|
+
export const STORAGE_KEY = 'calendar_events';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generate unique ID for events
|
|
16
|
+
*/
|
|
17
|
+
export const generateId = (): string => {
|
|
18
|
+
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Hydrate date strings in events back to Date objects
|
|
23
|
+
*/
|
|
24
|
+
export const hydrateEvents = (events: CalendarEvent[]): CalendarEvent[] => {
|
|
25
|
+
return events.map((event) => ({
|
|
26
|
+
...event,
|
|
27
|
+
createdAt: new Date(event.createdAt),
|
|
28
|
+
updatedAt: new Date(event.updatedAt),
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Handle storage operation error
|
|
34
|
+
*/
|
|
35
|
+
export const handleStorageError = (
|
|
36
|
+
set: (state: Partial<CalendarState>) => void,
|
|
37
|
+
errorMessage: string
|
|
38
|
+
): void => {
|
|
39
|
+
set({
|
|
40
|
+
error: errorMessage,
|
|
41
|
+
isLoading: false,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Handle storage operation success
|
|
47
|
+
*/
|
|
48
|
+
export const handleStorageSuccess = (
|
|
49
|
+
set: (state: Partial<CalendarState>) => void,
|
|
50
|
+
updates: Partial<CalendarState>
|
|
51
|
+
): void => {
|
|
52
|
+
set({
|
|
53
|
+
...updates,
|
|
54
|
+
isLoading: false,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar Event Actions
|
|
3
|
+
* Event CRUD operations for calendar store
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { storageRepository, unwrap } from '@umituz/react-native-storage';
|
|
7
|
+
import type { CalendarEvent, CreateCalendarEventRequest, UpdateCalendarEventRequest } from '../../domain/entities/CalendarEvent.entity';
|
|
8
|
+
import { generateId, STORAGE_KEY, hydrateEvents, handleStorageError, handleStorageSuccess } from './CalendarStore.utils';
|
|
9
|
+
import type { CalendarState } from './CalendarStore.types';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Load events from storage
|
|
13
|
+
*/
|
|
14
|
+
export const loadEvents = async (
|
|
15
|
+
set: (state: Partial<CalendarState>) => void
|
|
16
|
+
): Promise<void> => {
|
|
17
|
+
set({ isLoading: true, error: null });
|
|
18
|
+
try {
|
|
19
|
+
const result = await storageRepository.getItem<CalendarEvent[]>(STORAGE_KEY, []);
|
|
20
|
+
const events = unwrap(result, []);
|
|
21
|
+
|
|
22
|
+
if (events && events.length > 0) {
|
|
23
|
+
const hydratedEvents = hydrateEvents(events);
|
|
24
|
+
set({ events: hydratedEvents, isLoading: false });
|
|
25
|
+
} else {
|
|
26
|
+
set({ isLoading: false });
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
handleStorageError(set, 'Failed to load events');
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Add a new event
|
|
35
|
+
*/
|
|
36
|
+
export const addEvent = async (
|
|
37
|
+
request: CreateCalendarEventRequest,
|
|
38
|
+
set: (state: Partial<CalendarState>) => void,
|
|
39
|
+
get: () => CalendarState
|
|
40
|
+
): Promise<void> => {
|
|
41
|
+
set({ isLoading: true, error: null });
|
|
42
|
+
try {
|
|
43
|
+
const newEvent: CalendarEvent = {
|
|
44
|
+
id: generateId(),
|
|
45
|
+
...request,
|
|
46
|
+
isCompleted: false,
|
|
47
|
+
createdAt: new Date(),
|
|
48
|
+
updatedAt: new Date(),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const events = [...get().events, newEvent];
|
|
52
|
+
await storageRepository.setItem(STORAGE_KEY, events);
|
|
53
|
+
handleStorageSuccess(set, { events });
|
|
54
|
+
} catch {
|
|
55
|
+
handleStorageError(set, 'Failed to add event');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Update an existing event
|
|
61
|
+
*/
|
|
62
|
+
export const updateEvent = async (
|
|
63
|
+
request: UpdateCalendarEventRequest,
|
|
64
|
+
set: (state: Partial<CalendarState>) => void,
|
|
65
|
+
get: () => CalendarState
|
|
66
|
+
): Promise<void> => {
|
|
67
|
+
set({ isLoading: true, error: null });
|
|
68
|
+
try {
|
|
69
|
+
const events = get().events.map((event) => {
|
|
70
|
+
if (event.id === request.id) {
|
|
71
|
+
return {
|
|
72
|
+
...event,
|
|
73
|
+
...request,
|
|
74
|
+
updatedAt: new Date(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return event;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await storageRepository.setItem(STORAGE_KEY, events);
|
|
81
|
+
handleStorageSuccess(set, { events });
|
|
82
|
+
} catch {
|
|
83
|
+
handleStorageError(set, 'Failed to update event');
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Delete an event
|
|
89
|
+
*/
|
|
90
|
+
export const deleteEvent = async (
|
|
91
|
+
id: string,
|
|
92
|
+
set: (state: Partial<CalendarState>) => void,
|
|
93
|
+
get: () => CalendarState
|
|
94
|
+
): Promise<void> => {
|
|
95
|
+
set({ isLoading: true, error: null });
|
|
96
|
+
try {
|
|
97
|
+
const events = get().events.filter((event) => event.id !== id);
|
|
98
|
+
await storageRepository.setItem(STORAGE_KEY, events);
|
|
99
|
+
handleStorageSuccess(set, { events });
|
|
100
|
+
} catch {
|
|
101
|
+
handleStorageError(set, 'Failed to delete event');
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Mark event as completed
|
|
107
|
+
*/
|
|
108
|
+
export const completeEvent = async (
|
|
109
|
+
id: string,
|
|
110
|
+
get: () => CalendarState,
|
|
111
|
+
updateEvent: (request: UpdateCalendarEventRequest) => Promise<void>
|
|
112
|
+
): Promise<void> => {
|
|
113
|
+
await updateEvent({ id, isCompleted: true });
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Mark event as incomplete
|
|
118
|
+
*/
|
|
119
|
+
export const uncompleteEvent = async (
|
|
120
|
+
id: string,
|
|
121
|
+
get: () => CalendarState,
|
|
122
|
+
updateEvent: (request: UpdateCalendarEventRequest) => Promise<void>
|
|
123
|
+
): Promise<void> => {
|
|
124
|
+
await updateEvent({ id, isCompleted: false });
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Clear all events (for testing/reset)
|
|
129
|
+
*/
|
|
130
|
+
export const clearAllEvents = async (
|
|
131
|
+
set: (state: Partial<CalendarState>) => void
|
|
132
|
+
): Promise<void> => {
|
|
133
|
+
set({ isLoading: true, error: null });
|
|
134
|
+
try {
|
|
135
|
+
await storageRepository.removeItem(STORAGE_KEY);
|
|
136
|
+
handleStorageSuccess(set, { events: [] });
|
|
137
|
+
} catch {
|
|
138
|
+
handleStorageError(set, 'Failed to clear events');
|
|
139
|
+
}
|
|
140
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar Navigation Actions
|
|
3
|
+
* Navigation and view mode operations for calendar store
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { CalendarService } from '../services/CalendarService';
|
|
7
|
+
import type { CalendarState, CalendarViewMode } from './CalendarStore.types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Set selected date
|
|
11
|
+
*/
|
|
12
|
+
export const setSelectedDate = (
|
|
13
|
+
date: Date,
|
|
14
|
+
set: (state: Partial<CalendarState>) => void
|
|
15
|
+
): void => {
|
|
16
|
+
set({ selectedDate: date });
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Go to today's date
|
|
21
|
+
*/
|
|
22
|
+
export const goToToday = (
|
|
23
|
+
set: (state: Partial<CalendarState>) => void
|
|
24
|
+
): void => {
|
|
25
|
+
const today = new Date();
|
|
26
|
+
set({
|
|
27
|
+
selectedDate: today,
|
|
28
|
+
currentMonth: today,
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Navigate to previous/next month
|
|
34
|
+
*/
|
|
35
|
+
export const navigateMonth = (
|
|
36
|
+
direction: 'prev' | 'next',
|
|
37
|
+
set: (state: Partial<CalendarState>) => void,
|
|
38
|
+
get: () => CalendarState
|
|
39
|
+
): void => {
|
|
40
|
+
const currentMonth = get().currentMonth;
|
|
41
|
+
const newMonth =
|
|
42
|
+
direction === 'prev'
|
|
43
|
+
? CalendarService.getPreviousMonth(currentMonth)
|
|
44
|
+
: CalendarService.getNextMonth(currentMonth);
|
|
45
|
+
|
|
46
|
+
set({ currentMonth: newMonth });
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Navigate to previous/next week
|
|
51
|
+
*/
|
|
52
|
+
export const navigateWeek = (
|
|
53
|
+
direction: 'prev' | 'next',
|
|
54
|
+
set: (state: Partial<CalendarState>) => void,
|
|
55
|
+
get: () => CalendarState
|
|
56
|
+
): void => {
|
|
57
|
+
const selectedDate = get().selectedDate;
|
|
58
|
+
const newDate =
|
|
59
|
+
direction === 'prev'
|
|
60
|
+
? CalendarService.getPreviousWeek(selectedDate)
|
|
61
|
+
: CalendarService.getNextWeek(selectedDate);
|
|
62
|
+
|
|
63
|
+
set({ selectedDate: newDate });
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Set current month directly
|
|
68
|
+
*/
|
|
69
|
+
export const setCurrentMonth = (
|
|
70
|
+
date: Date,
|
|
71
|
+
set: (state: Partial<CalendarState>) => void
|
|
72
|
+
): void => {
|
|
73
|
+
set({ currentMonth: date });
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Set view mode
|
|
78
|
+
*/
|
|
79
|
+
export const setViewMode = (
|
|
80
|
+
mode: CalendarViewMode,
|
|
81
|
+
set: (state: Partial<CalendarState>) => void
|
|
82
|
+
): void => {
|
|
83
|
+
set({ viewMode: mode });
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get events for a specific date
|
|
88
|
+
*/
|
|
89
|
+
export const getEventsForDate = (
|
|
90
|
+
date: Date,
|
|
91
|
+
get: () => CalendarState
|
|
92
|
+
): ReturnType<typeof CalendarService.getEventsForDate> => {
|
|
93
|
+
const events = get().events;
|
|
94
|
+
return CalendarService.getEventsForDate(date, events);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get events for a specific month
|
|
99
|
+
*/
|
|
100
|
+
export const getEventsForMonth = (
|
|
101
|
+
year: number,
|
|
102
|
+
month: number,
|
|
103
|
+
get: () => CalendarState
|
|
104
|
+
): ReturnType<typeof CalendarService.getEventsInRange> => {
|
|
105
|
+
const events = get().events;
|
|
106
|
+
const firstDay = new Date(year, month, 1);
|
|
107
|
+
const lastDay = new Date(year, month + 1, 0);
|
|
108
|
+
return CalendarService.getEventsInRange(firstDay, lastDay, events);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Clear error state
|
|
113
|
+
*/
|
|
114
|
+
export const clearError = (
|
|
115
|
+
set: (state: Partial<CalendarState>) => void
|
|
116
|
+
): void => {
|
|
117
|
+
set({ error: null });
|
|
118
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncStorage Adapter for Zustand Persist
|
|
3
|
+
* Converts AsyncStorageRepository to Zustand-compatible storage
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { storageRepository } from '@umituz/react-native-storage';
|
|
7
|
+
|
|
8
|
+
export const zustandStorage = {
|
|
9
|
+
getItem: async (name: string): Promise<string | null> => {
|
|
10
|
+
try {
|
|
11
|
+
const result = await storageRepository.getItem<string>(name, '');
|
|
12
|
+
if (result.success && result.data !== undefined) {
|
|
13
|
+
return result.data;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
setItem: async (name: string, value: string): Promise<void> => {
|
|
21
|
+
try {
|
|
22
|
+
await storageRepository.setItem(name, value);
|
|
23
|
+
} catch {
|
|
24
|
+
// Silent fail
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
removeItem: async (name: string): Promise<void> => {
|
|
28
|
+
try {
|
|
29
|
+
await storageRepository.removeItem(name);
|
|
30
|
+
} catch {
|
|
31
|
+
// Silent fail
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar Events Store
|
|
3
|
+
* Manages event CRUD operations only
|
|
4
|
+
* Uses manual persistence (no zustand persist middleware)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { create } from 'zustand';
|
|
8
|
+
import type { CalendarEvent, CreateCalendarEventRequest, UpdateCalendarEventRequest } from '../../domain/entities/CalendarEvent.entity';
|
|
9
|
+
import { zustandStorage } from './storageAdapter';
|
|
10
|
+
|
|
11
|
+
const STORAGE_KEY = 'calendar_events';
|
|
12
|
+
|
|
13
|
+
interface CalendarEventsState {
|
|
14
|
+
readonly events: CalendarEvent[];
|
|
15
|
+
readonly isLoading: boolean;
|
|
16
|
+
readonly error: string | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface CalendarEventsActions {
|
|
20
|
+
readonly loadEvents: () => Promise<void>;
|
|
21
|
+
readonly addEvent: (request: CreateCalendarEventRequest) => Promise<void>;
|
|
22
|
+
readonly updateEvent: (request: UpdateCalendarEventRequest) => Promise<void>;
|
|
23
|
+
readonly deleteEvent: (id: string) => Promise<void>;
|
|
24
|
+
readonly completeEvent: (id: string) => Promise<void>;
|
|
25
|
+
readonly uncompleteEvent: (id: string) => Promise<void>;
|
|
26
|
+
readonly clearError: () => void;
|
|
27
|
+
readonly clearAllEvents: () => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type CalendarEventsStore = CalendarEventsState & CalendarEventsActions;
|
|
31
|
+
|
|
32
|
+
const generateId = (): string => `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
33
|
+
|
|
34
|
+
const persistEvents = async (events: CalendarEvent[]): Promise<void> => {
|
|
35
|
+
try {
|
|
36
|
+
await zustandStorage.setItem(STORAGE_KEY, JSON.stringify(events));
|
|
37
|
+
} catch {
|
|
38
|
+
// Silent fail
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const useCalendarEvents = create<CalendarEventsStore>()((set, get) => ({
|
|
43
|
+
events: [],
|
|
44
|
+
isLoading: false,
|
|
45
|
+
error: null,
|
|
46
|
+
|
|
47
|
+
loadEvents: async () => {
|
|
48
|
+
set({ isLoading: true, error: null });
|
|
49
|
+
try {
|
|
50
|
+
const json = await zustandStorage.getItem(STORAGE_KEY);
|
|
51
|
+
if (!json) {
|
|
52
|
+
set({ isLoading: false });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const events = JSON.parse(json) as CalendarEvent[];
|
|
57
|
+
|
|
58
|
+
if (events && events.length > 0) {
|
|
59
|
+
const hydratedEvents = events.map((event) => ({
|
|
60
|
+
...event,
|
|
61
|
+
createdAt: new Date(event.createdAt),
|
|
62
|
+
updatedAt: new Date(event.updatedAt),
|
|
63
|
+
}));
|
|
64
|
+
set({ events: hydratedEvents, isLoading: false });
|
|
65
|
+
} else {
|
|
66
|
+
set({ isLoading: false });
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
set({ error: 'Failed to load events', isLoading: false });
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
addEvent: async (request) => {
|
|
74
|
+
set({ isLoading: true, error: null });
|
|
75
|
+
try {
|
|
76
|
+
const newEvent: CalendarEvent = {
|
|
77
|
+
id: generateId(),
|
|
78
|
+
...request,
|
|
79
|
+
createdAt: new Date(),
|
|
80
|
+
updatedAt: new Date(),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const { events } = get();
|
|
84
|
+
const updatedEvents = [...events, newEvent];
|
|
85
|
+
|
|
86
|
+
await persistEvents(updatedEvents);
|
|
87
|
+
set({ events: updatedEvents, isLoading: false });
|
|
88
|
+
} catch {
|
|
89
|
+
set({ error: 'Failed to add event', isLoading: false });
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
updateEvent: async (request) => {
|
|
94
|
+
set({ isLoading: true, error: null });
|
|
95
|
+
try {
|
|
96
|
+
const { events } = get();
|
|
97
|
+
const updatedEvents = events.map((event) =>
|
|
98
|
+
event.id === request.id
|
|
99
|
+
? { ...event, ...request, updatedAt: new Date() }
|
|
100
|
+
: event
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
await persistEvents(updatedEvents);
|
|
104
|
+
set({ events: updatedEvents, isLoading: false });
|
|
105
|
+
} catch {
|
|
106
|
+
set({ error: 'Failed to update event', isLoading: false });
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
deleteEvent: async (id) => {
|
|
111
|
+
set({ isLoading: true, error: null });
|
|
112
|
+
try {
|
|
113
|
+
const { events } = get();
|
|
114
|
+
const updatedEvents = events.filter((event) => event.id !== id);
|
|
115
|
+
|
|
116
|
+
await persistEvents(updatedEvents);
|
|
117
|
+
set({ events: updatedEvents, isLoading: false });
|
|
118
|
+
} catch {
|
|
119
|
+
set({ error: 'Failed to delete event', isLoading: false });
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
completeEvent: async (id) => {
|
|
124
|
+
set({ isLoading: true, error: null });
|
|
125
|
+
try {
|
|
126
|
+
const { events } = get();
|
|
127
|
+
const updatedEvents = events.map((event) =>
|
|
128
|
+
event.id === id
|
|
129
|
+
? { ...event, completed: true, updatedAt: new Date() }
|
|
130
|
+
: event
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
await persistEvents(updatedEvents);
|
|
134
|
+
set({ events: updatedEvents, isLoading: false });
|
|
135
|
+
} catch {
|
|
136
|
+
set({ error: 'Failed to complete event', isLoading: false });
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
uncompleteEvent: async (id) => {
|
|
141
|
+
set({ isLoading: true, error: null });
|
|
142
|
+
try {
|
|
143
|
+
const { events } = get();
|
|
144
|
+
const updatedEvents = events.map((event) =>
|
|
145
|
+
event.id === id
|
|
146
|
+
? { ...event, completed: false, updatedAt: new Date() }
|
|
147
|
+
: event
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
await persistEvents(updatedEvents);
|
|
151
|
+
set({ events: updatedEvents, isLoading: false });
|
|
152
|
+
} catch {
|
|
153
|
+
set({ error: 'Failed to uncomplete event', isLoading: false });
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
clearError: () => set({ error: null }),
|
|
158
|
+
|
|
159
|
+
clearAllEvents: async () => {
|
|
160
|
+
set({ isLoading: true, error: null });
|
|
161
|
+
try {
|
|
162
|
+
await zustandStorage.removeItem(STORAGE_KEY);
|
|
163
|
+
set({ events: [], isLoading: false });
|
|
164
|
+
} catch {
|
|
165
|
+
set({ error: 'Failed to clear events', isLoading: false });
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
}));
|