@churchapps/apphelper 0.6.0 → 0.6.1
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/dist/components/wrapper/PrivateMessageDetails.d.ts.map +1 -1
- package/dist/components/wrapper/PrivateMessageDetails.js +1 -2
- package/dist/components/wrapper/PrivateMessageDetails.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ImageEditor.tsx +167 -167
- package/src/components/gallery/GalleryModal.tsx +169 -169
- package/src/components/header/SiteHeader.tsx +204 -204
- package/src/components/wrapper/ChurchList.tsx +145 -145
- package/src/components/wrapper/PrivateMessageDetails.tsx +6 -8
- package/src/helpers/ErrorHelper.ts +41 -41
- package/src/helpers/NotificationService.ts +232 -232
- package/src/helpers/SocketHelper.ts +247 -247
|
@@ -1,170 +1,170 @@
|
|
|
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
|
-
|
|
33
|
-
if (!dataUrl) {
|
|
34
|
-
console.warn('No dataUrl provided to handleImageUpdated');
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const fileName = Math.floor(Date.now() / 1000).toString() + ".jpg"
|
|
40
|
-
const blob = FileHelper.dataURLtoBlob(dataUrl);
|
|
41
|
-
const file = new File([blob], "file_name");
|
|
42
|
-
|
|
43
|
-
const params = { folder: aspectRatio.toString(), fileName };
|
|
44
|
-
|
|
45
|
-
const presigned = await ApiHelper.post("/gallery/requestUpload", params, "ContentApi");
|
|
46
|
-
const doUpload = presigned.key !== undefined;
|
|
47
|
-
|
|
48
|
-
if (doUpload) {
|
|
49
|
-
await FileHelper.postPresignedFile(presigned, file, () => { });
|
|
50
|
-
} else {
|
|
51
|
-
console.warn('Upload failed - no presigned key received');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
setTabIndex(0);
|
|
55
|
-
loadData();
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error('Error in handleImageUpdated:', error);
|
|
58
|
-
// In case of API failure, still provide feedback to user
|
|
59
|
-
alert('Image processing completed, but upload failed. API may not be available in this environment.');
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const handleDelete = (folder: string, image: string) => {
|
|
64
|
-
if (window.confirm(Locale.label("gallery.confirmDelete"))) {
|
|
65
|
-
ApiHelper.delete("/gallery/" + folder + "/" + image, "ContentApi").then(() => { loadData(); });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
React.useEffect(() => { if (aspectRatio !== props.aspectRatio) setAspectRatio(Math.round(props.aspectRatio * 100) / 100) }, [props.aspectRatio]); //eslint-disable-line
|
|
70
|
-
React.useEffect(loadData, [aspectRatio]); //eslint-disable-line
|
|
71
|
-
|
|
72
|
-
const getImages = () => {
|
|
73
|
-
let result: React.ReactElement[] = [];
|
|
74
|
-
images.forEach((img: any, index: number) => {
|
|
75
|
-
const parts = img.split("/");
|
|
76
|
-
|
|
77
|
-
result.push(<Grid key={img || index} size={{ xs: 12, md: 4 }}>
|
|
78
|
-
<Box sx={{ position: "relative", ":hover #deleteIcon": { visibility: "visible" } }}>
|
|
79
|
-
<a href="about:blank" onClick={(e) => { e.preventDefault(); props.onSelect(contentRoot + "/" + img) }} aria-label="Select image" data-testid="select-image">
|
|
80
|
-
<Box
|
|
81
|
-
component="img"
|
|
82
|
-
src={contentRoot + "/" + img}
|
|
83
|
-
alt="custom"
|
|
84
|
-
sx={{
|
|
85
|
-
width: '100%',
|
|
86
|
-
height: 'auto',
|
|
87
|
-
maxWidth: '100%',
|
|
88
|
-
display: 'block'
|
|
89
|
-
}}
|
|
90
|
-
/>
|
|
91
|
-
</a>
|
|
92
|
-
<Box id="deleteIcon" sx={{ position: "absolute", top: 3, right: 3, visibility: "hidden", backgroundColor: "whitesmoke", borderRadius: 5 }}>
|
|
93
|
-
<Tooltip title="Delete">
|
|
94
|
-
<IconButton size="small" color="error" onClick={() => handleDelete(parts[2], parts[3])} aria-label="Delete image" data-testid="delete-image">
|
|
95
|
-
<Icon sx={{ fontSize: "17px !important" }}>delete_outline</Icon>
|
|
96
|
-
</IconButton>
|
|
97
|
-
</Tooltip>
|
|
98
|
-
</Box>
|
|
99
|
-
</Box>
|
|
100
|
-
</Grid>);
|
|
101
|
-
})
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const handleStockSelect = (url: string) => {
|
|
106
|
-
setEditorPhotoUrl(url);
|
|
107
|
-
setTabIndex(1);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const getDisplayAspect = () => {
|
|
111
|
-
let result = aspectRatio.toString();
|
|
112
|
-
if (aspectRatio === 0) result = "Free Form";
|
|
113
|
-
else if (aspectRatio === 1) result = "1:1";
|
|
114
|
-
else if (aspectRatio === 2) result = "2:1";
|
|
115
|
-
else if (aspectRatio === 3) result = "3:1";
|
|
116
|
-
else if (aspectRatio === 4) result = "4:1";
|
|
117
|
-
else if (aspectRatio === 1.33) result = "4:3";
|
|
118
|
-
else if (aspectRatio === 1.78) result = "16:9";
|
|
119
|
-
else if (aspectRatio === 0.5) result = "1:2";
|
|
120
|
-
else if (aspectRatio === 0.5625) result = "9:16";
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return (<>
|
|
125
|
-
<Dialog open={true} onClose={props.onClose}>
|
|
126
|
-
<DialogTitle>Select a Photo</DialogTitle>
|
|
127
|
-
<DialogContent style={{ overflowX: "hidden" }}>
|
|
128
|
-
|
|
129
|
-
{(props.aspectRatio === 0) && (
|
|
130
|
-
<FormControl fullWidth>
|
|
131
|
-
<InputLabel>{Locale.label("gallery.aspectRatio")}</InputLabel>
|
|
132
|
-
<Select size="small" label={Locale.label("gallery.aspectRatio")} name="aspectRatio" value={aspectRatio} onChange={(e) => setAspectRatio(parseFloat(e.target.value.toString()))}>
|
|
133
|
-
<MenuItem value="0">{Locale.label("gallery.freeForm")}</MenuItem>
|
|
134
|
-
<MenuItem value="1">1:1</MenuItem>
|
|
135
|
-
<MenuItem value="2">2:1</MenuItem>
|
|
136
|
-
<MenuItem value="3">3:1</MenuItem>
|
|
137
|
-
<MenuItem value="4">4:1</MenuItem>
|
|
138
|
-
<MenuItem value="1.33">4:3</MenuItem>
|
|
139
|
-
<MenuItem value="1.78">16:9</MenuItem>
|
|
140
|
-
<MenuItem value="0.5">1:2</MenuItem>
|
|
141
|
-
<MenuItem value="0.5625">9:16</MenuItem>
|
|
142
|
-
</Select>
|
|
143
|
-
</FormControl>
|
|
144
|
-
)}
|
|
145
|
-
|
|
146
|
-
<Tabs variant="fullWidth" value={tabIndex} onChange={handleTabChange}>
|
|
147
|
-
<Tab label="Gallery" />
|
|
148
|
-
<Tab label="Upload" />
|
|
149
|
-
<Tab label="Stock Photos" />
|
|
150
|
-
</Tabs>
|
|
151
|
-
<TabPanel value={tabIndex} index={0}>
|
|
152
|
-
|
|
153
|
-
<Grid container spacing={3} alignItems="center">
|
|
154
|
-
{getImages()}
|
|
155
|
-
</Grid>
|
|
156
|
-
</TabPanel>
|
|
157
|
-
<TabPanel value={tabIndex} index={1}>
|
|
158
|
-
<div>{Locale.label("gallery.aspectRatio")}: {getDisplayAspect()}</div>
|
|
159
|
-
<ImageEditor onUpdate={handleImageUpdated} photoUrl={editorPhotoUrl} aspectRatio={aspectRatio} outputWidth={1280} outputHeight={768} hideDelete={true} />
|
|
160
|
-
</TabPanel>
|
|
161
|
-
<TabPanel value={tabIndex} index={2}>
|
|
162
|
-
<StockPhotos aspectRatio={aspectRatio} onSelect={props.onSelect} onStockSelect={handleStockSelect} />
|
|
163
|
-
</TabPanel>
|
|
164
|
-
</DialogContent>
|
|
165
|
-
<DialogActions sx={{ paddingX: "16px", paddingBottom: "12px" }}>
|
|
166
|
-
<Button variant="outlined" onClick={props.onClose}>Close</Button>
|
|
167
|
-
</DialogActions>
|
|
168
|
-
</Dialog>
|
|
169
|
-
</>);
|
|
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
|
+
|
|
33
|
+
if (!dataUrl) {
|
|
34
|
+
console.warn('No dataUrl provided to handleImageUpdated');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const fileName = Math.floor(Date.now() / 1000).toString() + ".jpg"
|
|
40
|
+
const blob = FileHelper.dataURLtoBlob(dataUrl);
|
|
41
|
+
const file = new File([blob], "file_name");
|
|
42
|
+
|
|
43
|
+
const params = { folder: aspectRatio.toString(), fileName };
|
|
44
|
+
|
|
45
|
+
const presigned = await ApiHelper.post("/gallery/requestUpload", params, "ContentApi");
|
|
46
|
+
const doUpload = presigned.key !== undefined;
|
|
47
|
+
|
|
48
|
+
if (doUpload) {
|
|
49
|
+
await FileHelper.postPresignedFile(presigned, file, () => { });
|
|
50
|
+
} else {
|
|
51
|
+
console.warn('Upload failed - no presigned key received');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setTabIndex(0);
|
|
55
|
+
loadData();
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Error in handleImageUpdated:', error);
|
|
58
|
+
// In case of API failure, still provide feedback to user
|
|
59
|
+
alert('Image processing completed, but upload failed. API may not be available in this environment.');
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleDelete = (folder: string, image: string) => {
|
|
64
|
+
if (window.confirm(Locale.label("gallery.confirmDelete"))) {
|
|
65
|
+
ApiHelper.delete("/gallery/" + folder + "/" + image, "ContentApi").then(() => { loadData(); });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
React.useEffect(() => { if (aspectRatio !== props.aspectRatio) setAspectRatio(Math.round(props.aspectRatio * 100) / 100) }, [props.aspectRatio]); //eslint-disable-line
|
|
70
|
+
React.useEffect(loadData, [aspectRatio]); //eslint-disable-line
|
|
71
|
+
|
|
72
|
+
const getImages = () => {
|
|
73
|
+
let result: React.ReactElement[] = [];
|
|
74
|
+
images.forEach((img: any, index: number) => {
|
|
75
|
+
const parts = img.split("/");
|
|
76
|
+
|
|
77
|
+
result.push(<Grid key={img || index} size={{ xs: 12, md: 4 }}>
|
|
78
|
+
<Box sx={{ position: "relative", ":hover #deleteIcon": { visibility: "visible" } }}>
|
|
79
|
+
<a href="about:blank" onClick={(e) => { e.preventDefault(); props.onSelect(contentRoot + "/" + img) }} aria-label="Select image" data-testid="select-image">
|
|
80
|
+
<Box
|
|
81
|
+
component="img"
|
|
82
|
+
src={contentRoot + "/" + img}
|
|
83
|
+
alt="custom"
|
|
84
|
+
sx={{
|
|
85
|
+
width: '100%',
|
|
86
|
+
height: 'auto',
|
|
87
|
+
maxWidth: '100%',
|
|
88
|
+
display: 'block'
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
</a>
|
|
92
|
+
<Box id="deleteIcon" sx={{ position: "absolute", top: 3, right: 3, visibility: "hidden", backgroundColor: "whitesmoke", borderRadius: 5 }}>
|
|
93
|
+
<Tooltip title="Delete">
|
|
94
|
+
<IconButton size="small" color="error" onClick={() => handleDelete(parts[2], parts[3])} aria-label="Delete image" data-testid="delete-image">
|
|
95
|
+
<Icon sx={{ fontSize: "17px !important" }}>delete_outline</Icon>
|
|
96
|
+
</IconButton>
|
|
97
|
+
</Tooltip>
|
|
98
|
+
</Box>
|
|
99
|
+
</Box>
|
|
100
|
+
</Grid>);
|
|
101
|
+
})
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const handleStockSelect = (url: string) => {
|
|
106
|
+
setEditorPhotoUrl(url);
|
|
107
|
+
setTabIndex(1);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const getDisplayAspect = () => {
|
|
111
|
+
let result = aspectRatio.toString();
|
|
112
|
+
if (aspectRatio === 0) result = "Free Form";
|
|
113
|
+
else if (aspectRatio === 1) result = "1:1";
|
|
114
|
+
else if (aspectRatio === 2) result = "2:1";
|
|
115
|
+
else if (aspectRatio === 3) result = "3:1";
|
|
116
|
+
else if (aspectRatio === 4) result = "4:1";
|
|
117
|
+
else if (aspectRatio === 1.33) result = "4:3";
|
|
118
|
+
else if (aspectRatio === 1.78) result = "16:9";
|
|
119
|
+
else if (aspectRatio === 0.5) result = "1:2";
|
|
120
|
+
else if (aspectRatio === 0.5625) result = "9:16";
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return (<>
|
|
125
|
+
<Dialog open={true} onClose={props.onClose}>
|
|
126
|
+
<DialogTitle>Select a Photo</DialogTitle>
|
|
127
|
+
<DialogContent style={{ overflowX: "hidden" }}>
|
|
128
|
+
|
|
129
|
+
{(props.aspectRatio === 0) && (
|
|
130
|
+
<FormControl fullWidth>
|
|
131
|
+
<InputLabel>{Locale.label("gallery.aspectRatio")}</InputLabel>
|
|
132
|
+
<Select size="small" label={Locale.label("gallery.aspectRatio")} name="aspectRatio" value={aspectRatio} onChange={(e) => setAspectRatio(parseFloat(e.target.value.toString()))}>
|
|
133
|
+
<MenuItem value="0">{Locale.label("gallery.freeForm")}</MenuItem>
|
|
134
|
+
<MenuItem value="1">1:1</MenuItem>
|
|
135
|
+
<MenuItem value="2">2:1</MenuItem>
|
|
136
|
+
<MenuItem value="3">3:1</MenuItem>
|
|
137
|
+
<MenuItem value="4">4:1</MenuItem>
|
|
138
|
+
<MenuItem value="1.33">4:3</MenuItem>
|
|
139
|
+
<MenuItem value="1.78">16:9</MenuItem>
|
|
140
|
+
<MenuItem value="0.5">1:2</MenuItem>
|
|
141
|
+
<MenuItem value="0.5625">9:16</MenuItem>
|
|
142
|
+
</Select>
|
|
143
|
+
</FormControl>
|
|
144
|
+
)}
|
|
145
|
+
|
|
146
|
+
<Tabs variant="fullWidth" value={tabIndex} onChange={handleTabChange}>
|
|
147
|
+
<Tab label="Gallery" />
|
|
148
|
+
<Tab label="Upload" />
|
|
149
|
+
<Tab label="Stock Photos" />
|
|
150
|
+
</Tabs>
|
|
151
|
+
<TabPanel value={tabIndex} index={0}>
|
|
152
|
+
|
|
153
|
+
<Grid container spacing={3} alignItems="center">
|
|
154
|
+
{getImages()}
|
|
155
|
+
</Grid>
|
|
156
|
+
</TabPanel>
|
|
157
|
+
<TabPanel value={tabIndex} index={1}>
|
|
158
|
+
<div>{Locale.label("gallery.aspectRatio")}: {getDisplayAspect()}</div>
|
|
159
|
+
<ImageEditor onUpdate={handleImageUpdated} photoUrl={editorPhotoUrl} aspectRatio={aspectRatio} outputWidth={1280} outputHeight={768} hideDelete={true} />
|
|
160
|
+
</TabPanel>
|
|
161
|
+
<TabPanel value={tabIndex} index={2}>
|
|
162
|
+
<StockPhotos aspectRatio={aspectRatio} onSelect={props.onSelect} onStockSelect={handleStockSelect} />
|
|
163
|
+
</TabPanel>
|
|
164
|
+
</DialogContent>
|
|
165
|
+
<DialogActions sx={{ paddingX: "16px", paddingBottom: "12px" }}>
|
|
166
|
+
<Button variant="outlined" onClick={props.onClose}>Close</Button>
|
|
167
|
+
</DialogActions>
|
|
168
|
+
</Dialog>
|
|
169
|
+
</>);
|
|
170
170
|
};
|