@wasto/cms-components 1.5.10 → 1.5.12
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 +181 -51
- package/dist/index.d.ts +181 -51
- package/dist/index.js +3614 -3015
- package/dist/index.mjs +3021 -2418
- package/package.json +12 -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 +415 -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 +546 -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/push/PushTokenRegistrar.tsx +47 -0
- 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/HeaderConfigContext.tsx +29 -0
- package/src/contexts/LocalContext.tsx +227 -227
- package/src/contexts/ThemeContext.tsx +37 -37
- package/src/contexts/WastoContext.tsx +132 -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 +161 -142
- package/src/navigation/NavigationContext.tsx +56 -56
- package/src/push/registerExpoPushToken.ts +133 -0
- package/src/sentry/initSentry.ts +120 -120
- package/src/types/Theme.ts +72 -72
- package/src/types/css-modules.d.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -1,142 +1,161 @@
|
|
|
1
|
-
export {
|
|
2
|
-
Article,
|
|
3
|
-
type ArticleProps,
|
|
4
|
-
type ArticleDisplayMode
|
|
5
|
-
} from "./components/article/Article"
|
|
6
|
-
export {
|
|
7
|
-
Challenge,
|
|
8
|
-
type ChallengeProps
|
|
9
|
-
} from "./components/challenge/Challenge"
|
|
10
|
-
export {
|
|
11
|
-
ChallengeVignette,
|
|
12
|
-
type ChallengeVignetteProps
|
|
13
|
-
} from "./components/challenge/ChallengeVignette"
|
|
14
|
-
export {
|
|
15
|
-
Chat,
|
|
16
|
-
type ChatProps
|
|
17
|
-
} from "./components/chat/Chat"
|
|
18
|
-
export {
|
|
19
|
-
CollectionCalendar,
|
|
20
|
-
type CollectionCalendarProps
|
|
21
|
-
} from "./components/collection-calendar/CollectionCalendar"
|
|
22
|
-
export {
|
|
23
|
-
Columns,
|
|
24
|
-
type ColumnsProps,
|
|
25
|
-
type ColumnsColumnCount
|
|
26
|
-
} from "./components/columns/Columns"
|
|
27
|
-
export {
|
|
28
|
-
Image,
|
|
29
|
-
ImageProps,
|
|
30
|
-
} from "./components/image/Image"
|
|
31
|
-
export {
|
|
32
|
-
LocationsMap,
|
|
33
|
-
type LocationsMapProps
|
|
34
|
-
} from "./components/locations-map/LocationsMap"
|
|
35
|
-
export {
|
|
36
|
-
NextCollection,
|
|
37
|
-
type NextCollectionProps
|
|
38
|
-
} from "./components/next-collection/NextCollection"
|
|
39
|
-
export {
|
|
40
|
-
Page,
|
|
41
|
-
type PageProps
|
|
42
|
-
} from "./components/page/Page"
|
|
43
|
-
export {
|
|
44
|
-
ContentInset,
|
|
45
|
-
type ContentInsetProps
|
|
46
|
-
} from "./components/content-inset/ContentInset"
|
|
47
|
-
export {
|
|
48
|
-
Paragraph,
|
|
49
|
-
type PararaphProps
|
|
50
|
-
} from "./components/parapraph/Paragraph"
|
|
51
|
-
export {
|
|
52
|
-
RecyclingInfo,
|
|
53
|
-
type RecyclingInfoProps
|
|
54
|
-
} from "./components/recycling-info/RecyclingInfo"
|
|
55
|
-
export {
|
|
56
|
-
Search,
|
|
57
|
-
type SearchProps
|
|
58
|
-
} from "./components/search/Search"
|
|
59
|
-
export {
|
|
60
|
-
Title,
|
|
61
|
-
type TitleProps,
|
|
62
|
-
type TitleLevel
|
|
63
|
-
} from "./components/title/Title"
|
|
64
|
-
export {
|
|
65
|
-
Header,
|
|
66
|
-
|
|
67
|
-
type
|
|
68
|
-
type
|
|
69
|
-
type
|
|
70
|
-
type
|
|
71
|
-
type
|
|
72
|
-
type
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
type
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
type
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
type
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
1
|
+
export {
|
|
2
|
+
Article,
|
|
3
|
+
type ArticleProps,
|
|
4
|
+
type ArticleDisplayMode
|
|
5
|
+
} from "./components/article/Article"
|
|
6
|
+
export {
|
|
7
|
+
Challenge,
|
|
8
|
+
type ChallengeProps
|
|
9
|
+
} from "./components/challenge/Challenge"
|
|
10
|
+
export {
|
|
11
|
+
ChallengeVignette,
|
|
12
|
+
type ChallengeVignetteProps
|
|
13
|
+
} from "./components/challenge/ChallengeVignette"
|
|
14
|
+
export {
|
|
15
|
+
Chat,
|
|
16
|
+
type ChatProps
|
|
17
|
+
} from "./components/chat/Chat"
|
|
18
|
+
export {
|
|
19
|
+
CollectionCalendar,
|
|
20
|
+
type CollectionCalendarProps
|
|
21
|
+
} from "./components/collection-calendar/CollectionCalendar"
|
|
22
|
+
export {
|
|
23
|
+
Columns,
|
|
24
|
+
type ColumnsProps,
|
|
25
|
+
type ColumnsColumnCount
|
|
26
|
+
} from "./components/columns/Columns"
|
|
27
|
+
export {
|
|
28
|
+
Image,
|
|
29
|
+
ImageProps,
|
|
30
|
+
} from "./components/image/Image"
|
|
31
|
+
export {
|
|
32
|
+
LocationsMap,
|
|
33
|
+
type LocationsMapProps
|
|
34
|
+
} from "./components/locations-map/LocationsMap"
|
|
35
|
+
export {
|
|
36
|
+
NextCollection,
|
|
37
|
+
type NextCollectionProps
|
|
38
|
+
} from "./components/next-collection/NextCollection"
|
|
39
|
+
export {
|
|
40
|
+
Page,
|
|
41
|
+
type PageProps
|
|
42
|
+
} from "./components/page/Page"
|
|
43
|
+
export {
|
|
44
|
+
ContentInset,
|
|
45
|
+
type ContentInsetProps
|
|
46
|
+
} from "./components/content-inset/ContentInset"
|
|
47
|
+
export {
|
|
48
|
+
Paragraph,
|
|
49
|
+
type PararaphProps
|
|
50
|
+
} from "./components/parapraph/Paragraph"
|
|
51
|
+
export {
|
|
52
|
+
RecyclingInfo,
|
|
53
|
+
type RecyclingInfoProps
|
|
54
|
+
} from "./components/recycling-info/RecyclingInfo"
|
|
55
|
+
export {
|
|
56
|
+
Search,
|
|
57
|
+
type SearchProps
|
|
58
|
+
} from "./components/search/Search"
|
|
59
|
+
export {
|
|
60
|
+
Title,
|
|
61
|
+
type TitleProps,
|
|
62
|
+
type TitleLevel
|
|
63
|
+
} from "./components/title/Title"
|
|
64
|
+
export {
|
|
65
|
+
Header,
|
|
66
|
+
DEFAULT_HEADER_ACTIONS,
|
|
67
|
+
type HeaderProps,
|
|
68
|
+
type AppHeaderConfig,
|
|
69
|
+
type AppHeaderElement,
|
|
70
|
+
type AppHeaderLogoElement,
|
|
71
|
+
type AppHeaderTitleElement,
|
|
72
|
+
type AppHeaderActionElement,
|
|
73
|
+
type AppHeaderSlot,
|
|
74
|
+
} from "./components/header/Header"
|
|
75
|
+
export {
|
|
76
|
+
BottomTab,
|
|
77
|
+
type BottomTabProps
|
|
78
|
+
} from "./components/bottom-tab/BottomTab"
|
|
79
|
+
export {
|
|
80
|
+
NotificationsScreen,
|
|
81
|
+
} from "./components/notifications/NotificationsScreen"
|
|
82
|
+
export {
|
|
83
|
+
ProfileScreen,
|
|
84
|
+
} from "./components/profile/ProfileScreen"
|
|
85
|
+
export {
|
|
86
|
+
Vision,
|
|
87
|
+
type VisionProps,
|
|
88
|
+
type VisionCaptureResult,
|
|
89
|
+
} from "./components/vision/Vision"
|
|
90
|
+
export {
|
|
91
|
+
type VisionSuggestion,
|
|
92
|
+
type VisionActionCardProps,
|
|
93
|
+
} from "./components/vision/VisionActionCard"
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
WastoProvider,
|
|
97
|
+
useWasto,
|
|
98
|
+
type WastoProviderProps,
|
|
99
|
+
type WastoContextType,
|
|
100
|
+
} from "./contexts/WastoContext"
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
HeaderConfigProvider,
|
|
104
|
+
useHeaderConfig,
|
|
105
|
+
type HeaderConfigProviderProps,
|
|
106
|
+
} from "./contexts/HeaderConfigContext"
|
|
107
|
+
|
|
108
|
+
export {
|
|
109
|
+
useAppData,
|
|
110
|
+
useOptionalAppData,
|
|
111
|
+
NEXT_EVENTS_DAY_RADIUS,
|
|
112
|
+
type AppDataContextType,
|
|
113
|
+
} from "./contexts/AppDataContext"
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
initWastoSentry,
|
|
117
|
+
wrapWithSentry,
|
|
118
|
+
reportError,
|
|
119
|
+
isWastoSentryActive,
|
|
120
|
+
type WastoSentryConfig,
|
|
121
|
+
type WastoErrorContext,
|
|
122
|
+
} from "./sentry/initSentry"
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
registerExpoPushToken,
|
|
126
|
+
type RegisterExpoPushTokenOptions,
|
|
127
|
+
} from "./push/registerExpoPushToken"
|
|
128
|
+
|
|
129
|
+
export { useWastoClient } from "./hooks/useWastoClient"
|
|
130
|
+
|
|
131
|
+
export type {
|
|
132
|
+
Theme,
|
|
133
|
+
ResolvedTheme,
|
|
134
|
+
ThemeShadowStyle,
|
|
135
|
+
} from "./types/Theme"
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
resolveTheme,
|
|
139
|
+
cardStyle,
|
|
140
|
+
softCardStyle,
|
|
141
|
+
groupedSectionStyle,
|
|
142
|
+
coloredShadow,
|
|
143
|
+
} from "./helpers/themeStyles"
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
SPACE,
|
|
147
|
+
MAQUETTE_RADII,
|
|
148
|
+
MAQUETTE_COLORS,
|
|
149
|
+
} from "./helpers/layout"
|
|
150
|
+
|
|
151
|
+
export { SYSTEM_ROUTES, type SystemRouteKey } from "./helpers/systemRoutes"
|
|
152
|
+
|
|
153
|
+
export { createMaquetteTheme } from "./helpers/maquetteTheme"
|
|
154
|
+
|
|
155
|
+
export {
|
|
156
|
+
NavigationProvider,
|
|
157
|
+
useAppNavigation,
|
|
158
|
+
useOptionalAppNavigation,
|
|
159
|
+
type NavigationApi,
|
|
160
|
+
type NavigationProviderProps,
|
|
161
|
+
} from "./navigation/NavigationContext"
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
useContext,
|
|
4
|
-
useMemo,
|
|
5
|
-
type PropsWithChildren,
|
|
6
|
-
type ReactNode,
|
|
7
|
-
} from "react";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Host-agnostic navigation API.
|
|
11
|
-
* Expo Router apps pass `router.push` / `router.back`;
|
|
12
|
-
* React Navigation apps pass `navigation.navigate` / `goBack`.
|
|
13
|
-
*/
|
|
14
|
-
export type NavigationApi = {
|
|
15
|
-
push: (href: string) => void;
|
|
16
|
-
canGoBack?: () => boolean;
|
|
17
|
-
goBack?: () => void;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const NavigationContext = createContext<NavigationApi | null>(null);
|
|
21
|
-
|
|
22
|
-
export type NavigationProviderProps = PropsWithChildren & {
|
|
23
|
-
value: NavigationApi;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export function NavigationProvider({ value, children }: NavigationProviderProps): ReactNode {
|
|
27
|
-
const memo = useMemo(
|
|
28
|
-
() => ({
|
|
29
|
-
push: value.push,
|
|
30
|
-
canGoBack: value.canGoBack,
|
|
31
|
-
goBack: value.goBack,
|
|
32
|
-
}),
|
|
33
|
-
[value.push, value.canGoBack, value.goBack],
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<NavigationContext.Provider value={memo}>
|
|
38
|
-
{children}
|
|
39
|
-
</NavigationContext.Provider>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function useAppNavigation(): NavigationApi {
|
|
44
|
-
const nav = useContext(NavigationContext);
|
|
45
|
-
if (!nav) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
"[cms-components] NavigationProvider is required (wrap the app root).",
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return nav;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Soft read — returns null when no provider (e.g. isolated component tests). */
|
|
54
|
-
export function useOptionalAppNavigation(): NavigationApi | null {
|
|
55
|
-
return useContext(NavigationContext);
|
|
56
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useMemo,
|
|
5
|
+
type PropsWithChildren,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from "react";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Host-agnostic navigation API.
|
|
11
|
+
* Expo Router apps pass `router.push` / `router.back`;
|
|
12
|
+
* React Navigation apps pass `navigation.navigate` / `goBack`.
|
|
13
|
+
*/
|
|
14
|
+
export type NavigationApi = {
|
|
15
|
+
push: (href: string) => void;
|
|
16
|
+
canGoBack?: () => boolean;
|
|
17
|
+
goBack?: () => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const NavigationContext = createContext<NavigationApi | null>(null);
|
|
21
|
+
|
|
22
|
+
export type NavigationProviderProps = PropsWithChildren & {
|
|
23
|
+
value: NavigationApi;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function NavigationProvider({ value, children }: NavigationProviderProps): ReactNode {
|
|
27
|
+
const memo = useMemo(
|
|
28
|
+
() => ({
|
|
29
|
+
push: value.push,
|
|
30
|
+
canGoBack: value.canGoBack,
|
|
31
|
+
goBack: value.goBack,
|
|
32
|
+
}),
|
|
33
|
+
[value.push, value.canGoBack, value.goBack],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<NavigationContext.Provider value={memo}>
|
|
38
|
+
{children}
|
|
39
|
+
</NavigationContext.Provider>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function useAppNavigation(): NavigationApi {
|
|
44
|
+
const nav = useContext(NavigationContext);
|
|
45
|
+
if (!nav) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"[cms-components] NavigationProvider is required (wrap the app root).",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return nav;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Soft read — returns null when no provider (e.g. isolated component tests). */
|
|
54
|
+
export function useOptionalAppNavigation(): NavigationApi | null {
|
|
55
|
+
return useContext(NavigationContext);
|
|
56
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
type NotificationsModule = typeof import("expo-notifications");
|
|
4
|
+
|
|
5
|
+
type ExpoConstantsLike = {
|
|
6
|
+
expoConfig?: {
|
|
7
|
+
extra?: {
|
|
8
|
+
eas?: {
|
|
9
|
+
projectId?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
} | null;
|
|
13
|
+
easConfig?: {
|
|
14
|
+
projectId?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let notificationsModule: NotificationsModule | null | undefined;
|
|
19
|
+
let constantsModule: ExpoConstantsLike | null | undefined;
|
|
20
|
+
let handlerConfigured = false;
|
|
21
|
+
|
|
22
|
+
function loadNotifications(): NotificationsModule | null {
|
|
23
|
+
if (notificationsModule !== undefined) return notificationsModule;
|
|
24
|
+
try {
|
|
25
|
+
// Optional peer — apps without the package still load cms-components.
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
27
|
+
notificationsModule = require("expo-notifications") as NotificationsModule;
|
|
28
|
+
} catch {
|
|
29
|
+
notificationsModule = null;
|
|
30
|
+
}
|
|
31
|
+
return notificationsModule;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function loadConstants(): ExpoConstantsLike | null {
|
|
35
|
+
if (constantsModule !== undefined) return constantsModule;
|
|
36
|
+
try {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
38
|
+
const mod = require("expo-constants") as
|
|
39
|
+
| ExpoConstantsLike
|
|
40
|
+
| { default: ExpoConstantsLike };
|
|
41
|
+
constantsModule = "default" in mod && mod.default ? mod.default : (mod as ExpoConstantsLike);
|
|
42
|
+
} catch {
|
|
43
|
+
constantsModule = null;
|
|
44
|
+
}
|
|
45
|
+
return constantsModule;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function resolveEasProjectId(): string | null {
|
|
49
|
+
const Constants = loadConstants();
|
|
50
|
+
const fromExtra = Constants?.expoConfig?.extra?.eas?.projectId;
|
|
51
|
+
const fromEasConfig = Constants?.easConfig?.projectId;
|
|
52
|
+
const fromEnv =
|
|
53
|
+
typeof process !== "undefined"
|
|
54
|
+
? String(process.env.EXPO_PUBLIC_EAS_PROJECT_ID ?? "").trim()
|
|
55
|
+
: "";
|
|
56
|
+
const projectId = String(fromExtra || fromEasConfig || fromEnv || "").trim();
|
|
57
|
+
return projectId || null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type RegisterExpoPushTokenOptions = {
|
|
61
|
+
deviceId: string;
|
|
62
|
+
registerPushToken: (deviceId: string, token: string) => Promise<unknown>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Request OS permission, fetch Expo push token, register it on the API.
|
|
67
|
+
* No-op on web, preview, missing peer, missing EAS projectId, or denied permission.
|
|
68
|
+
*/
|
|
69
|
+
export async function registerExpoPushToken(
|
|
70
|
+
options: RegisterExpoPushTokenOptions,
|
|
71
|
+
): Promise<string | null> {
|
|
72
|
+
if (Platform.OS === "web") return null;
|
|
73
|
+
|
|
74
|
+
const deviceId = options.deviceId?.trim();
|
|
75
|
+
if (!deviceId) return null;
|
|
76
|
+
|
|
77
|
+
const Notifications = loadNotifications();
|
|
78
|
+
if (!Notifications) {
|
|
79
|
+
if (__DEV__) {
|
|
80
|
+
console.warn(
|
|
81
|
+
"[wasto] expo-notifications is not installed; push registration skipped",
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const projectId = resolveEasProjectId();
|
|
88
|
+
if (!projectId) {
|
|
89
|
+
if (__DEV__) {
|
|
90
|
+
console.warn(
|
|
91
|
+
"[wasto] EAS projectId missing (extra.eas.projectId or EXPO_PUBLIC_EAS_PROJECT_ID); push registration skipped",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!handlerConfigured) {
|
|
98
|
+
Notifications.setNotificationHandler({
|
|
99
|
+
handleNotification: async () => ({
|
|
100
|
+
shouldShowAlert: true,
|
|
101
|
+
shouldPlaySound: true,
|
|
102
|
+
shouldSetBadge: false,
|
|
103
|
+
shouldShowBanner: true,
|
|
104
|
+
shouldShowList: true,
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
handlerConfigured = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (Platform.OS === "android") {
|
|
111
|
+
await Notifications.setNotificationChannelAsync("default", {
|
|
112
|
+
name: "default",
|
|
113
|
+
importance: Notifications.AndroidImportance.MAX,
|
|
114
|
+
vibrationPattern: [0, 250, 250, 250],
|
|
115
|
+
lightColor: "#FF231F7C",
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const { status: existingStatus } = await Notifications.getPermissionsAsync();
|
|
120
|
+
let finalStatus = existingStatus;
|
|
121
|
+
if (existingStatus !== "granted") {
|
|
122
|
+
const { status } = await Notifications.requestPermissionsAsync();
|
|
123
|
+
finalStatus = status;
|
|
124
|
+
}
|
|
125
|
+
if (finalStatus !== "granted") return null;
|
|
126
|
+
|
|
127
|
+
const push = await Notifications.getExpoPushTokenAsync({ projectId });
|
|
128
|
+
const token = push?.data?.trim();
|
|
129
|
+
if (!token) return null;
|
|
130
|
+
|
|
131
|
+
await options.registerPushToken(deviceId, token);
|
|
132
|
+
return token;
|
|
133
|
+
}
|