@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrivateMessageDetails.d.ts","sourceRoot":"","sources":["../../../src/components/wrapper/PrivateMessageDetails.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PrivateMessageDetails.d.ts","sourceRoot":"","sources":["../../../src/components/wrapper/PrivateMessageDetails.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAKpF,UAAU,KAAK;IACb,OAAO,EAAE,oBAAoB,CAAC;IAC9B,cAAc,EAAE,uBAAuB,CAAC;IACxC,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAgFjD,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import React from "react";
|
|
4
|
-
import { Paper, Box, Typography, Stack, IconButton
|
|
4
|
+
import { Paper, Box, Typography, Stack, IconButton } from "@mui/material";
|
|
5
5
|
import { ArrowBack as ArrowBackIcon } from "@mui/icons-material";
|
|
6
6
|
import { Notes } from "../notes/Notes";
|
|
7
7
|
import { ApiHelper, Locale, NotificationService } from "../../helpers";
|
|
8
8
|
import { PersonAvatar } from "../PersonAvatar";
|
|
9
9
|
export const PrivateMessageDetails = (props) => {
|
|
10
|
-
const theme = useTheme();
|
|
11
10
|
// Clear notification when conversation is opened
|
|
12
11
|
React.useEffect(() => {
|
|
13
12
|
const clearNotification = async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrivateMessageDetails.js","sourceRoot":"","sources":["../../../src/components/wrapper/PrivateMessageDetails.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,KAAK,EACL,GAAG,EACH,UAAU,EACV,KAAK,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"PrivateMessageDetails.js","sourceRoot":"","sources":["../../../src/components/wrapper/PrivateMessageDetails.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,KAAK,EACL,GAAG,EACH,UAAU,EACV,KAAK,EACL,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,MAAM,CAAC,MAAM,qBAAqB,GAAoB,CAAC,KAAK,EAAE,EAAE;IAE9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"use client";
|
|
2
|
-
|
|
3
|
-
import React, { useState, useEffect, useRef, Suspense, lazy } from "react";
|
|
4
|
-
import { InputBox, SmallButton, Loading } from ".";
|
|
5
|
-
import { Locale } from "../helpers";
|
|
6
|
-
import "../../public/css/cropper.css";
|
|
7
|
-
|
|
8
|
-
// Lazy load the Cropper component
|
|
9
|
-
const Cropper = lazy(() => import("react-cropper").then(module => ({ default: module.default })));
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
title?: string;
|
|
13
|
-
photoUrl: string;
|
|
14
|
-
aspectRatio: number;
|
|
15
|
-
onUpdate: (dataUrl?: string) => void;
|
|
16
|
-
onCancel?: () => void;
|
|
17
|
-
outputWidth?: number;
|
|
18
|
-
outputHeight?: number;
|
|
19
|
-
hideDelete?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function ImageEditor(props: Props) {
|
|
23
|
-
const [photoSrc, setPhotoSrc] = useState<string>("");
|
|
24
|
-
const [croppedImageDataUrl, setCroppedImageDataUrl] = useState<string>("");
|
|
25
|
-
const cropperRef = useRef<HTMLImageElement>(null);
|
|
26
|
-
const timeoutRef = useRef<number | null>(null);
|
|
27
|
-
|
|
28
|
-
// Cleanup timeout on unmount
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
return () => {
|
|
31
|
-
if (timeoutRef.current !== null) {
|
|
32
|
-
window.clearTimeout(timeoutRef.current);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
const handleSave = () => {
|
|
38
|
-
props.onUpdate(croppedImageDataUrl);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const handleDelete = () => props.onUpdate("");
|
|
42
|
-
|
|
43
|
-
const handleUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
44
|
-
e.preventDefault();
|
|
45
|
-
let files;
|
|
46
|
-
if (e.target) {
|
|
47
|
-
files = e.target.files;
|
|
48
|
-
}
|
|
49
|
-
if (!files || files.length === 0) return;
|
|
50
|
-
|
|
51
|
-
const reader = new FileReader();
|
|
52
|
-
reader.onload = () => {
|
|
53
|
-
const url = reader.result.toString();
|
|
54
|
-
setPhotoSrc(url);
|
|
55
|
-
setCroppedImageDataUrl("");
|
|
56
|
-
};
|
|
57
|
-
reader.readAsDataURL(files[0]);
|
|
58
|
-
|
|
59
|
-
// Clear the input value to allow re-uploading the same file
|
|
60
|
-
e.target.value = "";
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const selectDefaultCropZone = () => {
|
|
64
|
-
const imageElement: any = cropperRef?.current;
|
|
65
|
-
let cropper: any = imageElement?.cropper;
|
|
66
|
-
if (props.aspectRatio===0)
|
|
67
|
-
{
|
|
68
|
-
let containerData = cropper.getContainerData();
|
|
69
|
-
const imgWidth = cropper.getImageData().width;
|
|
70
|
-
const imgHeight = cropper.getImageData().height;
|
|
71
|
-
const effectiveWidth = (containerData.width > imgWidth) ? imgWidth : containerData.width;
|
|
72
|
-
const effectiveHeight = (containerData.height > imgHeight) ? imgHeight : containerData.height;
|
|
73
|
-
cropper.setCropBoxData({ width: effectiveWidth, height: effectiveHeight, left: (containerData.width - effectiveWidth) / 2.0 , top: (containerData.height - effectiveHeight) / 2.0 });
|
|
74
|
-
} else {
|
|
75
|
-
let desiredAspect = props.aspectRatio;
|
|
76
|
-
let containerData = cropper.getContainerData();
|
|
77
|
-
let imgAspect = cropper.getImageData().aspectRatio;
|
|
78
|
-
let scale = imgAspect / desiredAspect;
|
|
79
|
-
if (scale < 1) {
|
|
80
|
-
const imgWidth = cropper.getImageData().width;
|
|
81
|
-
let l = (containerData.width - imgWidth) / 2.0;
|
|
82
|
-
let t = (containerData.height - (containerData.height * scale)) / 2.0;
|
|
83
|
-
cropper.setCropBoxData({ width: imgWidth, height: imgWidth / desiredAspect, left: l, top: t });
|
|
84
|
-
} else {
|
|
85
|
-
const imgHeight = cropper.getImageData().height;
|
|
86
|
-
let l = (containerData.width - (imgHeight * desiredAspect)) / 2.0;
|
|
87
|
-
let t = cropper.canvasData.top;
|
|
88
|
-
cropper.setCropBoxData({ width: imgHeight * desiredAspect, height: imgHeight, left: l, top: t });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const handleCrop = () => {
|
|
95
|
-
if (timeoutRef.current !== null) {
|
|
96
|
-
window.clearTimeout(timeoutRef.current);
|
|
97
|
-
timeoutRef.current = null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
timeoutRef.current = window.setTimeout(() => {
|
|
101
|
-
if (cropperRef.current !== null) {
|
|
102
|
-
const imageElement: any = cropperRef?.current;
|
|
103
|
-
const cropper: any = imageElement?.cropper;
|
|
104
|
-
|
|
105
|
-
//Do not enlarge if less
|
|
106
|
-
const imageData = cropper.getImageData();
|
|
107
|
-
let width = props.outputWidth || 400;
|
|
108
|
-
let height = props.outputHeight || 300;
|
|
109
|
-
if (imageData.naturalWidth < width && imageData.naturalHeight < height) {
|
|
110
|
-
width = imageData.naturalWidth;
|
|
111
|
-
height = imageData.naturalHeight;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const url = cropper.getCroppedCanvas({ width, height }).toDataURL("image/png", 0.4);
|
|
115
|
-
setCroppedImageDataUrl(url);
|
|
116
|
-
}
|
|
117
|
-
}, 200);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
useEffect(() => { setPhotoSrc(props.photoUrl); }, [props.photoUrl]);
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<InputBox
|
|
124
|
-
id="cropperBox"
|
|
125
|
-
headerIcon=""
|
|
126
|
-
headerText={props.title}
|
|
127
|
-
ariaLabelDelete="deletePhoto"
|
|
128
|
-
saveText={Locale.label("common.update")}
|
|
129
|
-
saveFunction={handleSave}
|
|
130
|
-
cancelFunction={props.onCancel}
|
|
131
|
-
deleteFunction={(!props.hideDelete) && handleDelete}
|
|
132
|
-
headerActionContent={
|
|
133
|
-
<div>
|
|
134
|
-
<input type="file" onChange={handleUpload} id="fileUpload" accept="image/*" style={{ display: "none" }} />
|
|
135
|
-
<SmallButton
|
|
136
|
-
icon="upload"
|
|
137
|
-
text="Upload"
|
|
138
|
-
onClick={() => {
|
|
139
|
-
document.getElementById("fileUpload").click();
|
|
140
|
-
}}
|
|
141
|
-
/>
|
|
142
|
-
</div>
|
|
143
|
-
}
|
|
144
|
-
>
|
|
145
|
-
<Suspense fallback={<Loading />}>
|
|
146
|
-
<Cropper
|
|
147
|
-
ref={cropperRef}
|
|
148
|
-
src={photoSrc}
|
|
149
|
-
key={photoSrc}
|
|
150
|
-
style={{ height: 240, width: "100%" }}
|
|
151
|
-
aspectRatio={props.aspectRatio}
|
|
152
|
-
guides={false}
|
|
153
|
-
crop={handleCrop}
|
|
154
|
-
autoCropArea={1}
|
|
155
|
-
viewMode={0}
|
|
156
|
-
responsive={true}
|
|
157
|
-
restore={false}
|
|
158
|
-
checkOrientation={false}
|
|
159
|
-
background={false}
|
|
160
|
-
ready={() => {
|
|
161
|
-
setTimeout(selectDefaultCropZone, 100);
|
|
162
|
-
}}
|
|
163
|
-
/>
|
|
164
|
-
</Suspense>
|
|
165
|
-
</InputBox>
|
|
166
|
-
);
|
|
167
|
-
}
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect, useRef, Suspense, lazy } from "react";
|
|
4
|
+
import { InputBox, SmallButton, Loading } from ".";
|
|
5
|
+
import { Locale } from "../helpers";
|
|
6
|
+
import "../../public/css/cropper.css";
|
|
7
|
+
|
|
8
|
+
// Lazy load the Cropper component
|
|
9
|
+
const Cropper = lazy(() => import("react-cropper").then(module => ({ default: module.default })));
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
title?: string;
|
|
13
|
+
photoUrl: string;
|
|
14
|
+
aspectRatio: number;
|
|
15
|
+
onUpdate: (dataUrl?: string) => void;
|
|
16
|
+
onCancel?: () => void;
|
|
17
|
+
outputWidth?: number;
|
|
18
|
+
outputHeight?: number;
|
|
19
|
+
hideDelete?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function ImageEditor(props: Props) {
|
|
23
|
+
const [photoSrc, setPhotoSrc] = useState<string>("");
|
|
24
|
+
const [croppedImageDataUrl, setCroppedImageDataUrl] = useState<string>("");
|
|
25
|
+
const cropperRef = useRef<HTMLImageElement>(null);
|
|
26
|
+
const timeoutRef = useRef<number | null>(null);
|
|
27
|
+
|
|
28
|
+
// Cleanup timeout on unmount
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
return () => {
|
|
31
|
+
if (timeoutRef.current !== null) {
|
|
32
|
+
window.clearTimeout(timeoutRef.current);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
const handleSave = () => {
|
|
38
|
+
props.onUpdate(croppedImageDataUrl);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const handleDelete = () => props.onUpdate("");
|
|
42
|
+
|
|
43
|
+
const handleUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
let files;
|
|
46
|
+
if (e.target) {
|
|
47
|
+
files = e.target.files;
|
|
48
|
+
}
|
|
49
|
+
if (!files || files.length === 0) return;
|
|
50
|
+
|
|
51
|
+
const reader = new FileReader();
|
|
52
|
+
reader.onload = () => {
|
|
53
|
+
const url = reader.result.toString();
|
|
54
|
+
setPhotoSrc(url);
|
|
55
|
+
setCroppedImageDataUrl("");
|
|
56
|
+
};
|
|
57
|
+
reader.readAsDataURL(files[0]);
|
|
58
|
+
|
|
59
|
+
// Clear the input value to allow re-uploading the same file
|
|
60
|
+
e.target.value = "";
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const selectDefaultCropZone = () => {
|
|
64
|
+
const imageElement: any = cropperRef?.current;
|
|
65
|
+
let cropper: any = imageElement?.cropper;
|
|
66
|
+
if (props.aspectRatio===0)
|
|
67
|
+
{
|
|
68
|
+
let containerData = cropper.getContainerData();
|
|
69
|
+
const imgWidth = cropper.getImageData().width;
|
|
70
|
+
const imgHeight = cropper.getImageData().height;
|
|
71
|
+
const effectiveWidth = (containerData.width > imgWidth) ? imgWidth : containerData.width;
|
|
72
|
+
const effectiveHeight = (containerData.height > imgHeight) ? imgHeight : containerData.height;
|
|
73
|
+
cropper.setCropBoxData({ width: effectiveWidth, height: effectiveHeight, left: (containerData.width - effectiveWidth) / 2.0 , top: (containerData.height - effectiveHeight) / 2.0 });
|
|
74
|
+
} else {
|
|
75
|
+
let desiredAspect = props.aspectRatio;
|
|
76
|
+
let containerData = cropper.getContainerData();
|
|
77
|
+
let imgAspect = cropper.getImageData().aspectRatio;
|
|
78
|
+
let scale = imgAspect / desiredAspect;
|
|
79
|
+
if (scale < 1) {
|
|
80
|
+
const imgWidth = cropper.getImageData().width;
|
|
81
|
+
let l = (containerData.width - imgWidth) / 2.0;
|
|
82
|
+
let t = (containerData.height - (containerData.height * scale)) / 2.0;
|
|
83
|
+
cropper.setCropBoxData({ width: imgWidth, height: imgWidth / desiredAspect, left: l, top: t });
|
|
84
|
+
} else {
|
|
85
|
+
const imgHeight = cropper.getImageData().height;
|
|
86
|
+
let l = (containerData.width - (imgHeight * desiredAspect)) / 2.0;
|
|
87
|
+
let t = cropper.canvasData.top;
|
|
88
|
+
cropper.setCropBoxData({ width: imgHeight * desiredAspect, height: imgHeight, left: l, top: t });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const handleCrop = () => {
|
|
95
|
+
if (timeoutRef.current !== null) {
|
|
96
|
+
window.clearTimeout(timeoutRef.current);
|
|
97
|
+
timeoutRef.current = null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
101
|
+
if (cropperRef.current !== null) {
|
|
102
|
+
const imageElement: any = cropperRef?.current;
|
|
103
|
+
const cropper: any = imageElement?.cropper;
|
|
104
|
+
|
|
105
|
+
//Do not enlarge if less
|
|
106
|
+
const imageData = cropper.getImageData();
|
|
107
|
+
let width = props.outputWidth || 400;
|
|
108
|
+
let height = props.outputHeight || 300;
|
|
109
|
+
if (imageData.naturalWidth < width && imageData.naturalHeight < height) {
|
|
110
|
+
width = imageData.naturalWidth;
|
|
111
|
+
height = imageData.naturalHeight;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const url = cropper.getCroppedCanvas({ width, height }).toDataURL("image/png", 0.4);
|
|
115
|
+
setCroppedImageDataUrl(url);
|
|
116
|
+
}
|
|
117
|
+
}, 200);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
useEffect(() => { setPhotoSrc(props.photoUrl); }, [props.photoUrl]);
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<InputBox
|
|
124
|
+
id="cropperBox"
|
|
125
|
+
headerIcon=""
|
|
126
|
+
headerText={props.title}
|
|
127
|
+
ariaLabelDelete="deletePhoto"
|
|
128
|
+
saveText={Locale.label("common.update")}
|
|
129
|
+
saveFunction={handleSave}
|
|
130
|
+
cancelFunction={props.onCancel}
|
|
131
|
+
deleteFunction={(!props.hideDelete) && handleDelete}
|
|
132
|
+
headerActionContent={
|
|
133
|
+
<div>
|
|
134
|
+
<input type="file" onChange={handleUpload} id="fileUpload" accept="image/*" style={{ display: "none" }} />
|
|
135
|
+
<SmallButton
|
|
136
|
+
icon="upload"
|
|
137
|
+
text="Upload"
|
|
138
|
+
onClick={() => {
|
|
139
|
+
document.getElementById("fileUpload").click();
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
</div>
|
|
143
|
+
}
|
|
144
|
+
>
|
|
145
|
+
<Suspense fallback={<Loading />}>
|
|
146
|
+
<Cropper
|
|
147
|
+
ref={cropperRef}
|
|
148
|
+
src={photoSrc}
|
|
149
|
+
key={photoSrc}
|
|
150
|
+
style={{ height: 240, width: "100%" }}
|
|
151
|
+
aspectRatio={props.aspectRatio}
|
|
152
|
+
guides={false}
|
|
153
|
+
crop={handleCrop}
|
|
154
|
+
autoCropArea={1}
|
|
155
|
+
viewMode={0}
|
|
156
|
+
responsive={true}
|
|
157
|
+
restore={false}
|
|
158
|
+
checkOrientation={false}
|
|
159
|
+
background={false}
|
|
160
|
+
ready={() => {
|
|
161
|
+
setTimeout(selectDefaultCropZone, 100);
|
|
162
|
+
}}
|
|
163
|
+
/>
|
|
164
|
+
</Suspense>
|
|
165
|
+
</InputBox>
|
|
166
|
+
);
|
|
167
|
+
}
|