Skip to content

Commit

Permalink
🔥 burn things form UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Zain-ul-din committed Mar 17, 2024
1 parent fc5be3b commit 5192df9
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ NEXT_PUBLIC_preview=

OPEN_DB_KEY=
OPEN_DB_IV=

# Github Token
GITHUB_USER_TOKEN=
87 changes: 47 additions & 40 deletions src/components/Developer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import styles from '~/styles/developer.module.css';
import Button from './design/Button';
import { useToast } from '@chakra-ui/react';
import { Flex, HStack, Heading, Input, useMediaQuery, useToast } from '@chakra-ui/react';

import { IApiSchema } from '~/lib/redis';
import { Nunito } from 'next/font/google';
Expand All @@ -23,48 +23,53 @@ export default function Developer({ children }: { children: React.ReactNode }) {
const user = useContext(UserCredentialsContext);

return (
<div className={styles.developer + ' ' + nunito.className}>
<h1>APIS For Developers</h1>
<p>
{`Welcome to LGU timetable site! I'm excited to provide you with APIs that allow you to access and utilize our comprehensive timetable data. To get started, simply sign up for an API key and provide a brief description of how you plan to use our APIs.
<>
<Flex maxW={'1400px'} mx={'auto'} w={'100%'} px={'1rem'} py={5}>
<SessionInput className={nunito.className} />
</Flex>
<div className={styles.developer + ' ' + nunito.className}>
<h1>APIS For Developers</h1>
<p>
{`Welcome to LGU timetable site! I'm excited to provide you with APIs that allow you to access and utilize our comprehensive timetable data. To get started, simply sign up for an API key and provide a brief description of how you plan to use our APIs.
you will have access to our complete university timetable data and more. Our APIs are designed to be easy to use and integrate into your own applications and websites.
If you have any questions or issues with our APIs, please feel free to contact us at any time. We are committed to providing you with the best possible experience.`}
</p>
<motion.div
className={styles.api}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 1 }}>
<h1>API KEYS</h1>
<p>
Your secret API keys are listed below. Please note that we do not display your secret API
keys again after you generate them.
<i>Do not share your API key with others.</i> You will get <b>200</b> request per day with
each secret key and secret key will expire after <b>1 month</b>.
</p>
</motion.div>

{!user?.user && (
<>
<Center>
<NotLoggedIn text={'Sign in with Google to Get API keys'} />
</Center>
</>
)}

{user?.user && (
<>
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: 0.5, duration: 1.5 }}>
<DashBoardTable user={user.user as User} />
</motion.div>
</>
)}

{children}
</div>
<motion.div
className={styles.api}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 1 }}>
<h1>API KEYS</h1>
<p>
Your secret API keys are listed below. Please note that we do not display your secret
API keys again after you generate them.
<i>Do not share your API key with others.</i> You will get <b>200</b> request per day
with each secret key and secret key will expire after <b>1 month</b>.
</p>
</motion.div>

{!user?.user && (
<>
<Center>
<NotLoggedIn text={'Sign in with Google to Get API keys'} />
</Center>
</>
)}

{/* {user?.user && (
<>
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: 0.5, duration: 1.5 }}>
<DashBoardTable user={user.user as User} />
</motion.div>
</>
)} */}

{children}
</div>
</>
);
}

Expand All @@ -88,6 +93,8 @@ import { apiAnalysisCol } from '~/lib/firebase';
import { setDoc, doc, serverTimestamp } from 'firebase/firestore';

import { NotLoggedIn } from './Header';
import PremiumButton from './design/PremiumButton';
import SessionInput from './SessionInput';

const DashBoardTable = ({ user }: { user: User }) => {
const [keys, setKeys] = useState<Array<IApiResponse>>([]);
Expand Down
140 changes: 140 additions & 0 deletions src/components/SessionInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import {
HStack,
Text,
Button as Btn,
Flex,
FlexProps,
Input,
useMediaQuery,
Stack,
Link
} from '@chakra-ui/react';
import PremiumButton from './design/PremiumButton';
import { useCallback, useState } from 'react';
import { useUserCredentials } from '~/hooks/hooks';

interface SessionInputProps extends FlexProps {}

export default function SessionInput({ ...rest }: SessionInputProps) {
const [under600] = useMediaQuery('(max-width: 600px)');
const [session, setSession] = useState({
value: '',
error: false
});
const [loading, setLoading] = useState<boolean>(false);
const [serverRes, setServerRes] = useState({
message: undefined,
succeed: undefined
});

const [user] = useUserCredentials();

const isValidateSession = useCallback((session: string) => {
var regex = /^[a-zA-Z0-9]+$/;
const REQUIRE_LEN = 26;
const duplicates = session.length - Array.from(new Set(Array.from(session))).length;
return session.length === REQUIRE_LEN && duplicates < REQUIRE_LEN / 2 && regex.test(session);
}, []);

if (!user) {
return <></>;
}

return (
<Flex
bg={'var(--card-color)'}
border={'1px solid var(--border-color)'}
w={'100%'}
rounded={'md'}
px={4}
flexDir={'column'}
py={5}
gap={5}
{...rest}>
<h1
style={{
color: 'rgba(255,255,255,0.5)',
fontSize: under600 ? '1.5rem' : '3rem',
fontWeight: 'bold'
}}>
Keep Timetable Up-to-date for EveryOne
</h1>
<Stack
as={'form'}
onSubmit={(e) => {
e.preventDefault();
const error = !isValidateSession(session.value);
setSession((prev) => ({ ...prev, error }));
if (error) return;
setLoading(true);
fetch('/api/util/workflow', {
method: 'POST',
body: JSON.stringify({
user_id: user.uid,
session_id: session.value
})
})
.then((res) => res.json())
.then((res) => {
setLoading(false);
setServerRes(res);
});
}}>
<Input
variant={'filled'}
boxShadow={'xl'}
outline={'none'}
_focus={{
borderColor: 'var(--border-color)'
}}
size={'lg'}
value={session.value}
onChange={(e) =>
setSession(() => ({
value: e.target.value,
error: !isValidateSession(e.target.value)
}))
}
placeholder="Enter Session ID or Value"
/>
<Text color={'red.400'}>{session.error ? 'Invalid Session ID' : ''}</Text>
<HStack>
<PremiumButton fontWeight={'bold'} size={'lg'} type="submit" isLoading={loading}>
Submit
</PremiumButton>
<Btn
variant={'outline'}
size={'lg'}
fontSize={{ sm: 'sm', base: 'xs' }}
as={'a'}
href={
'https://github.com/IIvexII/LGU-TimetableAPI/blob/main/docs/How_to_get_session.md'
}
target="_blank">
How to Obtain Session Id?
</Btn>
</HStack>
{serverRes.message && (
<Flex
border={'1px solid var(--border-color)'}
p={3}
rounded={'md'}
my={2}
flexDir={'column'}
gap={2}>
<Text color={'rgba(255,255,255,0.7)'}>Server Response: {serverRes.message}</Text>
{serverRes.succeed && (
<Link
href="https://github.com/Zain-ul-din/lgu-crawler/actions"
target="_blank"
fontSize={'sm'}
textDecoration={'underline'}>
🤖 See Workflow Running Here
</Link>
)}
</Flex>
)}
</Stack>
</Flex>
);
}
1 change: 1 addition & 0 deletions src/lib/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ export const pastPapersCol = collection(firebase.firebaseStore, 'past_papers');
export const pastPapersInputCol = collection(firebase.firebaseStore, 'past_papers_input');
export const discussionsColRef = collection(firebase.firebaseStore, 'discussions');
export const discussionsCommentsColRef = collection(firebase.firebaseStore, 'discussions_comments');
export const workFlowColRef = collection(firebase.firebaseStore, 'workflow');
export const discussionSubColName = 'participants';
Loading

0 comments on commit 5192df9

Please sign in to comment.