Skip to content

Commit 95c56c7

Browse files
author
Lauren Pothuru
committed
Update FolderDetailPage to display apartment cards
1 parent dc20dc9 commit 95c56c7

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

backend/src/app.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,22 @@ app.get('/api/folders/:folderId/apartments', authenticate, async (req, res) => {
19121912
}
19131913

19141914
const apartments = folderDoc.data()?.apartments || [];
1915-
return res.status(200).json(apartments);
1915+
const aptsArr = await Promise.all(
1916+
apartments.map(async (id: string) => {
1917+
const snapshot = await buildingsCollection.doc(id).get();
1918+
if (!snapshot.exists) {
1919+
console.warn(`Apartment ${id} not found`);
1920+
return null;
1921+
}
1922+
return { id, ...snapshot.data() };
1923+
})
1924+
);
1925+
1926+
// Filter out any null values from non-existent apartments
1927+
const validApartments = aptsArr.filter((apt) => apt !== null);
1928+
const enrichedResults = await pageData(validApartments);
1929+
console.log('Enriched Results:', enrichedResults);
1930+
return res.status(200).json(enrichedResults);
19161931
} catch (err) {
19171932
console.error(err);
19181933
return res.status(500).send('Error fetching apartments from folder');

frontend/src/components/ApartmentCard/SearchResultsPageApartmentCards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ReactElement, useEffect } from 'react';
22
import NewApartmentCard from './NewApartmentCard';
3-
import { Grid, Link, makeStyles, Button, Box, Typography } from '@material-ui/core';
3+
import { Link, makeStyles } from '@material-ui/core';
44
import { Link as RouterLink } from 'react-router-dom';
55
import { CardData } from '../../App';
66
import { loadingLength } from '../../constants/HomeConsts';

frontend/src/pages/FolderDetailPage.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import Toast from '../components/utils/Toast';
1414
import { colors } from '../colors';
1515
import axios from 'axios';
1616
import { createAuthHeaders, getUser } from '../utils/firebase';
17+
import ApartmentCards from '../components/ApartmentCard/SearchResultsPageApartmentCards';
18+
import { CardData } from '../App';
1719

1820
type Props = {
1921
user: firebase.User | null;
@@ -75,7 +77,7 @@ const FolderDetailPage = ({ user, setUser }: Props): ReactElement => {
7577
const { background, headerStyle, headerContainer, backButton, gridContainer } = useStyles();
7678

7779
const [folder, setFolder] = useState<Folder | null>(null);
78-
const [apartments, setApartments] = useState<string[]>([]);
80+
const [apartments, setApartments] = useState<CardData[]>([]);
7981
const [loading, setLoading] = useState<boolean>(true);
8082
const [showErrorToast, setShowErrorToast] = useState<boolean>(false);
8183
const [errorMessage, setErrorMessage] = useState<string>('');
@@ -191,24 +193,7 @@ const FolderDetailPage = ({ user, setUser }: Props): ReactElement => {
191193
</Box>
192194
) : (
193195
<Grid container spacing={3} className={gridContainer}>
194-
{apartments.map((aptId) => (
195-
<Grid item xs={12} sm={6} md={4} key={aptId}>
196-
<Box
197-
style={{
198-
padding: '2em',
199-
backgroundColor: 'white',
200-
borderRadius: '8px',
201-
cursor: 'pointer',
202-
}}
203-
onClick={() => history.push(`/apartment/${aptId}`)}
204-
>
205-
<Typography variant="h6">Apartment {aptId}</Typography>
206-
<Typography variant="body2" style={{ color: colors.gray2, marginTop: '0.5em' }}>
207-
Click to view details
208-
</Typography>
209-
</Box>
210-
</Grid>
211-
))}
196+
<ApartmentCards data={apartments} user={user} setUser={setUser} />
212197
</Grid>
213198
)}
214199

0 commit comments

Comments
 (0)