Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

my moments page +new create moments page #73

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 108 additions & 4 deletions tracknow/web/src/components/User/UserAddLaptimes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,110 @@
import * as React from "react";
import {
Box, Flex, Card, CardHeader, CardBody,
Heading, Stack, Button, FormControl,
Textarea, FormHelperText, Input, Select,
HStack,
} from "@chakra-ui/react";
import { useParams } from "react-router-dom";
import { SimracingTitles } from "../../misc/dropDown";

export const Laptimes = () => (
<>
</>
);
const UserAddLaptimes = () => {

return (
<Flex mt={10} bg="dark">
{/* Left section*/}
<Box flex="1" borderRight="1px solid #323536" overflowY="auto" display={["none", "none", "block"]}>
{/* left section content */}
</Box>

{/* Main Section */}
<Box flex="4"
rounded={'sm'}
my={1}
mx={[0, 5]}
overflow={'hidden'}
borderRadius={"1px"}>

<Card size={'lg'} maxW='600px' >
<CardHeader>
<Heading size='lg'>Add Racing Moment</Heading>
</CardHeader>

<HStack spacing={6} pt={3}>
<Select borderColor={'#323536'}
focusBorderColor="grey"
ml={4}
>
<option style={{ backgroundColor: 'black' }} value="true">Sim racing</option>
<option style={{ backgroundColor: 'black' }} value="false">Real life</option>
</Select>

<SimracingTitles />
</HStack>


<CardBody >
<Stack spacing='5'>
<Input borderColor={'#323536'} focusBorderColor="grey" placeholder='Title' isRequired />
<FormControl isRequired>
<Textarea
borderColor={'#323536'}
focusBorderColor="grey"
maxLength={500}
placeholder='Body'

/>
<FormHelperText></FormHelperText>
</FormControl>
</Stack>
<Stack pt={4} spacing='3'>
<Box>
<Heading size='xs' textTransform='uppercase'>
Car
</Heading>
<Input borderColor={'#323536'} focusBorderColor="grey" variant='flushed' placeholder='Porsche 911 GT3' isRequired />

</Box>

<Box>
<Heading size='xs' textTransform='uppercase'>
Track
</Heading>
<Input borderColor={'#323536'} focusBorderColor="grey" variant='flushed' placeholder='Nürburgring Nordschleife' isRequired />

</Box>

<Box>
<Heading size='xs' textTransform='uppercase'>
Hotlap/Time
</Heading>
<Input borderColor={'#323536'} focusBorderColor="grey" variant='flushed' placeholder='6.59.34' isRequired />

</Box>
<Box>
<Heading size='xs' textTransform='uppercase'>
Images / Videos
</Heading>
<FormControl>
<Input borderColor={'#323536'} focusBorderColor="grey" variant='flushed' placeholder='https://www.youtube.com/watch?v=l_hbqBxxISY&feature=youtu.be' isRequired />
<FormHelperText fontSize={'11px'}>Only Youtube links(Videos) are supported now, bear with me :)</FormHelperText>
</FormControl>

</Box>
</Stack>
</CardBody>
<Flex pr={5} mb={6} justifyContent={'flex-end'}>
<Button variant={"navbarButton"}>
Post
</Button>
</Flex>
</Card>

</Box >


</Flex >
);
};

export default UserAddLaptimes;
20 changes: 16 additions & 4 deletions tracknow/web/src/components/User/UserLaptimes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import * as React from "react";
import { HomePost } from "../Post/Post";
import { useLaptimes } from "../../hooks/useLaptimes";

export const UserLaptimes = () => (
<>
</>
);
const UserLaptimes = () => {

const { mylaptime } = useLaptimes();

return (
<>

< HomePost laptimes={mylaptime} />

</>
)
};

export default UserLaptimes
4 changes: 2 additions & 2 deletions tracknow/web/src/hooks/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function CreateUser(newUser: Login): Promise<SignUpResponse> {
};

// function to create a user's personal laptime and get personal laptimes
async function handleLaptimes(newLaptime?: Laptime): Promise<CreateLaptimeResponse | GetUserLaptimesResponse> {
async function handleLaptimes(newLaptime?: Laptime): Promise<CreateLaptimeResponse | GetUserLaptimesResponse[]> {

const token = localStorage.getItem('access_token') // after logging in, we retrieve the token to get access to some of the functions

Expand Down Expand Up @@ -152,7 +152,7 @@ async function handleLaptimes(newLaptime?: Laptime): Promise<CreateLaptimeRespon
throw new Error('Failed to fetch Personal laptimes');
}

const data: GetUserLaptimesResponse = await response.json();
const data: GetUserLaptimesResponse[] = await response.json();
return data;
};
};
Expand Down
21 changes: 20 additions & 1 deletion tracknow/web/src/hooks/useLaptimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GetUserLaptimesResponse, Laptime } from "../Types";
export const useLaptimes = () => {

const [laptime, setLaptime] = React.useState<GetUserLaptimesResponse[]>([]);
const [mylaptime, setmylaptimes] = React.useState<GetUserLaptimesResponse[]>([]);

// fetch all laptimes from the server
const fetchLaptime = async () => {
Expand All @@ -22,9 +23,27 @@ export const useLaptimes = () => {
}
};

// fetch connected user personal uploaded laptimes/moments
const fetchMyLaptimes = async () => {
try {
const response = await API.handleLaptimes();

if (Array.isArray(response)) {

setmylaptimes(response);

} else {
// CreateLaptimeResponse - addLaptime function lol
}
} catch (error) {
throw new Error("My Laptimes not loaded");
}
}

React.useEffect(() => {
//console.log("useEffect called");
fetchLaptime();
fetchMyLaptimes();
}, [])

// add laptimes
Expand All @@ -41,6 +60,6 @@ export const useLaptimes = () => {
}
};

return { laptime, addLaptime };
return { laptime, addLaptime, mylaptime };

}