Skip to content

Commit

Permalink
Unit List View (#102)
Browse files Browse the repository at this point in the history
## Tracking Info

Resolves #93

## Changes
Implemented the card/list view toggle button at the top of the page and
the list view for units.
Also replaced paginator with V2 button version. 

## Testing
Tested by switching between unit and list views and trying the paginator
on varying numbers of pages.

## Confirmation of Change
The implemented list view: 
<img width="1427" alt="Screenshot 2024-05-22 at 1 03 12 PM"
src="https://github.com/TritonSE/USHS-Housing-Portal/assets/35088854/b3dd9ec8-a4e6-4712-acaf-295cd2e70e78">
<img width="1427" alt="Screenshot 2024-05-22 at 1 03 19 PM"
src="https://github.com/TritonSE/USHS-Housing-Portal/assets/35088854/b6a640b8-cb9a-4fb5-8d8a-484978dc3f27">

**The paginator:** 
<img width="348" alt="Screenshot 2024-05-22 at 1 03 42 PM"
src="https://github.com/TritonSE/USHS-Housing-Portal/assets/35088854/f6e1359f-3bb2-4301-84e0-6d9467972047">
<img width="1032" alt="Screenshot 2024-05-22 at 1 03 54 PM"
src="https://github.com/TritonSE/USHS-Housing-Portal/assets/35088854/33e142a8-7296-4a5b-83a4-7d2622413ff9">
<img width="1056" alt="Screenshot 2024-05-22 at 1 04 00 PM"
src="https://github.com/TritonSE/USHS-Housing-Portal/assets/35088854/f338a6e6-a56a-4fa0-aa03-70526089efe3">
<img width="1063" alt="Screenshot 2024-05-22 at 1 04 06 PM"
src="https://github.com/TritonSE/USHS-Housing-Portal/assets/35088854/6cdfcb4c-edbf-46e2-9b21-86300807c774">

---------

Co-authored-by: Philip Zhang <[email protected]>
  • Loading branch information
PoliteUnicorn and petabite authored Jun 4, 2024
1 parent 2d3228d commit fcc8dac
Show file tree
Hide file tree
Showing 14 changed files with 644 additions and 138 deletions.
Binary file modified frontend/bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions frontend/public/card_view_icon_selected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/public/card_view_icon_unselected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/public/list_view_icon_selected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/public/list_view_icon_unselected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions frontend/src/components/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ const AllFiltersContainer = styled.div`
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
margin-left: 95px;
margin-right: 95px;
margin-top: 55px;
gap: 16px;
`;

Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ import { FiltersContext } from "@/pages/Home";

const PanelBackground = styled.div`
min-width: 284px;
max-height: calc(100vh - 70px);
background-color: #fff;
position: fixed;
top: 70px;
bottom: 0;
overflow-y: scroll;
overflow-x: hidden;
Expand Down
32 changes: 22 additions & 10 deletions frontend/src/components/HousingLocatorTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useContext, useEffect, useState } from "react";
import styled from "styled-components";

import { Button } from "./Button";
import { TablePagination } from "./TablePagination";
import { Pagination } from "./Pagination";

import { User, demoteUser } from "@/api/users";
import { DataContext } from "@/contexts/DataContext";
Expand Down Expand Up @@ -68,9 +68,19 @@ const HLRow = styled.div`
margin-bottom: 20px;
`;

const HLTableFooterWrapper = styled.div`
display: flex;
flex-direction: row;
margin-right: 24px;
margin-bottom: 20px;
justify-content: right;
`;

const HLTableFooter = styled.div`
padding-left: 85%;
margin: 1vh 0vw 3vh 0vw;
display: flex;
flex-direction: row;
justify-content: space-between;
`;

const Overlay = styled.div`
Expand Down Expand Up @@ -219,6 +229,15 @@ export const HousingLocatorTable = () => {
></DeleteIcon>
</HLRow>
))}
<HLTableFooterWrapper>
<HLTableFooter>
<Pagination
totalPages={Math.ceil(housingLocators.length / ENTRIES_PER_PAGE)}
currPage={pageNumber}
setPageNumber={setPageNumber}
/>
</HLTableFooter>
</HLTableFooterWrapper>
</HLTableContainer>
{popup && selectedUser && (
<>
Expand Down Expand Up @@ -303,13 +322,6 @@ export const HousingLocatorTable = () => {
</Modal>
</>
)}
<HLTableFooter>
<TablePagination
totalPages={Math.ceil(housingLocators.length / ENTRIES_PER_PAGE)}
currPage={pageNumber}
setPageNumber={setPageNumber}
/>
</HLTableFooter>
</HLTableWrapper>
);
};
216 changes: 216 additions & 0 deletions frontend/src/components/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import styled from "styled-components";

const NumPageButton = styled.button`
width: 25px;
height: 24px;
border-radius: 4px;
border: 1px solid #eeeeee;
opacity: 0px;
background: #f5f5f5;
align-content: center;
&:hover {
cursor: pointer;
background: #f5f5f5;
}
&.active {
background: #ec8537;
color: #ffffff;
border-color: #ec8537;
}
`;

const ButtonWrapper = styled.div`
display: flex;
flex-direction: row;
//width: 341.87px;
height: 24px;
justify-content: space-between;
gap: 20px;
opacity: 0px;
`;

