@churchapps/apphelper 0.5.0 → 0.5.2

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.
Files changed (100) hide show
  1. package/dist/components/Loading.js +36 -36
  2. package/dist/components/notes/Notes.js +27 -27
  3. package/dist/helpers/AnalyticsHelper.d.ts.map +1 -1
  4. package/dist/helpers/AnalyticsHelper.js +21 -6
  5. package/dist/helpers/AnalyticsHelper.js.map +1 -1
  6. package/dist/helpers/UserHelper.d.ts.map +1 -1
  7. package/dist/helpers/UserHelper.js +4 -1
  8. package/dist/helpers/UserHelper.js.map +1 -1
  9. package/dist/public/css/cropper.css +309 -309
  10. package/dist/public/css/styles.css +111 -111
  11. package/dist/public/locales/de.json +270 -0
  12. package/dist/public/locales/en.json +277 -0
  13. package/dist/public/locales/es.json +272 -0
  14. package/dist/public/locales/fr.json +270 -0
  15. package/dist/public/locales/hi.json +270 -0
  16. package/dist/public/locales/it.json +270 -0
  17. package/dist/public/locales/ko.json +270 -0
  18. package/dist/public/locales/no.json +270 -0
  19. package/dist/public/locales/pt.json +270 -0
  20. package/dist/public/locales/ru.json +270 -0
  21. package/dist/public/locales/tl.json +270 -0
  22. package/dist/public/locales/zh.json +270 -0
  23. package/package.json +72 -72
  24. package/public/css/cropper.css +309 -309
  25. package/public/css/styles.css +111 -111
  26. package/public/locales/de.json +269 -269
  27. package/public/locales/en.json +276 -276
  28. package/public/locales/es.json +272 -272
  29. package/public/locales/fr.json +269 -269
  30. package/public/locales/hi.json +269 -269
  31. package/public/locales/it.json +269 -269
  32. package/public/locales/ko.json +269 -269
  33. package/public/locales/no.json +269 -269
  34. package/public/locales/pt.json +269 -269
  35. package/public/locales/ru.json +269 -269
  36. package/public/locales/tl.json +269 -269
  37. package/public/locales/zh.json +269 -269
  38. package/src/components/DisplayBox.tsx +83 -83
  39. package/src/components/ErrorMessages.tsx +28 -28
  40. package/src/components/ExportLink.tsx +81 -81
  41. package/src/components/FloatingSupport.tsx +18 -18
  42. package/src/components/FormCardPayment.tsx +184 -184
  43. package/src/components/FormSubmissionEdit.tsx +168 -168
  44. package/src/components/HelpIcon.tsx +12 -12
  45. package/src/components/ImageEditor.tsx +161 -161
  46. package/src/components/InputBox.tsx +96 -96
  47. package/src/components/Loading.tsx +77 -77
  48. package/src/components/PageHeader.tsx +110 -110
  49. package/src/components/PersonAvatar.tsx +77 -77
  50. package/src/components/QuestionEdit.tsx +99 -99
  51. package/src/components/SmallButton.tsx +42 -42
  52. package/src/components/SupportModal.tsx +32 -32
  53. package/src/components/TabPanel.tsx +28 -28
  54. package/src/components/gallery/GalleryModal.tsx +173 -173
  55. package/src/components/gallery/StockPhotos.tsx +95 -95
  56. package/src/components/gallery/index.ts +1 -1
  57. package/src/components/header/Banner.tsx +11 -11
  58. package/src/components/header/PrimaryMenu.tsx +100 -100
  59. package/src/components/header/SecondaryMenu.tsx +23 -23
  60. package/src/components/header/SecondaryMenuAlt.tsx +40 -40
  61. package/src/components/header/SiteHeader.tsx +207 -207
  62. package/src/components/header/SupportDrawer.tsx +111 -111
  63. package/src/components/header/index.tsx +2 -2
  64. package/src/components/index.tsx +20 -20
  65. package/src/components/notes/AddNote.tsx +180 -180
  66. package/src/components/notes/Note.tsx +68 -68
  67. package/src/components/notes/Notes.tsx +208 -208
  68. package/src/components/notes/index.ts +3 -3
  69. package/src/components/wrapper/AppList.tsx +19 -19
  70. package/src/components/wrapper/ChurchList.tsx +154 -154
  71. package/src/components/wrapper/NavItem.tsx +47 -47
  72. package/src/components/wrapper/NewPrivateMessage.tsx +253 -253
  73. package/src/components/wrapper/Notifications.tsx +223 -223
  74. package/src/components/wrapper/PrivateMessageDetails.tsx +112 -112
  75. package/src/components/wrapper/PrivateMessages.tsx +576 -576
  76. package/src/components/wrapper/UserMenu.tsx +383 -383
  77. package/src/components/wrapper/index.tsx +8 -8
  78. package/src/helpers/AnalyticsHelper.ts +44 -32
  79. package/src/helpers/AppearanceHelper.ts +73 -73
  80. package/src/helpers/ArrayHelper.ts +87 -87
  81. package/src/helpers/CurrencyHelper.ts +10 -10
  82. package/src/helpers/DateHelper.ts +104 -104
  83. package/src/helpers/ErrorHelper.ts +43 -43
  84. package/src/helpers/EventHelper.ts +49 -49
  85. package/src/helpers/FileHelper.ts +31 -31
  86. package/src/helpers/Locale.ts +457 -457
  87. package/src/helpers/NotificationService.ts +296 -296
  88. package/src/helpers/PersonHelper.ts +62 -62
  89. package/src/helpers/SlugHelper.ts +37 -37
  90. package/src/helpers/SocketHelper.ts +296 -296
  91. package/src/helpers/UniqueIdHelper.ts +36 -36
  92. package/src/helpers/UserHelper.ts +107 -104
  93. package/src/helpers/createEmotionCache.ts +17 -17
  94. package/src/helpers/index.ts +58 -58
  95. package/src/hooks/index.ts +3 -3
  96. package/src/hooks/useMountedState.ts +16 -16
  97. package/src/hooks/useNotifications.ts +93 -93
  98. package/src/index.ts +2 -2
  99. package/src/types/interface-extensions.d.ts +11 -11
  100. package/tsconfig.json +31 -31
