From 404ce309b87f4876559c01520f52b9672c563998 Mon Sep 17 00:00:00 2001 From: dominic Date: Tue, 3 Sep 2024 14:16:23 +0100 Subject: [PATCH 1/3] feat(post-input): create and add new post input component with media selection functionality --- .../feed/components/create-post/index.tsx | 104 -------- .../components/create-post/styles.module.scss | 64 ----- .../feed/components/post-input/container.tsx | 61 +++++ .../feed/components/post-input/index.test.tsx | 104 ++++++++ .../feed/components/post-input/index.tsx | 231 ++++++++++++++++++ .../feed/components/post-input/styles.scss | 80 ++++++ src/components/messenger/feed/index.test.tsx | 4 +- src/components/messenger/feed/index.tsx | 18 +- 8 files changed, 485 insertions(+), 181 deletions(-) delete mode 100644 src/components/messenger/feed/components/create-post/index.tsx delete mode 100644 src/components/messenger/feed/components/create-post/styles.module.scss create mode 100644 src/components/messenger/feed/components/post-input/container.tsx create mode 100644 src/components/messenger/feed/components/post-input/index.test.tsx create mode 100644 src/components/messenger/feed/components/post-input/index.tsx create mode 100644 src/components/messenger/feed/components/post-input/styles.scss diff --git a/src/components/messenger/feed/components/create-post/index.tsx b/src/components/messenger/feed/components/create-post/index.tsx deleted file mode 100644 index e7daed194..000000000 --- a/src/components/messenger/feed/components/create-post/index.tsx +++ /dev/null @@ -1,104 +0,0 @@ -import { useEffect, useRef, useState } from 'react'; - -import { motion, AnimatePresence } from 'framer-motion'; -import { Avatar, Button } from '@zero-tech/zui/components'; - -import { Key } from '../../../../../lib/keyboard-search'; - -import styles from './styles.module.scss'; - -interface CreatePostProps { - avatarUrl?: string; - isSubmitting?: boolean; - - onSubmit: (message: string) => void; -} - -export const CreatePost = ({ avatarUrl, isSubmitting, onSubmit }: CreatePostProps) => { - const [value, setValue] = useState(''); - const isDisabled = !value.trim() || isSubmitting; - - const handleOnChange = (event: React.ChangeEvent) => { - setValue(event.target.value); - }; - - const handleKeyDown = (event: React.KeyboardEvent) => { - if (!event.shiftKey && event.key === Key.Enter) { - event.preventDefault(); - handleOnSubmit(); - } - }; - - const handleOnSubmit = () => { - if (value.trim()) { - onSubmit(value); - setValue(''); - } - }; - - return ( -
-
- -
-
-
- - {isSubmitting && ( - - )} - - -
-
-
-
- -
-
-
- ); -}; - -interface PostInputProps { - onChange: (event: React.ChangeEvent) => void; - onKeyDown: (event: React.KeyboardEvent) => void; - value: string; -} - -const PostInput = ({ onChange, onKeyDown, value }: PostInputProps) => { - const ref = useRef(null); - - useEffect(() => { - if (ref.current) { - ref.current.style.height = 'auto'; - ref.current.style.height = `${ref.current.scrollHeight}px`; - - // Auto-resize on input - ref.current.addEventListener('input', () => { - ref.current.style.height = 'auto'; - ref.current.style.height = `${ref.current.scrollHeight}px`; - }); - } - }, []); - - return ( -