const NavButton = styled(NumPageButton)``;

const NavButtonIcon = styled.img`
width: 24px;
height: 24px;
flex-shrink: 0;
border-radius: 4px;
border: 0;
`;

const EllipsesWrapper = styled.div`
width: 24px;
height: 24px;
`;

type PaginationProps = {
totalPages: number;
currPage: number;
setPageNumber: (newPageNumber: number) => void;
};

const BUTTONS_PER_PAGE = 5;

export const Pagination = (props: PaginationProps) => {
const pages = [];

const handleClick = (increase: boolean): void => {
if (increase && props.currPage !== props.totalPages) {
props.setPageNumber(props.currPage + 1);
}

if (!increase && props.currPage > 1) {
props.setPageNumber(props.currPage - 1);
}
};

//case 1: num pages < buttons per page -> show all
if (props.totalPages <= BUTTONS_PER_PAGE) {
for (let i = 1; i <= props.totalPages; i++) {
pages.push(
<NumPageButton
key={i}
onClick={() => {
props.setPageNumber(i);
}}
className={props.currPage === i ? "active" : ""}
>
{i}
</NumPageButton>,
);
}
}
//case 2: on page 1-3 -> show first 4 ... and last
else if (props.currPage <= BUTTONS_PER_PAGE - 2) {
for (let i = 1; i <= props.totalPages; i++) {
//add button for first three pages
if (i <= BUTTONS_PER_PAGE - 1) {
pages.push(
<NumPageButton
key={i}
onClick={() => {
props.setPageNumber(i);
}}
className={props.currPage === i ? "active" : ""}
>
{i}
</NumPageButton>,
);
} else if (i === props.totalPages) {
pages.push(<EllipsesWrapper>...</EllipsesWrapper>);
pages.push(
<NumPageButton
key={i}
onClick={() => {
props.setPageNumber(i);
}}
className={props.currPage === i ? "active" : ""}
>
{i}
</NumPageButton>,
);
}
}
}
//case 3: on page end - 4 + 1-> show first ... last 4
else if (props.currPage > props.totalPages - BUTTONS_PER_PAGE + 2) {
//add button for first three pages
for (let i = 1; i <= props.totalPages; i++) {
if (i >= props.totalPages - BUTTONS_PER_PAGE + 2) {
pages.push(
<NumPageButton
key={i}
onClick={() => {
props.setPageNumber(i);
}}
className={props.currPage === i ? "active" : ""}
>
{i}
</NumPageButton>,
);
} else if (i === 1) {
pages.push(
<NumPageButton
key={i}
onClick={() => {
props.setPageNumber(i);
}}
className={props.currPage === i ? "active" : ""}
>
{i}
</NumPageButton>,
);
pages.push(<EllipsesWrapper>...</EllipsesWrapper>);
}
}
}
//case 4: middle -> show first ... middle - 1, middle, middle + 1, ... last
else {
for (let i = 1; i <= props.totalPages; i++) {
if (i === 1) {
pages.push(
<NumPageButton
key={i}
onClick={() => {
props.setPageNumber(i);
}}
className={props.currPage === i ? "active" : ""}
>
{i}
</NumPageButton>,
);
pages.push(<EllipsesWrapper>...</EllipsesWrapper>);
} else if (i === props.currPage - 1 || i === props.currPage || i === props.currPage + 1) {
pages.push(
<NumPageButton
key={i}
onClick={() => {
props.setPageNumber(i);
}}
className={props.currPage === i ? "active" : ""}
>
{i}
</NumPageButton>,
);
} else if (i === props.totalPages) {
pages.push(<EllipsesWrapper>...</EllipsesWrapper>);
pages.push(
<NumPageButton
key={i}
onClick={() => {
props.setPageNumber(i);
}}
className={props.currPage === i ? "active" : ""}
>
{i}
</NumPageButton>,
);
}
}
}

return (
<ButtonWrapper>
<NavButton>
<NavButtonIcon
src={"/ic_caretleft.svg"}
onClick={() => {
handleClick(false);
}}
/>
</NavButton>
{pages}
<NavButton>
<NavButtonIcon
src={"/ic_caretright.svg"}
onClick={() => {
handleClick(true);
}}
/>
</NavButton>
</ButtonWrapper>
);
};
7 changes: 5 additions & 2 deletions frontend/src/components/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react";
import styled from "styled-components";

import { TablePagination } from "./TablePagination";
import { Pagination } from "./Pagination";

const TableContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -43,6 +43,9 @@ const TableCell = styled.div`
`;

const TableFooter = styled.div`
display: flex;
flex-direction: row;
justify-content: right;
padding-top: 20px;
`;

Expand Down Expand Up @@ -82,7 +85,7 @@ export const Table = (props: TableProps) => {
))}
<TableFooter>
{/* TODO: Replace this with new pagination when it is implemented */}
<TablePagination
<Pagination
totalPages={Math.ceil(rows.length / rowsPerPage)}
currPage={pageNumber}
setPageNumber={setPageNumber}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/UnitCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const RentText = styled(UnitCardText)`
font-weight: 700;
line-height: 121%;
letter-spacing: 0.331px;
font-family: Inter;
font-family: "Neutraface Text";
`;

const AddressText = styled(UnitCardText)`
Expand Down
Loading

0 comments on commit fcc8dac

Please sign in to comment.