Skip to content

Commit

Permalink
Make a post functionlity is added. (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
KalyanMatta-SDE authored Aug 7, 2024
1 parent d778882 commit e01aeb8
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 1 deletion.
42 changes: 42 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"@types/react-dom": "^18.2.0",
"@types/react-router-dom": "^5.1.7",
"axios": "^0.26.1",
"classname": "^0.0.0",
"classnames": "^2.5.1",
"jest": "26.6.0",
"jsonwebtoken": "^9.0.0",
"react": "^18.2.0",
Expand Down Expand Up @@ -57,6 +59,7 @@
]
},
"devDependencies": {
"@types/classnames": "^2.3.1",
"@types/jest": "^26.0.23",
"@types/jsonwebtoken": "^8.5.4",
"@types/node": "^15.6.0",
Expand Down
21 changes: 20 additions & 1 deletion client/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ function Header() {
history.push('/');
};

const handleMakePostClick = () => {
history.push(routes.MakePost.path); // Ensure this matches your route definition
};

return (
<AppBar position="sticky" className={classes.appBar} color="inherit">
{/* if no color defaults to primary */}
Expand All @@ -168,7 +172,22 @@ function Header() {
<IconButton size="large">{/* Mailbox icon here */}</IconButton>
<IconButton size="large">{/* Bell icon here */}</IconButton>
<IconButton size="large">{/* Profile icon here */}</IconButton>

<Button
onClick={() => handleMakePostClick()}
sx={{
textTransform: 'capitalize',
color: '#323232',
fontWeight: 400,
marginRight: '1.5em',
border: 0,
'&:hover, &:active, &[aria-expanded="true"]': {
fontWeight: 600,
backgroundColor: 'transparent',
},
}}
>
Make a Post
</Button>
<Button
id="exchange-button"
aria-label="exchange dropdown"
Expand Down
6 changes: 6 additions & 0 deletions client/src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SignupCitizen from '../views/SignupCitizen';
import SignupNonProfit from '../views/SignupNonProfit';
import Inbox from '../views/Inbox';
import User from '../views/User';
import MakePost from '../views/MakePost';
import ActionForm from '../views/ActionForm';
import SearchResults from '../views/SearchResults';
import Asset from '../views/Asset';
Expand Down Expand Up @@ -117,6 +118,11 @@ const routes: RouteMap = {
roles: [],
path: '/my-profile',
},
MakePost: {
component: MakePost,
roles: [],
path: '/make-a-post',
},
ActionForm: {
component: ActionForm,
roles: [],
Expand Down
4 changes: 4 additions & 0 deletions client/src/views/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
SignupNonProfit,
Inbox,
User,
MakePost,
ActionForm,
Assets,
Asset,
Expand Down Expand Up @@ -63,6 +64,9 @@ function Main() {
<Route exact path={Assets.path} component={Assets.component} />
<Route exact path={Asset.path} component={Asset.component} />

{/*Make a post Route */}
<Route exact path={MakePost.path} component={MakePost.component} />

{/* Private Routes */}
<Route exact path={User.path} render={renderPrivateRoute(User.roles, User.component)} />

Expand Down
151 changes: 151 additions & 0 deletions client/src/views/MakePost.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import React, { useState } from 'react';
import { Grid, Typography, Card, Button } from '@mui/material';

const MakePost = () => {
const [selected, setSelected] = useState<string | null>(null);
const [step, setStep] = useState(1);

const handleCardClick = (id: string) => {
setSelected(id);
};

const handleNextClick = () => {
if (step === 1 && selected) {
setStep(2);
setSelected(null);
}
};

const handleBackClick = () => {
if (step === 2) {
setStep(1);
setSelected(null);
}
};

const styles = {
card: (isSelected: boolean) => ({
display: 'flex',
flexDirection: 'column' as const,
height: '550px',
width: '520px',
margin: '10px',
position: 'relative' as const,
cursor: 'pointer',
transition: 'opacity 0.3s ease-in-out',
opacity: isSelected ? 0.8 : 1,
}),
image: {
height: '70%',
backgroundColor: '#ffc958',
},
textContainer: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '30%',
},
overlay: (isSelected: boolean) => ({
position: 'absolute' as const,
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: isSelected ? 'rgba(0, 0, 0, 0.5)' : 'transparent',
transition: 'background-color 0.3s ease-in-out',
pointerEvents: 'none' as const,
}),
button: (isDisabled: boolean) => ({
marginTop: '30px',
marginBottom: '10px !important',
color: isDisabled ? 'white' : 'black',
backgroundColor: isDisabled ? 'lightgrey' : 'white',
boxShadow: '0 3px 5px 2px rgba(0, 0, 0, .3)',
alignSelf: 'flex-end',
cursor: isDisabled ? 'default' : 'pointer',
'&:hover': {
backgroundColor: isDisabled ? 'lightgrey' : 'lightgrey',
},
}),
backButton: {
marginTop: '30px',
marginBottom: '10px !important',
color: 'black',
backgroundColor: 'white',
boxShadow: '0 3px 5px 2px rgba(0, 0, 0, .3)',
alignSelf: 'flex-start',
cursor: 'pointer',
'&:hover': {
backgroundColor: 'lightgrey',
},
},
title: {
color: 'rgb(85, 26, 139)',
fontSize: '4.2em',
transition: 'all 0.3s ease-in-out',
},
text: {
fontSize: '1.9em !important',
fontWeight: 'bold',
transition: 'font-size 0.3s ease-in-out, color 0.3s ease-in-out',
},
buttonContainer: {
display: 'flex',
justifyContent: step === 1 ? 'flex-end' : 'space-between',
width: '50%', // Changed to 50% to ensure correct alignment
marginTop: '20px',
},
};

const title = step === 1 ? 'What is your post for?' : 'What would you like to do?';
const cards =
step === 1
? [
{ id: 'goods', text: 'Goods' },
{ id: 'skills', text: 'Skills' },
]
: [
{ id: 'need', text: 'Share a Need' },
{ id: 'offer', text: 'Make an Offer' },
];

return (
<Grid container direction="column" alignItems="center">
<Typography variant="h4" sx={styles.title}>
{title}
</Typography>
<Grid container justifyContent="center" spacing={2} sx={{ marginTop: '20px' }}>
{cards.map((card) => (
<Grid item key={card.id} onClick={() => handleCardClick(card.id)}>
<Card sx={styles.card(selected === card.id)}>
<div style={styles.image}></div>
<div style={styles.textContainer}>
<Typography align="center" sx={styles.text}>
{card.text}
</Typography>
</div>
<div style={styles.overlay(selected === card.id)}></div>
</Card>
</Grid>
))}
</Grid>
<Grid container sx={styles.buttonContainer}>
{step === 2 && (
<Button variant="contained" sx={styles.backButton} onClick={handleBackClick}>
Back
</Button>
)}
<Button
variant="contained"
sx={styles.button(!selected)}
disabled={!selected}
onClick={handleNextClick}
>
Next
</Button>
</Grid>
</Grid>
);
};

export default MakePost;

0 comments on commit e01aeb8

Please sign in to comment.