From 3930d8fba5ba495fb24d6d3fe6e05f04abcfbcc3 Mon Sep 17 00:00:00 2001 From: Vicky Chen <56861768+viiiiiicccky@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:25:28 -0700 Subject: [PATCH] 34 add photo thumbnail to the UI (#37) * move likes to the left corner * add photo thumbnail to the top right corner * add photo thumbnail to the top right corner * making photo thumbnail smaller * small fix for comments flow making sure it flows from the top on a longer screen * fixing likes, making sure they are at the left side * increasing margins --------- Co-authored-by: Vicky Chen Co-authored-by: Natalie Chan --- client/components/comments/comment.tsx | 8 ++++---- client/components/comments/commentFeed.tsx | 7 +++---- client/components/likes/likes.tsx | 4 +--- client/components/photo/photo.tsx | 9 +++++++++ client/pages/backend.tsx | 3 +-- client/pages/index.tsx | 20 +++++++++++++++++--- 6 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 client/components/photo/photo.tsx diff --git a/client/components/comments/comment.tsx b/client/components/comments/comment.tsx index 2dd6485..fa81aff 100644 --- a/client/components/comments/comment.tsx +++ b/client/components/comments/comment.tsx @@ -10,10 +10,10 @@ interface CommentProps { const Comment: React.FC = ({ comment }) => { return ( <>

diff --git a/client/components/comments/commentFeed.tsx b/client/components/comments/commentFeed.tsx index 3dd9f20..31f8ef6 100644 --- a/client/components/comments/commentFeed.tsx +++ b/client/components/comments/commentFeed.tsx @@ -51,11 +51,10 @@ const CommentFeed: React.FC = ({ comments, onComplete }) => { }, [commentsIndex]); return ( -
-
+
+
{displayedComments.map((comment) => ( diff --git a/client/components/likes/likes.tsx b/client/components/likes/likes.tsx index 2555018..15e15d7 100644 --- a/client/components/likes/likes.tsx +++ b/client/components/likes/likes.tsx @@ -84,11 +84,9 @@ export const Likes = ({ finalLikes, onComplete }: LikesProps) => { }, [finalLikes]); // reset when finalLikes is updated return ( -
-
+

❤️

{animatedLikes}

-
); }; diff --git a/client/components/photo/photo.tsx b/client/components/photo/photo.tsx new file mode 100644 index 0000000..5c85de5 --- /dev/null +++ b/client/components/photo/photo.tsx @@ -0,0 +1,9 @@ +export const Photo = ({ img }: { img: string }) => { + if (!img) return null; + + return ( +
+ Received image +
+ ); +}; diff --git a/client/pages/backend.tsx b/client/pages/backend.tsx index 0f83102..2722db1 100644 --- a/client/pages/backend.tsx +++ b/client/pages/backend.tsx @@ -1,7 +1,6 @@ import { useEffect, useState } from 'react'; import { socket } from '../utils/socket'; import { ResponseData } from '../../shared/types'; -import Image from 'next/image'; const Backend = () => { const [img, setImg] = useState(''); @@ -41,7 +40,7 @@ const Backend = () => { return ( <>
Welcome to the backend ui!
- {img && Received image} + {img && Received image} ); }; diff --git a/client/pages/index.tsx b/client/pages/index.tsx index ad04ff4..3c43502 100644 --- a/client/pages/index.tsx +++ b/client/pages/index.tsx @@ -5,6 +5,7 @@ import CommentFeed from '@/components/comments/commentFeed'; import { ResponseData } from '../../shared/types'; import { LoadingOverlay } from '@/components/loadingOverlay/loadingOverlay'; import { EndingOverlay } from '@/components/endingOverlay/endingOverlay'; +import { Photo } from '@/components/photo/photo'; const Home = () => { const intervalRef = useRef | null>(null); // test timer @@ -17,6 +18,7 @@ const Home = () => { const [commentsComplete, setCommentsComplete] = useState(false); const [isLoading, setIsLoading] = useState(true); + const [img, setImg] = useState(''); useEffect(() => { console.log('Connecting Socket'); @@ -43,6 +45,11 @@ const Home = () => { } }; + const onSendPhoto = (data: string) => { + console.log('Received image data'); + setImg(`data:image/jpeg;base64,${data}`); + }; + const onErrorMessage = (msg: string) => { // on error take a new photo console.error(msg); @@ -51,6 +58,7 @@ const Home = () => { socket.on('connect', onConnect); socket.on('api_response', onApiResonse); + socket.on('send_photo', onSendPhoto); socket.on('err_msg', onErrorMessage); return () => { @@ -59,6 +67,7 @@ const Home = () => { // clean up socket event listeners socket.off('connect', onConnect); socket.off('api_response', onApiResonse); + socket.off('send_photo', onSendPhoto); if (intervalRef.current) { clearInterval(intervalRef.current); @@ -76,7 +85,7 @@ const Home = () => { console.log('Likes and comments animation completed'); setLikesComplete(false); setCommentsComplete(false); - + setImg(''); donePhoto(); } // fire useEffect when either state vars change @@ -112,10 +121,14 @@ const Home = () => { return ( <> -
+
{display ? ( <> - +
+ + {img && !(likesComplete && commentsComplete) && } +
+ ) : ( @@ -129,6 +142,7 @@ const Home = () => { )} )} +
);