@@ -1,174 +1,174 @@
1
- "use client";
2
-
3
- import { FileHelper } from "../../helpers/FileHelper";
4
- import { ApiHelper } from "../../helpers";
5
- import { Locale } from "../../helpers";
6
- import { CommonEnvironmentHelper } from "@churchapps/helpers";
7
- import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, Grid, IconButton, InputLabel, MenuItem, Select, Tab, Tabs, Tooltip, Icon } from "@mui/material";
8
- import React, { useState } from "react";
9
- import { ImageEditor } from "../ImageEditor";
10
- import { TabPanel } from "../TabPanel";
11
- import { StockPhotos } from "./StockPhotos";
12
-
13
- interface Props {
14
- aspectRatio: number,
15
- onClose: () => void,
16
- onSelect: (img: string) => void
17
- }
18
-
19
- export const GalleryModal: React.FC<Props> = (props: Props) => {
20
- const [images, setImages] = useState<string[]>([]);
21
- const [tabIndex, setTabIndex] = React.useState(0);
22
- const [aspectRatio, setAspectRatio] = React.useState(Math.round(props.aspectRatio * 100) / 100);
23
- const [editorPhotoUrl, setEditorPhotoUrl] = React.useState("");
24
-
25
- const contentRoot = CommonEnvironmentHelper.ContentRoot;
26
-
27
- const handleTabChange = (el: any, newValue: any) => { setTabIndex(newValue); }
28
-
29
- const loadData = () => { ApiHelper.get("/gallery/" + aspectRatio.toString(), "ContentApi").then((data: any) => setImages(data.images)); }
30
-
31
- const handleImageUpdated = async (dataUrl: string) => {
32
- console.log('handleImageUpdated called with dataUrl:', dataUrl ? 'Data URL received' : 'Empty dataUrl');
33
-
34
- if (!dataUrl) {
35
- console.warn('No dataUrl provided to handleImageUpdated');
36
- return;
37
- }
38
-
39
- try {
40
- const fileName = Math.floor(Date.now() / 1000).toString() + ".jpg"
41
- const blob = FileHelper.dataURLtoBlob(dataUrl);
42
- const file = new File([blob], "file_name");
43
-
44
- const params = { folder: aspectRatio.toString(), fileName };
45
- console.log('Attempting to upload image with params:', params);
46
-
47
- const presigned = await ApiHelper.post("/gallery/requestUpload", params, "ContentApi");
48
- const doUpload = presigned.key !== undefined;
49
-
50
- if (doUpload) {
51
- console.log('Upload successful, uploading to presigned URL');
52
- await FileHelper.postPresignedFile(presigned, file, () => { });
53
- console.log('Image uploaded successfully');
54
- } else {
55
- console.warn('Upload failed - no presigned key received');
56
- }
57
-
58
- setTabIndex(0);
59
- loadData();
60
- } catch (error) {
61
- console.error('Error in handleImageUpdated:', error);
62
- // In case of API failure, still provide feedback to user
63
- alert('Image processing completed, but upload failed. API may not be available in this environment.');
64
- }
65
- };
66
-
67
- const handleDelete = (folder: string, image: string) => {
68
- if (window.confirm(Locale.label("gallery.confirmDelete"))) {
69
- ApiHelper.delete("/gallery/" + folder + "/" + image, "ContentApi").then(() => { loadData(); });
70
- }
71
- }
72
-
73
- React.useEffect(() => { if (aspectRatio !== props.aspectRatio) setAspectRatio(Math.round(props.aspectRatio * 100) / 100) }, [props.aspectRatio]); //eslint-disable-line
74
- React.useEffect(loadData, [aspectRatio]); //eslint-disable-line
75
-
76
- const getImages = () => {
77
- let result: React.ReactElement[] = [];
78
- images.forEach((img: any) => {
79
- const parts = img.split("/");
80
-
81
- result.push(<Grid size={{ xs: 12, md: 4 }}>
82
- <Box sx={{ position: "relative", ":hover #deleteIcon": { visibility: "visible" } }}>
83
- <a href="about:blank" onClick={(e) => { e.preventDefault(); props.onSelect(contentRoot + "/" + img) }} aria-label="Select image" data-testid="select-image">
84
- <Box
85
- component="img"
86
- src={contentRoot + "/" + img}
87
- alt="custom"
88
- sx={{
89
- width: '100%',
90
- height: 'auto',
91
- maxWidth: '100%',
92
- display: 'block'
93
- }}
94
- />
95
- </a>
96
- <Box id="deleteIcon" sx={{ position: "absolute", top: 3, right: 3, visibility: "hidden", backgroundColor: "whitesmoke", borderRadius: 5 }}>
97
- <Tooltip title="Delete">
98
- <IconButton size="small" color="error" onClick={() => handleDelete(parts[2], parts[3])} aria-label="Delete image" data-testid="delete-image">
99
- <Icon sx={{ fontSize: "17px !important" }}>delete_outline</Icon>
100
- </IconButton>
101
- </Tooltip>
102
- </Box>
103
- </Box>
104
- </Grid>);
105
- })
106
- return result;
107
- }
108
-
109
- const handleStockSelect = (url: string) => {
110
- setEditorPhotoUrl(url);
111
- setTabIndex(1);
112
- }
113
-
114
- const getDisplayAspect = () => {
115
- let result = aspectRatio.toString();
116
- if (aspectRatio === 0) result = "Free Form";
117
- else if (aspectRatio === 1) result = "1:1";
118
- else if (aspectRatio === 2) result = "2:1";
119
- else if (aspectRatio === 3) result = "3:1";
120
- else if (aspectRatio === 4) result = "4:1";
121
- else if (aspectRatio === 1.33) result = "4:3";
122
- else if (aspectRatio === 1.78) result = "16:9";
123
- else if (aspectRatio === 0.5) result = "1:2";
124
- else if (aspectRatio === 0.5625) result = "9:16";
125
- return result;
126
- }
127
-
128
- return (<>
129
- <Dialog open={true} onClose={props.onClose}>
130
- <DialogTitle>Select a Photo</DialogTitle>
131
- <DialogContent style={{ overflowX: "hidden" }}>
132
-
133
- {(props.aspectRatio === 0) && (
134
- <FormControl fullWidth>
135
- <InputLabel>{Locale.label("gallery.aspectRatio")}</InputLabel>
136
- <Select size="small" label={Locale.label("gallery.aspectRatio")} name="aspectRatio" value={aspectRatio} onChange={(e) => setAspectRatio(parseFloat(e.target.value.toString()))}>
137
- <MenuItem value="0">{Locale.label("gallery.freeForm")}</MenuItem>
138
- <MenuItem value="1">1:1</MenuItem>
139
- <MenuItem value="2">2:1</MenuItem>
140
- <MenuItem value="3">3:1</MenuItem>
141
- <MenuItem value="4">4:1</MenuItem>
142
- <MenuItem value="1.33">4:3</MenuItem>
143
- <MenuItem value="1.78">16:9</MenuItem>
144
- <MenuItem value="0.5">1:2</MenuItem>
145
- <MenuItem value="0.5625">9:16</MenuItem>
146
- </Select>
147
- </FormControl>
148
- )}
149
-
150
- <Tabs variant="fullWidth" value={tabIndex} onChange={handleTabChange}>
151
- <Tab label="Gallery" />
152
- <Tab label="Upload" />
153
- <Tab label="Stock Photos" />
154
- </Tabs>
155
- <TabPanel value={tabIndex} index={0}>
156
-
157
- <Grid container spacing={3} alignItems="center">
158
- {getImages()}
159
- </Grid>
160
- </TabPanel>
161
- <TabPanel value={tabIndex} index={1}>
162
- <div>{Locale.label("gallery.aspectRatio")}: {getDisplayAspect()}</div>
163
- <ImageEditor onUpdate={handleImageUpdated} photoUrl={editorPhotoUrl} aspectRatio={aspectRatio} outputWidth={1280} outputHeight={768} hideDelete={true} />
164
- </TabPanel>
165
- <TabPanel value={tabIndex} index={2}>
166
- <StockPhotos aspectRatio={aspectRatio} onSelect={props.onSelect} onStockSelect={handleStockSelect} />
167
- </TabPanel>
168
- </DialogContent>
169
- <DialogActions sx={{ paddingX: "16px", paddingBottom: "12px" }}>
170
- <Button variant="outlined" onClick={props.onClose}>Close</Button>
171
- </DialogActions>
172
- </Dialog>
173
- </>);
1
+ "use client";
2
+
3
+ import { FileHelper } from "../../helpers/FileHelper";
4
+ import { ApiHelper } from "../../helpers";
5
+ import { Locale } from "../../helpers";
6
+ import { CommonEnvironmentHelper } from "@churchapps/helpers";
7
+ import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, Grid, IconButton, InputLabel, MenuItem, Select, Tab, Tabs, Tooltip, Icon } from "@mui/material";
8
+ import React, { useState } from "react";
9
+ import { ImageEditor } from "../ImageEditor";
10
+ import { TabPanel } from "../TabPanel";
11
+ import { StockPhotos } from "./StockPhotos";
12
+
13
+ interface Props {
14
+ aspectRatio: number,
15
+ onClose: () => void,
16
+ onSelect: (img: string) => void
17
+ }
18
+
19
+ export const GalleryModal: React.FC<Props> = (props: Props) => {
20
+ const [images, setImages] = useState<string[]>([]);
21
+ const [tabIndex, setTabIndex] = React.useState(0);
22
+ const [aspectRatio, setAspectRatio] = React.useState(Math.round(props.aspectRatio * 100) / 100);
23
+ const [editorPhotoUrl, setEditorPhotoUrl] = React.useState("");
24
+
25
+ const contentRoot = CommonEnvironmentHelper.ContentRoot;
26
+
27
+ const handleTabChange = (el: any, newValue: any) => { setTabIndex(newValue); }
28
+
29
+ const loadData = () => { ApiHelper.get("/gallery/" + aspectRatio.toString(), "ContentApi").then((data: any) => setImages(data.images)); }
30
+
31
+ const handleImageUpdated = async (dataUrl: string) => {
32
+ console.log('handleImageUpdated called with dataUrl:', dataUrl ? 'Data URL received' : 'Empty dataUrl');
33
+
34
+ if (!dataUrl) {
35
+ console.warn('No dataUrl provided to handleImageUpdated');
36
+ return;
37
+ }
38
+
39
+ try {
40
+ const fileName = Math.floor(Date.now() / 1000).toString() + ".jpg"
41
+ const blob = FileHelper.dataURLtoBlob(dataUrl);
42
+ const file = new File([blob], "file_name");
43
+
44
+ const params = { folder: aspectRatio.toString(), fileName };
45
+ console.log('Attempting to upload image with params:', params);
46
+
47
+ const presigned = await ApiHelper.post("/gallery/requestUpload", params, "ContentApi");
48
+ const doUpload = presigned.key !== undefined;
49
+
50
+ if (doUpload) {
51
+ console.log('Upload successful, uploading to presigned URL');
52
+ await FileHelper.postPresignedFile(presigned, file, () => { });
53
+ console.log('Image uploaded successfully');
54
+ } else {
55
+ console.warn('Upload failed - no presigned key received');
56
+ }
57
+
58
+ setTabIndex(0);
59
+ loadData();
60
+ } catch (error) {
61
+ console.error('Error in handleImageUpdated:', error);
62
+ // In case of API failure, still provide feedback to user
63
+ alert('Image processing completed, but upload failed. API may not be available in this environment.');
64
+ }
65
+ };
66
+
67
+ const handleDelete = (folder: string, image: string) => {
68
+ if (window.confirm(Locale.label("gallery.confirmDelete"))) {
69
+ ApiHelper.delete("/gallery/" + folder + "/" + image, "ContentApi").then(() => { loadData(); });
70
+ }
71
+ }
72
+
73
+ React.useEffect(() => { if (aspectRatio !== props.aspectRatio) setAspectRatio(Math.round(props.aspectRatio * 100) / 100) }, [props.aspectRatio]); //eslint-disable-line
74
+ React.useEffect(loadData, [aspectRatio]); //eslint-disable-line
75
+
76
+ const getImages = () => {
77
+ let result: React.ReactElement[] = [];
78
+ images.forEach((img: any) => {
79
+ const parts = img.split("/");
80
+
81
+ result.push(<Grid size={{ xs: 12, md: 4 }}>
82
+ <Box sx={{ position: "relative", ":hover #deleteIcon": { visibility: "visible" } }}>
83
+ <a href="about:blank" onClick={(e) => { e.preventDefault(); props.onSelect(contentRoot + "/" + img) }} aria-label="Select image" data-testid="select-image">
84
+ <Box
85
+ component="img"
86
+ src={contentRoot + "/" + img}
87
+ alt="custom"
88
+ sx={{
89
+ width: '100%',
90
+ height: 'auto',
91
+ maxWidth: '100%',
92
+ display: 'block'
93
+ }}
94
+ />
95
+ </a>
96
+ <Box id="deleteIcon" sx={{ position: "absolute", top: 3, right: 3, visibility: "hidden", backgroundColor: "whitesmoke", borderRadius: 5 }}>
97
+ <Tooltip title="Delete">
98
+ <IconButton size="small" color="error" onClick={() => handleDelete(parts[2], parts[3])} aria-label="Delete image" data-testid="delete-image">
99
+ <Icon sx={{ fontSize: "17px !important" }}>delete_outline</Icon>
100
+ </IconButton>
101
+ </Tooltip>
102
+ </Box>
103
+ </Box>
104
+ </Grid>);
105
+ })
106
+ return result;
107
+ }
108
+
109
+ const handleStockSelect = (url: string) => {
110
+ setEditorPhotoUrl(url);
111
+ setTabIndex(1);
112
+ }
113
+
114
+ const getDisplayAspect = () => {
115
+ let result = aspectRatio.toString();
116
+ if (aspectRatio === 0) result = "Free Form";
117
+ else if (aspectRatio === 1) result = "1:1";
118
+ else if (aspectRatio === 2) result = "2:1";
119
+ else if (aspectRatio === 3) result = "3:1";
120
+ else if (aspectRatio === 4) result = "4:1";
121
+ else if (aspectRatio === 1.33) result = "4:3";
122
+ else if (aspectRatio === 1.78) result = "16:9";
123
+ else if (aspectRatio === 0.5) result = "1:2";
124
+ else if (aspectRatio === 0.5625) result = "9:16";
125
+ return result;
126
+ }
127
+
128
+ return (<>
129
+ <Dialog open={true} onClose={props.onClose}>
130
+ <DialogTitle>Select a Photo</DialogTitle>
131
+ <DialogContent style={{ overflowX: "hidden" }}>
132
+
133
+ {(props.aspectRatio === 0) && (
134
+ <FormControl fullWidth>
135
+ <InputLabel>{Locale.label("gallery.aspectRatio")}</InputLabel>
136
+ <Select size="small" label={Locale.label("gallery.aspectRatio")} name="aspectRatio" value={aspectRatio} onChange={(e) => setAspectRatio(parseFloat(e.target.value.toString()))}>
137
+ <MenuItem value="0">{Locale.label("gallery.freeForm")}</MenuItem>
138
+ <MenuItem value="1">1:1</MenuItem>
139
+ <MenuItem value="2">2:1</MenuItem>
140
+ <MenuItem value="3">3:1</MenuItem>
141
+ <MenuItem value="4">4:1</MenuItem>
142
+ <MenuItem value="1.33">4:3</MenuItem>
143
+ <MenuItem value="1.78">16:9</MenuItem>
144
+ <MenuItem value="0.5">1:2</MenuItem>
145
+ <MenuItem value="0.5625">9:16</MenuItem>
146
+ </Select>
147
+ </FormControl>
148
+ )}
149
+
150
+ <Tabs variant="fullWidth" value={tabIndex} onChange={handleTabChange}>
151
+ <Tab label="Gallery" />
152
+ <Tab label="Upload" />
153
+ <Tab label="Stock Photos" />
154
+ </Tabs>
155
+ <TabPanel value={tabIndex} index={0}>
156
+
157
+ <Grid container spacing={3} alignItems="center">
158
+ {getImages()}
159
+ </Grid>
160
+ </TabPanel>
161
+ <TabPanel value={tabIndex} index={1}>
162
+ <div>{Locale.label("gallery.aspectRatio")}: {getDisplayAspect()}</div>
163
+ <ImageEditor onUpdate={handleImageUpdated} photoUrl={editorPhotoUrl} aspectRatio={aspectRatio} outputWidth={1280} outputHeight={768} hideDelete={true} />
164
+ </TabPanel>
165
+ <TabPanel value={tabIndex} index={2}>
166
+ <StockPhotos aspectRatio={aspectRatio} onSelect={props.onSelect} onStockSelect={handleStockSelect} />
167
+ </TabPanel>
168
+ </DialogContent>
169
+ <DialogActions sx={{ paddingX: "16px", paddingBottom: "12px" }}>
170
+ <Button variant="outlined" onClick={props.onClose}>Close</Button>
171
+ </DialogActions>
172
+ </Dialog>
173
+ </>);
174
174
  };
