diff --git a/code/frontend/src/pages/PostCreation.tsx b/code/frontend/src/pages/PostCreation.tsx index 2c12d7c..799238a 100644 --- a/code/frontend/src/pages/PostCreation.tsx +++ b/code/frontend/src/pages/PostCreation.tsx @@ -13,12 +13,19 @@ import "../styles/sizes.css"; import "../styles/fonts.css"; import AspectRatio from '@mui/joy/AspectRatio'; -import Box from '@mui/joy/Box'; -import Card from '@mui/joy/Card'; -import IconButton from '@mui/joy/IconButton'; import api from "../api/axios"; import { useAuth } from "../api/Auth"; +import { + Box, + Card, + CardMedia, + CardActionArea, + IconButton, + Skeleton, + StyledEngineProvider, +} from '@mui/material'; +import CloseIcon from '@mui/icons-material/Close'; function PostCreation(){ const {user} = useAuth(); @@ -37,15 +44,6 @@ function PostCreation(){ title: string; } - type FormData = { - images: Array; - status: string; - description: string; - tags: Array; - } - - - const initialOptions = startTags.map((option) => option.title); const [options, setOptions] = useState(initialOptions); @@ -56,7 +54,6 @@ function PostCreation(){ const [data, setData] = useState([]); const navigate = useNavigate(); - const [fileList,setFileList] = useState(null); const handleChange = (event: React.ChangeEvent) => { @@ -87,8 +84,14 @@ function PostCreation(){ } setFileList(files); }; - const handleDelete = (idx: number) => + const handleDelete = (idx: number) =>{ setData((prev) => prev.filter((_, i) => i !== idx)); + if((idx-1)<0){ + if(data.length == 1){setSelectedImage("");} + else{setSelectedImage(data[idx+1].src);} + } + else {setSelectedImage(data[idx-1].src);} + } const onSubmit = async(event: React.FormEvent) =>{ event.preventDefault(); @@ -120,16 +123,19 @@ function PostCreation(){ const files = fileList ? [...fileList] : []; return( +

Create Post

- OP + OP {user?.username}
- Add an Image + {selectedImage? + Add an Image: + }
@@ -141,63 +147,84 @@ function PostCreation(){ overflowX: 'auto', overflowY: 'hidden', width: '100%', - maxWidth: {xs:'90vw', sm:'600px'}, - mx: 'auto', // center the box + maxWidth: { xs: '90vw', sm: '600px' }, + mx: 'auto', scrollSnapType: 'x mandatory', '& > *': { scrollSnapAlign: 'center' }, - '::-webkit-scrollbar': { display: 'none', flexShrink: '0' }, + '::-webkit-scrollbar': { display: 'none' }, }} > {/* Upload card */} - - - - + + {/* Image cards */} {data.map((item, idx) => ( setSelectedImage(item.src)} > - {/* delete pill */} + {/* Delete button */} { - e.stopPropagation(); + e.stopPropagation(); handleDelete(idx); }} sx={{ position: 'absolute', top: 2, right: 2, - bgcolor: 'background.body', + backgroundColor: 'background.paper', zIndex: 1, }} > - + - - {item.title} - + + + ))} +
+ ); } export default PostCreation; \ No newline at end of file