Skip to content

Commit

Permalink
perf: cash_resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Zain-ul-din committed Feb 18, 2024
1 parent a93c328 commit 591d35a
Show file tree
Hide file tree
Showing 11 changed files with 487 additions and 304 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@types/react-syntax-highlighter": "^15.5.6",
"apexcharts": "^3.41.0",
"axios": "^1.3.5",
"chakra-paginator": "^0.7.3",
"chatgpt": "^5.2.2",
"eslint": "8.37.0",
"eslint-config-next": "13.2.4",
Expand Down
3 changes: 2 additions & 1 deletion src/components/Timetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ const TimetableHeader = ({
/>
<Link
href={`${APIS_ENDPOINTS.SCREEN_SHOTS_PATH}/${metadataStr}.png`}
target="_blank">
target="_blank"
download>
<Button variant={'outline'} size={'sm'}>
Download Screen Shot
<FaFileImage
Expand Down
192 changes: 112 additions & 80 deletions src/components/clash_resolver/CourseCart.tsx
Original file line number Diff line number Diff line change
@@ -1,85 +1,117 @@
import { Alert, Button, Drawer, DrawerBody, Text,DrawerContent, DrawerHeader, DrawerOverlay, Flex, useDisclosure } from "@chakra-ui/react";
import { SubjectObjectVal, SubjectOjectType } from "~/types/typedef";
import SubjectCard from "./CourseCard";
import { ArrowUpIcon } from "@chakra-ui/icons";
import { useMemo } from "react";
import { BiExit } from "react-icons/bi";
import Link from "next/link";
import {
Alert,
Button,
Drawer,
DrawerBody,
Text,
DrawerContent,
DrawerHeader,
DrawerOverlay,
Flex,
useDisclosure
} from '@chakra-ui/react';
import { SubjectObjectVal, SubjectOjectType } from '~/types/typedef';
import SubjectCard from './CourseCard';
import { ArrowUpIcon } from '@chakra-ui/icons';
import { useMemo } from 'react';
import { BiExit } from 'react-icons/bi';
import Link from 'next/link';

export default function CourseCart (
{ subjects, removeCartItemHandle }:
{ subjects: SubjectOjectType,removeCartItemHandle: (subj: string)=>void }
) {
const { isOpen, onOpen, onClose } = useDisclosure()
const isEmpty = useMemo(()=> Object.values(subjects).filter(s=>s.isInCart).length == 0,[subjects])
export default function CourseCart({
subjects,
removeCartItemHandle
}: {
subjects: SubjectOjectType;
removeCartItemHandle: (subj: string) => void;
}) {
const { isOpen, onOpen, onClose } = useDisclosure();
const isEmpty = useMemo(
() => Object.values(subjects).filter((s) => s.isInCart).length == 0,
[subjects]
);

return <>
<Flex w={'100%'} position={'fixed'}
bottom={0}
py={'1rem'} borderTop={'1px solid'}
borderColor={'var(--border-color)'}
justifyContent={'center'}
bg={'var(--bg-color)'}
zIndex={2}
alignContent={'center'}
flexDir={'column'}
alignItems={'center'}
>
<Flex flexDir={'column'} gap={2}>

<Button variant={'outline'} size={'sm'} position={'relative'}
onClick={onOpen}
>
View Your Courses
<ArrowUpIcon />
{!isEmpty && <Flex position={'absolute'}
width={'8px'} height={'8px'} bg={'red'}
rounded={'full'}
top={-1}
right={-1}
>
{' '}
</Flex>}
</Button>
<Link href={`/discussions?active_route=View&discussion_id=4NgpCTfJ2cX8Tkzdbs3C`}>
<Text fontSize={'sm'} color={'blue.200'} textDecoration={'underline'}
_hover={{
cursor: 'pointer',
color: 'blue.300'
}}
>
{"Don't know how to use? View this post"}
</Text>
</Link>
return (
<>
<Flex
w={'100%'}
position={'fixed'}
bottom={0}
py={'1rem'}
borderTop={'1px solid'}
borderColor={'var(--border-color)'}
justifyContent={'center'}
bg={'var(--bg-color)'}
zIndex={2}
alignContent={'center'}
flexDir={'column'}
alignItems={'center'}>
<Flex flexDir={'column'} gap={2}>
<Button variant={'outline'} size={'sm'} position={'relative'} onClick={onOpen}>
View Your Courses
<ArrowUpIcon />
{!isEmpty && (
<Flex
position={'absolute'}
width={'8px'}
height={'8px'}
bg={'red'}
rounded={'full'}
top={-1}
right={-1}>
{' '}
</Flex>
)}
</Button>
<Link
href={`/discussions?active_route=View&discussion_id=4NgpCTfJ2cX8Tkzdbs3C`}>
<Text
fontSize={'sm'}
color={'blue.200'}
textDecoration={'underline'}
_hover={{
cursor: 'pointer',
color: 'blue.300'
}}>
{"Don't know how to use? View this post"}
</Text>
</Link>
</Flex>
</Flex>
</Flex>

{/* Drawer */}
<Drawer placement={'bottom'} onClose={onClose} isOpen={isOpen} size={'xl'}>
<DrawerOverlay />
<DrawerContent>
<DrawerHeader borderBottomWidth='1px'>
Your Courses
<Button colorScheme="red" size={'sm'} float={'right'} onClick={onClose}>
<BiExit />
</Button>
</DrawerHeader>
<DrawerBody maxH={'80vh'} overflowY={'auto'}>
<Flex mb={'5rem'} flexDir={'column'} justifyContent={'center'}>
{isEmpty && <Text>No, Course added so far</Text>}
{Object.entries(subjects)
.filter(e=> e[1].isInCart)
.map(([subjName,subj]:[string,SubjectObjectVal],i)=>{
return <SubjectCard
key={i}
name={subjName}
subject = {subj}
onRemove={removeCartItemHandle}
/>
})}
</Flex>
</DrawerBody>
</DrawerContent>
</Drawer>
</>
{/* Drawer */}
<Drawer
placement={'bottom'}
onClose={onClose}
isOpen={isOpen}
size={'xl'}
allowPinchZoom>
<DrawerOverlay />
<DrawerContent>
<DrawerHeader borderBottomWidth="1px">
Your Courses
<Button colorScheme="red" size={'sm'} float={'right'} onClick={onClose}>
<BiExit />
</Button>
</DrawerHeader>
<DrawerBody maxH={'80vh'} overflowY={'auto'}>
<Flex mb={'5rem'} flexDir={'column'} justifyContent={'center'}>
{isEmpty && <Text>No, Course added so far</Text>}
{Object.entries(subjects)
.filter((e) => e[1].isInCart)
.map(([subjName, subj]: [string, SubjectObjectVal], i) => {
return (
<SubjectCard
key={i}
name={subjName}
subject={subj}
onRemove={removeCartItemHandle}
/>
);
})}
</Flex>
</DrawerBody>
</DrawerContent>
</Drawer>
</>
);
}
42 changes: 42 additions & 0 deletions src/components/clash_resolver/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { BiLoader } from 'react-icons/bi';
import Loader from '../design/Loader';
import { Flex } from '@chakra-ui/react';

const LoadingOverlay = () => {
return (
<Flex
position={'fixed'}
top={2}
right={2}
bottom={0}
left={2}
bg={'var(--bg-dark)'}
zIndex={9999}
justifyContent={'center'}
alignContent={'center'}
alignItems={'center'}>
<Flex
p={5}
bg={'black'}
rounded={'md'}
gap={2}
alignItems={'center'}
border={'2px solid'}
borderColor={'var(--border-color)'}>
<Loader
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '0.5rem',
justifyContent: 'center'
}}>
<BiLoader className="spinner" />
Wait, Updating Subjects
</Loader>
</Flex>{' '}
</Flex>
);
};

export default LoadingOverlay;
Loading

0 comments on commit 591d35a

Please sign in to comment.