@@ -1,96 +1,96 @@
1
- "use client";
2
- import { Button, Grid, TextField } from "@mui/material";
3
- import React, { useState } from "react";
4
- import { ApiHelper } from "../../helpers";
5
- import { Locale } from "../../helpers";
6
- import { CommonEnvironmentHelper } from "@churchapps/helpers";
7
-
8
- interface Props {
9
- aspectRatio: number,
10
- onSelect: (img: string) => void,
11
- onStockSelect: (img: string) => void
12
- }
13
-
14
- interface SearchResult { description: string, url: string, photographer: string, photographerUrl: string, large: string, thumbnail: string }
15
-
16
- export const StockPhotos: React.FC<Props> = (props: Props) => {
17
- const [images, setImages] = useState<string[]>([]);
18
- const [searchText, setSearchText] = useState("");
19
- const [searchResults, setSearchResults] = useState<SearchResult[]>(null);
20
-
21
- const contentRoot = CommonEnvironmentHelper.ContentRoot;
22
-
23
- const loadData = () => { ApiHelper.getAnonymous("/gallery/stock/" + props.aspectRatio.toString(), "ContentApi").then((data: any) => setImages(data.images)); }
24
-
25
- React.useEffect(loadData, [props.aspectRatio]); //eslint-disable-line
26
-
27
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { e.preventDefault(); setSearchText(e.currentTarget.value); }
28
-
29
- const handleSearch = (e: React.MouseEvent) => {
30
- if (e !== null) e.preventDefault();
31
- let term = searchText.trim();
32
- ApiHelper.post("/stock/search", { term: term }, "ContentApi").then((data: SearchResult[]) => { setSearchResults(data) });
33
- }
34
-
35
- const getImages = () => {
36
- if (searchResults) return getResults();
37
- else return getSuggested();
38
- }
39
-
40
- const getResults = () => {
41
- let result: React.ReactElement[] = [];
42
- searchResults.forEach((p: any) => {
43
- result.push(<Grid size={{ xs: 12, md: 4 }}>
44
- <a href="about:blank" onClick={(e) => { e.preventDefault(); props.onStockSelect(p.large) }}>
45
- <img
46
- src={p.thumbnail}
47
- alt="stock"
48
- style={{
49
- width: '100%',
50
- height: 'auto',
51
- maxWidth: '100%',
52
- display: 'block'
53
- }}
54
- />
55
- </a>
56
- <div>
57
- <i style={{ fontSize: 12 }}>
58
- <a href={p.url} target="_blank" rel="noreferrer noopener">{Locale.label("stockPhotos.photoBy")}</a> <a href={p.photographerUrl} target="_blank" rel="noreferrer noopener">{p.photographer}</a></i>
59
- </div>
60
- </Grid>);
61
- })
62
- return result;
63
- }
64
-
65
- const getSuggested = () => {
66
- let result: React.ReactElement[] = [];
67
- images.forEach((img: any) => {
68
- result.push(<Grid size={{ xs: 12, md: 4 }}>
69
- <a href="about:blank" onClick={(e) => { e.preventDefault(); props.onSelect(contentRoot + "/" + img) }}>
70
- <img
71
- src={contentRoot + "/" + img}
72
- alt="stock"
73
- style={{
74
- width: '100%',
75
- height: 'auto',
76
- maxWidth: '100%',
77
- display: 'block'
78
- }}
79
- />
80
- </a>
81
- </Grid>);
82
- })
83
- return result;
84
- }
85
-
86
- return (<>
87
- <TextField fullWidth name="personAddText" label="Search Term" value={searchText} onChange={handleChange}
88
- InputProps={{ endAdornment: <Button variant="contained" id="searchButton" data-testid="search-button" onClick={handleSearch}>Search</Button> }}
89
- />
90
- {searchResults && <div>{Locale.label("stockPhotos.providedBy")} <a href="https://pexels.com">Pexels</a>.</div>}
91
- <Grid container spacing={3} alignItems="center">
92
- {getImages()}
93
- </Grid>
94
-
95
- </>);
1
+ "use client";
2
+ import { Button, Grid, TextField } from "@mui/material";
3
+ import React, { useState } from "react";
4
+ import { ApiHelper } from "../../helpers";
5
+ import { Locale } from "../../helpers";
6
+ import { CommonEnvironmentHelper } from "@churchapps/helpers";
7
+
8
+ interface Props {
9
+ aspectRatio: number,
10
+ onSelect: (img: string) => void,
11
+ onStockSelect: (img: string) => void
12
+ }
13
+
14
+ interface SearchResult { description: string, url: string, photographer: string, photographerUrl: string, large: string, thumbnail: string }
15
+
16
+ export const StockPhotos: React.FC<Props> = (props: Props) => {
17
+ const [images, setImages] = useState<string[]>([]);
18
+ const [searchText, setSearchText] = useState("");
19
+ const [searchResults, setSearchResults] = useState<SearchResult[]>(null);
20
+
21
+ const contentRoot = CommonEnvironmentHelper.ContentRoot;
22
+
23
+ const loadData = () => { ApiHelper.getAnonymous("/gallery/stock/" + props.aspectRatio.toString(), "ContentApi").then((data: any) => setImages(data.images)); }
24
+
25
+ React.useEffect(loadData, [props.aspectRatio]); //eslint-disable-line
26
+
27
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { e.preventDefault(); setSearchText(e.currentTarget.value); }
28
+
29
+ const handleSearch = (e: React.MouseEvent) => {
30
+ if (e !== null) e.preventDefault();
31
+ let term = searchText.trim();
32
+ ApiHelper.post("/stock/search", { term: term }, "ContentApi").then((data: SearchResult[]) => { setSearchResults(data) });
33
+ }
34
+
35
+ const getImages = () => {
36
+ if (searchResults) return getResults();
37
+ else return getSuggested();
38
+ }
39
+
40
+ const getResults = () => {
41
+ let result: React.ReactElement[] = [];
42
+ searchResults.forEach((p: any) => {
43
+ result.push(<Grid size={{ xs: 12, md: 4 }}>
44
+ <a href="about:blank" onClick={(e) => { e.preventDefault(); props.onStockSelect(p.large) }}>
45
+ <img
46
+ src={p.thumbnail}
47
+ alt="stock"
48
+ style={{
49
+ width: '100%',
50
+ height: 'auto',
51
+ maxWidth: '100%',
52
+ display: 'block'
53
+ }}
54
+ />
55
+ </a>
56
+ <div>
57
+ <i style={{ fontSize: 12 }}>
58
+ <a href={p.url} target="_blank" rel="noreferrer noopener">{Locale.label("stockPhotos.photoBy")}</a> <a href={p.photographerUrl} target="_blank" rel="noreferrer noopener">{p.photographer}</a></i>
59
+ </div>
60
+ </Grid>);
61
+ })
62
+ return result;
63
+ }
64
+
65
+ const getSuggested = () => {
66
+ let result: React.ReactElement[] = [];
67
+ images.forEach((img: any) => {
68
+ result.push(<Grid size={{ xs: 12, md: 4 }}>
69
+ <a href="about:blank" onClick={(e) => { e.preventDefault(); props.onSelect(contentRoot + "/" + img) }}>
70
+ <img
71
+ src={contentRoot + "/" + img}
72
+ alt="stock"
73
+ style={{
74
+ width: '100%',
75
+ height: 'auto',
76
+ maxWidth: '100%',
77
+ display: 'block'
78
+ }}
79
+ />
80
+ </a>
81
+ </Grid>);
82
+ })
83
+ return result;
84
+ }
85
+
86
+ return (<>
87
+ <TextField fullWidth name="personAddText" label="Search Term" value={searchText} onChange={handleChange}
88
+ InputProps={{ endAdornment: <Button variant="contained" id="searchButton" data-testid="search-button" onClick={handleSearch}>Search</Button> }}
89
+ />
90
+ {searchResults && <div>{Locale.label("stockPhotos.providedBy")} <a href="https://pexels.com">Pexels</a>.</div>}
91
+ <Grid container spacing={3} alignItems="center">
92
+ {getImages()}
93
+ </Grid>
94
+
95
+ </>);
96
96
  };
@@ -1,2 +1,2 @@
1
- export * from "./GalleryModal";
1
+ export * from "./GalleryModal";
2
2
  export * from "./StockPhotos";
@@ -1,11 +1,11 @@
1
- import React from "react";
2
-
3
- interface Props {
4
- children: React.ReactNode
5
- }
6
-
7
- export const Banner = (props:Props) => {
8
- return (<div id="banner">
9
- {props.children}
10
- </div>);
11
- }
1
+ import React from "react";
2
+
3
+ interface Props {
4
+ children: React.ReactNode
5
+ }
6
+
7
+ export const Banner = (props:Props) => {
8
+ return (<div id="banner">
9
+ {props.children}
10
+ </div>);
11
+ }