@wasto/cms-components 1.5.10 → 1.5.11
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/README.md +47 -47
- package/dist/index.d.mts +103 -2
- package/dist/index.d.ts +103 -2
- package/dist/index.js +2861 -2442
- package/dist/index.mjs +3651 -3227
- package/package.json +2 -2
- package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
- package/src/components/article/Article.tsx +21 -21
- package/src/components/article/ArticleCard.tsx +81 -81
- package/src/components/article/ArticleExcerpts.tsx +80 -80
- package/src/components/article/ArticleList.tsx +114 -114
- package/src/components/article/ArticleMarkdown.tsx +170 -170
- package/src/components/article/ArticleReaderModal.tsx +93 -93
- package/src/components/article/ArticleSingle.tsx +57 -57
- package/src/components/bottom-tab/BottomTab.tsx +392 -392
- package/src/components/button/Button.tsx +154 -154
- package/src/components/challenge/Badges.tsx +84 -84
- package/src/components/challenge/BadgesModal.tsx +166 -166
- package/src/components/challenge/Challenge.tsx +380 -380
- package/src/components/challenge/ChallengeModal.tsx +231 -231
- package/src/components/challenge/ChallengeVignette.tsx +249 -249
- package/src/components/challenge/ChallengesModal.tsx +243 -243
- package/src/components/challenge/QuizModal.tsx +381 -381
- package/src/components/challenge/ResultModal.tsx +144 -144
- package/src/components/chat/Chat.tsx +928 -928
- package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
- package/src/components/columns/Columns.tsx +33 -33
- package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
- package/src/components/content-inset/ContentInset.tsx +33 -33
- package/src/components/header/Header.tsx +391 -391
- package/src/components/image/Image.tsx +15 -15
- package/src/components/image/ImageFrame.tsx +102 -102
- package/src/components/image/ImageMedia.tsx +31 -31
- package/src/components/image/ImageUrl.tsx +30 -30
- package/src/components/locations-map/LocationSheet.tsx +417 -417
- package/src/components/locations-map/LocationsMap.native.tsx +260 -260
- package/src/components/locations-map/LocationsMap.tsx +13 -13
- package/src/components/locations-map/LocationsMap.web.tsx +10 -10
- package/src/components/locations-map/LocationsMapShell.tsx +527 -527
- package/src/components/locations-map/LocationsMapView.tsx +108 -108
- package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
- package/src/components/nav-button/NavButton.tsx +59 -59
- package/src/components/next-collection/NextCollection.tsx +636 -621
- package/src/components/notifications/NotificationsScreen.tsx +247 -247
- package/src/components/page/Page.tsx +102 -64
- package/src/components/parapraph/Paragraph.tsx +67 -67
- package/src/components/profile/ProfileScreen.tsx +236 -236
- package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
- package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
- package/src/components/search/Search.tsx +320 -320
- package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
- package/src/components/title/Title.tsx +100 -100
- package/src/components/vision/Vision.tsx +447 -447
- package/src/components/vision/VisionActionCard.tsx +117 -117
- package/src/components/vision/VisionCapture.tsx +30 -30
- package/src/components/vision/VisionTapOverlay.tsx +122 -122
- package/src/contexts/AnnouncementsContext.tsx +171 -171
- package/src/contexts/AppDataContext.tsx +458 -0
- package/src/contexts/ChallengesContext.tsx +182 -182
- package/src/contexts/LocalContext.tsx +227 -227
- package/src/contexts/ThemeContext.tsx +37 -37
- package/src/contexts/WastoContext.tsx +130 -127
- package/src/helpers/blogPost.ts +72 -72
- package/src/helpers/generateQuizQuestions.ts +247 -247
- package/src/helpers/getContrastColor.ts +18 -18
- package/src/helpers/haptics.ts +20 -20
- package/src/helpers/hoursSchedule.ts +230 -230
- package/src/helpers/htmlContentToMarkdown.ts +114 -114
- package/src/helpers/layout.ts +54 -54
- package/src/helpers/loadLinearGradient.ts +22 -22
- package/src/helpers/mapLocations.ts +170 -0
- package/src/helpers/maquetteTheme.ts +76 -76
- package/src/helpers/markdownUnderlinePlugin.ts +32 -32
- package/src/helpers/nextCollection.ts +122 -0
- package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
- package/src/helpers/publicMediaUrl.ts +8 -8
- package/src/helpers/resolveApiAssetUrl.ts +21 -21
- package/src/helpers/systemRoutes.ts +7 -7
- package/src/helpers/themeStyles.ts +114 -114
- package/src/helpers/ttlCache.ts +41 -0
- package/src/helpers/useSafeAreaPadding.ts +14 -14
- package/src/hooks/useBadges.ts +100 -100
- package/src/hooks/useBlogPosts.ts +109 -105
- package/src/hooks/useChallenges.ts +110 -110
- package/src/hooks/useCities.ts +56 -56
- package/src/hooks/useCityAnnouncements.ts +118 -118
- package/src/hooks/useCollectionCalendar.ts +421 -421
- package/src/hooks/useColumns.ts +19 -19
- package/src/hooks/useConsignes.ts +62 -62
- package/src/hooks/useLocations.ts +120 -248
- package/src/hooks/useNextCollection.ts +163 -238
- package/src/hooks/useRecyclingInfo.ts +90 -90
- package/src/hooks/useWastoClient.ts +16 -16
- package/src/index.ts +149 -142
- package/src/navigation/NavigationContext.tsx +56 -56
- package/src/sentry/initSentry.ts +120 -120
- package/src/types/Theme.ts +72 -72
- package/src/types/css-modules.d.ts +1 -1
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
|
-
import {
|
|
3
|
-
createContext,
|
|
4
|
-
PropsWithChildren,
|
|
5
|
-
useCallback,
|
|
6
|
-
useContext,
|
|
7
|
-
useEffect,
|
|
8
|
-
useMemo,
|
|
9
|
-
useState,
|
|
10
|
-
type ReactNode,
|
|
11
|
-
} from "react";
|
|
12
|
-
import { useLocal } from "./LocalContext";
|
|
13
|
-
import { useWastoClient } from "../hooks/useWastoClient";
|
|
14
|
-
|
|
15
|
-
export type PublicAnnouncement = {
|
|
16
|
-
id: string;
|
|
17
|
-
title: string;
|
|
18
|
-
body: string;
|
|
19
|
-
imageUrl?: string | null;
|
|
20
|
-
sentAt?: string | null;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type AnnouncementsContextType = {
|
|
24
|
-
announcement: PublicAnnouncement | null;
|
|
25
|
-
hasUnread: boolean;
|
|
26
|
-
dismiss: () => Promise<void>;
|
|
27
|
-
/** Mark one announcement as read (inbox) and refresh unread badge. */
|
|
28
|
-
markAsRead: (id: string) => Promise<void>;
|
|
29
|
-
/** Open the shared AnnouncementModal for a specific item (inbox). */
|
|
30
|
-
openAnnouncement: (item: PublicAnnouncement) => void;
|
|
31
|
-
openFromBell: () => Promise<void>;
|
|
32
|
-
forceVisible: boolean;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const DISMISSED_KEY = "dismissed_announcements";
|
|
36
|
-
|
|
37
|
-
const AnnouncementsContext = createContext<AnnouncementsContextType | undefined>(undefined);
|
|
38
|
-
|
|
39
|
-
async function getDismissedIds(): Promise<Set<string>> {
|
|
40
|
-
try {
|
|
41
|
-
const raw = await AsyncStorage.getItem(DISMISSED_KEY);
|
|
42
|
-
if (!raw) return new Set();
|
|
43
|
-
const parsed = JSON.parse(raw) as string[];
|
|
44
|
-
return new Set(Array.isArray(parsed) ? parsed : []);
|
|
45
|
-
} catch {
|
|
46
|
-
return new Set();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function markDismissed(id: string): Promise<void> {
|
|
51
|
-
const set = await getDismissedIds();
|
|
52
|
-
set.add(id);
|
|
53
|
-
await AsyncStorage.setItem(DISMISSED_KEY, JSON.stringify([...set]));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function resolveImageUrl(apiUrl: string, url?: string | null): string | null {
|
|
57
|
-
if (!url) return null;
|
|
58
|
-
if (url.startsWith("http://") || url.startsWith("https://")) return url;
|
|
59
|
-
const base = apiUrl.replace(/\/$/, "");
|
|
60
|
-
const path = url.startsWith("/") ? url : `/${url}`;
|
|
61
|
-
return `${base}${path}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export type AnnouncementsProviderProps = PropsWithChildren & {
|
|
65
|
-
apiUrl: string;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export function AnnouncementsProvider({ children, apiUrl }: AnnouncementsProviderProps): ReactNode {
|
|
69
|
-
const { selectedCityId, hasPlaceSelected } = useLocal();
|
|
70
|
-
const client = useWastoClient();
|
|
71
|
-
const [announcement, setAnnouncement] = useState<PublicAnnouncement | null>(null);
|
|
72
|
-
const [hasUnread, setHasUnread] = useState(false);
|
|
73
|
-
const [forceVisible, setForceVisible] = useState(false);
|
|
74
|
-
const [queue, setQueue] = useState<PublicAnnouncement[]>([]);
|
|
75
|
-
|
|
76
|
-
const load = useCallback(async (): Promise<PublicAnnouncement[]> => {
|
|
77
|
-
if (!selectedCityId || !hasPlaceSelected) {
|
|
78
|
-
setAnnouncement(null);
|
|
79
|
-
setHasUnread(false);
|
|
80
|
-
setQueue([]);
|
|
81
|
-
return [];
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
const list = await client.public.announcements.listForCity(selectedCityId);
|
|
85
|
-
const dismissed = await getDismissedIds();
|
|
86
|
-
const pending = (list ?? [])
|
|
87
|
-
.filter((a) => a?.id && !dismissed.has(a.id))
|
|
88
|
-
.map((a) => ({
|
|
89
|
-
...a,
|
|
90
|
-
imageUrl: resolveImageUrl(apiUrl, a.imageUrl),
|
|
91
|
-
}));
|
|
92
|
-
setQueue(pending);
|
|
93
|
-
setHasUnread(pending.length > 0);
|
|
94
|
-
setAnnouncement(pending[0] ?? null);
|
|
95
|
-
return pending;
|
|
96
|
-
} catch {
|
|
97
|
-
setAnnouncement(null);
|
|
98
|
-
setHasUnread(false);
|
|
99
|
-
setQueue([]);
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
}, [apiUrl, client.public.announcements, hasPlaceSelected, selectedCityId]);
|
|
103
|
-
|
|
104
|
-
useEffect(() => {
|
|
105
|
-
void load().then((pending) => {
|
|
106
|
-
if (pending.length > 0) setForceVisible(true);
|
|
107
|
-
});
|
|
108
|
-
}, [load]);
|
|
109
|
-
|
|
110
|
-
const markAsRead = useCallback(async (id: string) => {
|
|
111
|
-
await markDismissed(id);
|
|
112
|
-
setQueue((prev) => {
|
|
113
|
-
const next = prev.filter((a) => a.id !== id);
|
|
114
|
-
setHasUnread(next.length > 0);
|
|
115
|
-
return next;
|
|
116
|
-
});
|
|
117
|
-
}, []);
|
|
118
|
-
|
|
119
|
-
const dismiss = useCallback(async () => {
|
|
120
|
-
if (!announcement) {
|
|
121
|
-
setForceVisible(false);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const id = announcement.id;
|
|
125
|
-
await markDismissed(id);
|
|
126
|
-
const nextQueue = queue.filter((a) => a.id !== id);
|
|
127
|
-
setQueue(nextQueue);
|
|
128
|
-
setHasUnread(nextQueue.length > 0);
|
|
129
|
-
setAnnouncement(nextQueue[0] ?? null);
|
|
130
|
-
setForceVisible(nextQueue.length > 0);
|
|
131
|
-
}, [announcement, queue]);
|
|
132
|
-
|
|
133
|
-
const openAnnouncement = useCallback((item: PublicAnnouncement) => {
|
|
134
|
-
setAnnouncement(item);
|
|
135
|
-
setForceVisible(true);
|
|
136
|
-
}, []);
|
|
137
|
-
|
|
138
|
-
const openFromBell = useCallback(async () => {
|
|
139
|
-
const pending = queue.length > 0 ? queue : await load();
|
|
140
|
-
if (pending.length === 0) return;
|
|
141
|
-
setAnnouncement(pending[0] ?? null);
|
|
142
|
-
setForceVisible(true);
|
|
143
|
-
}, [load, queue]);
|
|
144
|
-
|
|
145
|
-
const value = useMemo(
|
|
146
|
-
() => ({
|
|
147
|
-
announcement,
|
|
148
|
-
hasUnread,
|
|
149
|
-
dismiss,
|
|
150
|
-
markAsRead,
|
|
151
|
-
openAnnouncement,
|
|
152
|
-
openFromBell,
|
|
153
|
-
forceVisible,
|
|
154
|
-
}),
|
|
155
|
-
[announcement, dismiss, forceVisible, hasUnread, markAsRead, openAnnouncement, openFromBell],
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
return (
|
|
159
|
-
<AnnouncementsContext value={value}>
|
|
160
|
-
{children}
|
|
161
|
-
</AnnouncementsContext>
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function useAnnouncements() {
|
|
166
|
-
const ctx = useContext(AnnouncementsContext);
|
|
167
|
-
if (!ctx) {
|
|
168
|
-
throw new Error("useAnnouncements must be used within AnnouncementsProvider.");
|
|
169
|
-
}
|
|
170
|
-
return ctx;
|
|
171
|
-
}
|
|
1
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
PropsWithChildren,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useState,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { useLocal } from "./LocalContext";
|
|
13
|
+
import { useWastoClient } from "../hooks/useWastoClient";
|
|
14
|
+
|
|
15
|
+
export type PublicAnnouncement = {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
body: string;
|
|
19
|
+
imageUrl?: string | null;
|
|
20
|
+
sentAt?: string | null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type AnnouncementsContextType = {
|
|
24
|
+
announcement: PublicAnnouncement | null;
|
|
25
|
+
hasUnread: boolean;
|
|
26
|
+
dismiss: () => Promise<void>;
|
|
27
|
+
/** Mark one announcement as read (inbox) and refresh unread badge. */
|
|
28
|
+
markAsRead: (id: string) => Promise<void>;
|
|
29
|
+
/** Open the shared AnnouncementModal for a specific item (inbox). */
|
|
30
|
+
openAnnouncement: (item: PublicAnnouncement) => void;
|
|
31
|
+
openFromBell: () => Promise<void>;
|
|
32
|
+
forceVisible: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const DISMISSED_KEY = "dismissed_announcements";
|
|
36
|
+
|
|
37
|
+
const AnnouncementsContext = createContext<AnnouncementsContextType | undefined>(undefined);
|
|
38
|
+
|
|
39
|
+
async function getDismissedIds(): Promise<Set<string>> {
|
|
40
|
+
try {
|
|
41
|
+
const raw = await AsyncStorage.getItem(DISMISSED_KEY);
|
|
42
|
+
if (!raw) return new Set();
|
|
43
|
+
const parsed = JSON.parse(raw) as string[];
|
|
44
|
+
return new Set(Array.isArray(parsed) ? parsed : []);
|
|
45
|
+
} catch {
|
|
46
|
+
return new Set();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function markDismissed(id: string): Promise<void> {
|
|
51
|
+
const set = await getDismissedIds();
|
|
52
|
+
set.add(id);
|
|
53
|
+
await AsyncStorage.setItem(DISMISSED_KEY, JSON.stringify([...set]));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function resolveImageUrl(apiUrl: string, url?: string | null): string | null {
|
|
57
|
+
if (!url) return null;
|
|
58
|
+
if (url.startsWith("http://") || url.startsWith("https://")) return url;
|
|
59
|
+
const base = apiUrl.replace(/\/$/, "");
|
|
60
|
+
const path = url.startsWith("/") ? url : `/${url}`;
|
|
61
|
+
return `${base}${path}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type AnnouncementsProviderProps = PropsWithChildren & {
|
|
65
|
+
apiUrl: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export function AnnouncementsProvider({ children, apiUrl }: AnnouncementsProviderProps): ReactNode {
|
|
69
|
+
const { selectedCityId, hasPlaceSelected } = useLocal();
|
|
70
|
+
const client = useWastoClient();
|
|
71
|
+
const [announcement, setAnnouncement] = useState<PublicAnnouncement | null>(null);
|
|
72
|
+
const [hasUnread, setHasUnread] = useState(false);
|
|
73
|
+
const [forceVisible, setForceVisible] = useState(false);
|
|
74
|
+
const [queue, setQueue] = useState<PublicAnnouncement[]>([]);
|
|
75
|
+
|
|
76
|
+
const load = useCallback(async (): Promise<PublicAnnouncement[]> => {
|
|
77
|
+
if (!selectedCityId || !hasPlaceSelected) {
|
|
78
|
+
setAnnouncement(null);
|
|
79
|
+
setHasUnread(false);
|
|
80
|
+
setQueue([]);
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const list = await client.public.announcements.listForCity(selectedCityId);
|
|
85
|
+
const dismissed = await getDismissedIds();
|
|
86
|
+
const pending = (list ?? [])
|
|
87
|
+
.filter((a) => a?.id && !dismissed.has(a.id))
|
|
88
|
+
.map((a) => ({
|
|
89
|
+
...a,
|
|
90
|
+
imageUrl: resolveImageUrl(apiUrl, a.imageUrl),
|
|
91
|
+
}));
|
|
92
|
+
setQueue(pending);
|
|
93
|
+
setHasUnread(pending.length > 0);
|
|
94
|
+
setAnnouncement(pending[0] ?? null);
|
|
95
|
+
return pending;
|
|
96
|
+
} catch {
|
|
97
|
+
setAnnouncement(null);
|
|
98
|
+
setHasUnread(false);
|
|
99
|
+
setQueue([]);
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}, [apiUrl, client.public.announcements, hasPlaceSelected, selectedCityId]);
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
void load().then((pending) => {
|
|
106
|
+
if (pending.length > 0) setForceVisible(true);
|
|
107
|
+
});
|
|
108
|
+
}, [load]);
|
|
109
|
+
|
|
110
|
+
const markAsRead = useCallback(async (id: string) => {
|
|
111
|
+
await markDismissed(id);
|
|
112
|
+
setQueue((prev) => {
|
|
113
|
+
const next = prev.filter((a) => a.id !== id);
|
|
114
|
+
setHasUnread(next.length > 0);
|
|
115
|
+
return next;
|
|
116
|
+
});
|
|
117
|
+
}, []);
|
|
118
|
+
|
|
119
|
+
const dismiss = useCallback(async () => {
|
|
120
|
+
if (!announcement) {
|
|
121
|
+
setForceVisible(false);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const id = announcement.id;
|
|
125
|
+
await markDismissed(id);
|
|
126
|
+
const nextQueue = queue.filter((a) => a.id !== id);
|
|
127
|
+
setQueue(nextQueue);
|
|
128
|
+
setHasUnread(nextQueue.length > 0);
|
|
129
|
+
setAnnouncement(nextQueue[0] ?? null);
|
|
130
|
+
setForceVisible(nextQueue.length > 0);
|
|
131
|
+
}, [announcement, queue]);
|
|
132
|
+
|
|
133
|
+
const openAnnouncement = useCallback((item: PublicAnnouncement) => {
|
|
134
|
+
setAnnouncement(item);
|
|
135
|
+
setForceVisible(true);
|
|
136
|
+
}, []);
|
|
137
|
+
|
|
138
|
+
const openFromBell = useCallback(async () => {
|
|
139
|
+
const pending = queue.length > 0 ? queue : await load();
|
|
140
|
+
if (pending.length === 0) return;
|
|
141
|
+
setAnnouncement(pending[0] ?? null);
|
|
142
|
+
setForceVisible(true);
|
|
143
|
+
}, [load, queue]);
|
|
144
|
+
|
|
145
|
+
const value = useMemo(
|
|
146
|
+
() => ({
|
|
147
|
+
announcement,
|
|
148
|
+
hasUnread,
|
|
149
|
+
dismiss,
|
|
150
|
+
markAsRead,
|
|
151
|
+
openAnnouncement,
|
|
152
|
+
openFromBell,
|
|
153
|
+
forceVisible,
|
|
154
|
+
}),
|
|
155
|
+
[announcement, dismiss, forceVisible, hasUnread, markAsRead, openAnnouncement, openFromBell],
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<AnnouncementsContext value={value}>
|
|
160
|
+
{children}
|
|
161
|
+
</AnnouncementsContext>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function useAnnouncements() {
|
|
166
|
+
const ctx = useContext(AnnouncementsContext);
|
|
167
|
+
if (!ctx) {
|
|
168
|
+
throw new Error("useAnnouncements must be used within AnnouncementsProvider.");
|
|
169
|
+
}
|
|
170
|
+
return ctx;
|
|
171
|
+
}
|