Skip to content

Commit

Permalink
Format the list and panel
Browse files Browse the repository at this point in the history
  • Loading branch information
pratishta committed Jul 19, 2024
1 parent b54198e commit 9f4f923
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 74 deletions.
31 changes: 11 additions & 20 deletions app/components/CapitalProjectsAccordionPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, Box, Flex, HStack, Heading, IconButton } from "@nycplanning/streetscape"
import { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, Box, Text, Flex, HStack, Heading, IconButton, Stack } from "@nycplanning/streetscape"
import { Agency, CapitalProject } from "~/gen";
import { CapitalProjectsList } from "./CapitalProjectsList";
import { ChevronLeftIcon } from "@chakra-ui/icons";
Expand Down Expand Up @@ -32,34 +32,25 @@ export const CapitalProjectsAccordionPanel = ({
<AccordionItem border="none">
<h2>
<AccordionButton padding="0px">

<Box as='span' flex='1' textAlign='left'>
{/* <p>sdlkfja;sdlkjf;sa</p> */}
<Heading color="gray.600" fontWeight={"bold"} fontSize={"lg"}>
<Heading color="gray.600" fontWeight={"bold"} fontSize={"lg"} paddingBottom={"8px"}>
{district}
</Heading>

</Box>
<AccordionIcon size="lg" />
</AccordionButton>
</h2>




<AccordionPanel padding={"0px"}>
<p>sadlkfja;dsk</p>
<Box padding="20px">
<Divider borderColor={'cyan'} orientation="horizontal" />

</Box>
<CapitalProjectsList
capitalProjects={capitalProjects}
limit={limit}
offset={offset}
path={path}
total={total}
agencies={agencies}
/>
<CapitalProjectsList
capitalProjects={capitalProjects}
limit={limit}
offset={offset}
path={path}
total={total}
agencies={agencies}
/>
</AccordionPanel>
</AccordionItem>
</Accordion>
Expand Down
93 changes: 39 additions & 54 deletions app/components/CapitalProjectsList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Box, Flex, Hide, FlexProps, VStack, HStack, IconButton, Link} from "@nycplanning/streetscape";
import { Box, Flex, Hide, Text, VStack, HStack, IconButton, Link} from "@nycplanning/streetscape";
import { useState } from "react";
import { Agency, CapitalProject } from "~/gen";
import { getYear, getMonth, compareAsc } from "date-fns";
import { getYear, getMonth, compareAsc, format } from "date-fns";
import { CapitalProjectsListItem } from "./CapitalProjectsListItem";
import { Button } from "@chakra-ui/react";
import { defineStyle, defineStyleConfig } from '@chakra-ui/react'
import { ArrowLeftIcon, ArrowRightIcon, Icon } from "@chakra-ui/icons";
import { Pagination } from "./Pagination";
import ReactPaginate from 'react-paginate';
import { useSearchParams } from "@remix-run/react";


export interface CapitalProjectsListProps {
capitalProjects: Array<CapitalProject>;
Expand All @@ -23,36 +21,8 @@ export const CapitalProjectsList = ({
capitalProjects, limit, offset, total, path, agencies,
}: CapitalProjectsListProps) => {

const [searchParams] = useSearchParams();
console.log(searchParams);

function setSearchParamsString(
searchParams: URLSearchParams,
changes: Record<string, string | number | undefined>,
) {
const newSearchParams = new URLSearchParams(searchParams)
for (const [key, value] of Object.entries(changes)) {
if (value === undefined) {
newSearchParams.delete(key)
continue
}
newSearchParams.set(key, String(value))
}
// Print string manually to avoid over-encoding the URL
// Browsers are ok with $ nowadays
// optional: return newSearchParams.toString()
return Array.from(newSearchParams.entries())
.map(([key, value]) =>
value ? `${key}=${encodeURIComponent(value)}` : key,
)
.join("&")
}

const [isExpanded, setIsExpanded] = useState(false);

const numberOfPages = total / limit;
// Invoke when user click to request another page.

const getFiscalYearForDate = (date: Date): number => {
const year = getYear(date);
const month = getMonth(date);
Expand All @@ -65,9 +35,23 @@ export const CapitalProjectsList = ({
: `FY${getFiscalYearForDate(minDate)}-FY${getFiscalYearForDate(maxDate)}`;
};

// const Pagination = () => <Button colorScheme="blue" borderRadius="0" aria-label="Page" size="xs">{offset+1}</Button>
const currentDate = () => {
return `${format(new Date(), 'MM/dd/yyyy')}`;
}

return (
<>
<Box
borderTopWidth={"1px"}
borderTopColor={"gray.400"}
paddingTop={"16px"}
>
<Text
as={"span"}
>
Mapped Capital Projects as of <Text as={"b"}>{currentDate()}</Text>
</Text>
</Box>
<Flex
direction={"column"}
overflow={"hidden"}
Expand All @@ -78,29 +62,30 @@ export const CapitalProjectsList = ({
height={{ base: isExpanded ? "70vh" : "70vh"}}
overflowY={{ base: "scroll" }}
>
{/* this should be a generic panel for project detail and list */}

{/* we need a separate component for project list item */}


<VStack
align='stretch'
paddingTop={"12px"}
gap={"12px"}
>

{capitalProjects.map((capitalProject) => {
return (
<CapitalProjectsListItem
description={capitalProject.description}
minDate={capitalProject.minDate}
maxDate={capitalProject.maxDate}
agency= { agencies.find(
(agency) => agency.initials === capitalProject.managingAgency,
)?.name }
yearRange={formatFiscalYearRange(
new Date(capitalProject.minDate),
new Date(capitalProject.maxDate),
)}
/>
)
})}
{capitalProjects.map((capitalProject) => {
return (
<CapitalProjectsListItem
description={capitalProject.description}
minDate={capitalProject.minDate}
maxDate={capitalProject.maxDate}
agency= { agencies.find(
(agency) => agency.initials === capitalProject.managingAgency,
)?.name }
yearRange={formatFiscalYearRange(
new Date(capitalProject.minDate),
new Date(capitalProject.maxDate),
)}
/>
)
})}
</VStack>
</Box>
</Flex>
Expand Down

0 comments on commit 9f4f923

Please sign in to comment.