Add size limit modal (#95)
This commit is contained in:
parent
4711dc620f
commit
f8dbe5a2b7
|
@ -10,6 +10,7 @@ import { GifIcon } from "../Icons/GifIcon";
|
||||||
import { PictureIcon } from "../Icons/PictureIcon";
|
import { PictureIcon } from "../Icons/PictureIcon";
|
||||||
import { StickerIcon } from "../Icons/StickerIcon";
|
import { StickerIcon } from "../Icons/StickerIcon";
|
||||||
import "emoji-mart/css/emoji-mart.css";
|
import "emoji-mart/css/emoji-mart.css";
|
||||||
|
import { Modal } from "../Modals/Modal";
|
||||||
|
|
||||||
type ChatInputProps = {
|
type ChatInputProps = {
|
||||||
theme: Theme;
|
theme: Theme;
|
||||||
|
@ -21,7 +22,7 @@ export function ChatInput({ theme, addMessage }: ChatInputProps) {
|
||||||
const [showEmoji, setShowEmoji] = useState(false);
|
const [showEmoji, setShowEmoji] = useState(false);
|
||||||
const [inputHeight, setInputHeight] = useState(40);
|
const [inputHeight, setInputHeight] = useState(40);
|
||||||
const [imageUint, setImageUint] = useState<undefined | Uint8Array>(undefined);
|
const [imageUint, setImageUint] = useState<undefined | Uint8Array>(undefined);
|
||||||
|
const [showSizeLimit, setShowSizeLimit] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.addEventListener("click", () => setShowEmoji(false));
|
window.addEventListener("click", () => setShowEmoji(false));
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -71,6 +72,14 @@ export function ChatInput({ theme, addMessage }: ChatInputProps) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
|
<Modal onClose={() => setShowSizeLimit(false)} isVisible={showSizeLimit}>
|
||||||
|
<div
|
||||||
|
onClick={() => setShowSizeLimit(false)}
|
||||||
|
style={{ padding: "20px" }}
|
||||||
|
>
|
||||||
|
File size must be less than 1MB
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
{showEmoji && (
|
{showEmoji && (
|
||||||
<div>
|
<div>
|
||||||
<Picker
|
<Picker
|
||||||
|
@ -106,8 +115,13 @@ export function ChatInput({ theme, addMessage }: ChatInputProps) {
|
||||||
const arr = new Uint8Array(s.target?.result as ArrayBuffer);
|
const arr = new Uint8Array(s.target?.result as ArrayBuffer);
|
||||||
setImageUint(arr);
|
setImageUint(arr);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (e?.target?.files?.[0]) {
|
if (e?.target?.files?.[0]) {
|
||||||
fileReader.readAsArrayBuffer(e.target.files[0]);
|
if (e.target.files[0].size < 1024 * 1024) {
|
||||||
|
fileReader.readAsArrayBuffer(e.target.files[0]);
|
||||||
|
} else {
|
||||||
|
setShowSizeLimit(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue