Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 46 additions & 8 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ app.put('/api/delete-review/:reviewId', authenticate, async (req, res) => {
/**
* Handles saving or removing saved apartments for a user in the database.
*
* @deprecated This endpoint is deprecated and will be removed in future versions.
* Use the new folder-based endpoints (`POST /api/folders/:folderId/apartments`
* and `DELETE /api/folders/:folderId/apartments/:apartmentId`) instead.
*
* @param add - If true, the apartment is added to the user's saved list. If false, it is removed.
*/
const saveApartmentHandler =
Expand Down Expand Up @@ -871,6 +875,7 @@ const saveApartmentHandler =
/**
* Handles saving or removing saved landlords for a user in the database.
*
* @deprecated This endpoint is deprecated and will be removed in future versions.
* @param add - If true, the landlord is added to the user's saved list. If false, it is removed.
*/
const saveLandlordHandler =
Expand Down Expand Up @@ -913,7 +918,11 @@ const saveLandlordHandler =
}
};

// Function to check if a user has an apartment saved or not
/**
* Function to check if a user has an apartment saved or not
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/

const checkSavedApartment = (): RequestHandler => async (req, res) => {
try {
if (!req.user) throw new Error('Not authenticated');
Expand Down Expand Up @@ -942,7 +951,10 @@ const checkSavedApartment = (): RequestHandler => async (req, res) => {
}
};

// Function to check if a user has an landlord saved or not
/**
* Function to check if a user has an landlord saved or not
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/
const checkSavedLandlord = (): RequestHandler => async (req, res) => {
try {
if (!req.user) throw new Error('Not authenticated');
Expand Down Expand Up @@ -971,27 +983,45 @@ const checkSavedLandlord = (): RequestHandler => async (req, res) => {
}
};

// Endpoint for checking if an apartment is saved by a user
/**
*
* Endpoint for checking if an apartment is saved by a user
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/
app.post('/api/check-saved-apartment', authenticate, checkSavedApartment());
// This endpoint uses authentication middleware to ensure that the user is logged in.
// The checkSavedApartment() function is then called to check if a specific apartment is saved by the user.

// Endpoint for checking if a landlord is saved by a user
/**
*
* Endpoint for checking if an landlord is saved by a user
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/
app.post('/api/check-saved-landlord', authenticate, checkSavedLandlord());
// Similar to the above endpoint, this one checks if a specific landlord is saved by the user.
// It also uses authentication to ensure that the request is made by a logged-in user.

// Endpoint for adding a saved apartment for a user
/**
* Endpoint for adding a saved apartment for a user
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/
app.post('/api/add-saved-apartment', authenticate, saveApartmentHandler(true));
// This endpoint allows authenticated users to add an apartment to their list of saved apartments.
// The saveApartmentHandler function is used with a parameter of 'true' to signify adding a save.

// Endpoint for removing a saved apartment for a user
/**
* Endpoint for removing a saved apartment for a user
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/
app.post('/api/remove-saved-apartment', authenticate, saveApartmentHandler(false));
// This endpoint allows authenticated users to remove an apartment from their list of saved apartments.
// The saveApartmentHandler function is used with a parameter of 'false' to signify removing a save.

// Endpoint to get a list of saved apartments for a user
/**
* Endpoint to get a list of saved apartments for a user
*
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/
app.get('/api/saved-apartments', authenticate, async (req, res) => {
if (!req.user) throw new Error('Not authenticated');
const { uid } = req.user; // Extracting user ID from the request
Expand All @@ -1012,8 +1042,16 @@ app.get('/api/saved-apartments', authenticate, async (req, res) => {
return res.status(200).send(data);
});

// Endpoints for adding and removing saved landlords for a user
/**
* Endpoint for adding a saved landlord for a user
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/
app.post('/api/add-saved-landlord', authenticate, saveLandlordHandler(true));

/**
* Endpoint for removing a saved landlord for a user
* @deprecated This endpoint is deprecated and will be removed in future versions.
*/
app.post('/api/remove-saved-landlord', authenticate, saveLandlordHandler(false));
// These endpoints allow for adding and removing landlords to/from a user's saved list.
// Both endpoints use the saveLandlordHandler function with appropriate boolean parameters.
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/ApartmentCard/ApartmentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,7 @@ const ApartmentCard = ({
onMouseLeave={() => setSavedIsHovered(false)}
className={saveRibbonIcon}
>
<img
src={savedIsHovered || isSaved ? saved : unsaved}
alt={isSaved ? 'Saved' : 'Unsaved'}
/>
<img src={savedIsHovered ? saved : unsaved} alt={'Save'} />
</IconButton>
</Grid>
</Grid>
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/ApartmentCard/LargeApartmentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
} from '@material-ui/core';
import savedIcon from '../../assets/apartment-card-saved-icon-filled.svg';
import unsavedIcon from '../../assets/apartment-card-saved-icon-unfilled.svg';
import bedIcon from '../../assets/apartment-card-bedroom-icon.svg';

Check warning on line 15 in frontend/src/components/ApartmentCard/LargeApartmentCard.tsx

View workflow job for this annotation

GitHub Actions / lint

'bedIcon' is defined but never used
import moneyIcon from '../../assets/apartment-card-money-icon.svg';
import axios from 'axios';
import { createAuthHeaders, getUser } from '../../utils/firebase';
Expand Down Expand Up @@ -327,10 +327,7 @@
onMouseLeave={() => setSavedIsHovered(false)}
className={saveRibbonIcon}
>
<img
src={savedIsHovered || isSaved ? saved : unsaved}
alt={isSaved ? 'Saved' : 'Unsaved'}
/>
<img src={savedIsHovered ? saved : unsaved} alt={'Save'} />
</IconButton>
</div>
<Typography className={apartmentAddress}>{address}</Typography>
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/ApartmentCard/NewApartmentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,7 @@ const NewApartmentCard = ({
onMouseLeave={() => setSavedIsHovered(false)}
className={saveRibbonIcon}
>
<img
src={savedIsHovered || isSaved ? saved : unsaved}
alt={isSaved ? 'Saved' : 'Unsaved'}
/>
<img src={savedIsHovered ? saved : unsaved} alt={'Save'} />
</IconButton>
<img src={img} alt="apartment" className={apartmentImage} />
</CardMedia>
Expand Down
22 changes: 6 additions & 16 deletions frontend/src/pages/ApartmentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const ApartmentPage = ({ user, setUser }: Props): ReactElement => {
const [isSaved, setIsSaved] = useState(false);
const [mapToggle, setMapToggle] = useState(false);
const [showSaveSuccess, setShowSaveSuccess] = useState(false);
const [isHovered, setIsHovered] = useState(false);

const dummyTravelTimes: LocationTravelTimes = {
agQuadDriving: -1,
Expand Down Expand Up @@ -541,31 +542,20 @@ const ApartmentPage = ({ user, setUser }: Props): ReactElement => {
)}

<Grid item style={{ marginLeft: 'auto' }}>
{/* <IconButton
disableRipple
onClick={handleSaveToggle}
style={{
padding: 15,
backgroundColor: 'transparent',
}}
>
<img
src={isSaved ? saved : unsaved}
alt={isSaved ? 'Saved' : 'Unsaved'}
style={{ width: '107px', height: '43px' }}
/>
</IconButton> */}
<Button
disableRipple
onClick={handleSaveToggle}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
className={saveButton}
color="primary"
fullWidth
disableElevation
>
<img src={isSaved ? saved : unsaved} className={bookmarkRibbon} />
{isSaved ? 'Saved' : 'Save'}
<img src={isHovered ? saved : unsaved} className={bookmarkRibbon} alt="Save" />
Save
</Button>

<Button
color="primary"
className={reviewButton}
Expand Down
Loading