-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from euanwm/233-swr-two
shit rebase but i'm not going to lose sleep over it
- Loading branch information
Showing
26 changed files
with
826 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 19 additions & 19 deletions
38
frontend/api/fetchLifterGraphData/fetchLifterGraphData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import { LifterChartData } from './fetchLifterGraphDataTypes'; | ||
import { LifterChartData } from './fetchLifterGraphDataTypes' | ||
|
||
export default async function fetchLifterGraphData(lifterName = ''): Promise<LifterChartData> { | ||
const bodyContent = JSON.stringify({"NameStr": lifterName }); | ||
export default async function fetchLifterGraphData( | ||
lifterName: string, | ||
): Promise<LifterChartData> { | ||
if (!lifterName) { | ||
return | ||
} | ||
|
||
try { | ||
const response = await fetch(`${process.env.API}/lifter`, { | ||
method: 'POST', | ||
headers: { | ||
Accept: '*/*', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: bodyContent, | ||
}); | ||
const jsonResponse = response.json(); | ||
const bodyContent = JSON.stringify({ NameStr: lifterName }) | ||
|
||
return jsonResponse; | ||
} catch(error) { | ||
console.error('error in fetchLifterGraphData', error); | ||
const response = await fetch(`${process.env.API}/lifter`, { | ||
method: 'POST', | ||
headers: { | ||
Accept: '*/*', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: bodyContent, | ||
}) | ||
const jsonResponse = response.json() | ||
|
||
return undefined; | ||
} | ||
}; | ||
return jsonResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,20 @@ | ||
import { LifterHistory } from './fetchLifterHistoryTypes' | ||
|
||
const blankLifterHistory: LifterHistory = { | ||
name: '', | ||
graph: { | ||
labels: [], | ||
datasets: [], | ||
}, | ||
lifts: [], | ||
} | ||
|
||
export default async function fetchLifterHistory( | ||
name: string | string[] | undefined, | ||
): Promise<LifterHistory> { | ||
name: string, | ||
): Promise<LifterHistory | null> { | ||
if (!name) { | ||
return blankLifterHistory | ||
return null | ||
} | ||
|
||
try { | ||
const response = await fetch(`${process.env.API}/history`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ NameStr: name }), | ||
}) | ||
const response = await fetch(`${process.env.API}/history`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ NameStr: name }), | ||
}) | ||
|
||
const jsonResponse = response.json() | ||
return jsonResponse | ||
} catch (error) { | ||
console.error('error in fetchLifterHistory', error) | ||
|
||
return blankLifterHistory | ||
} | ||
const jsonResponse = response.json() | ||
return jsonResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import { LifterSearchList } from "./fetchLifterNamesTypes" | ||
import { LifterSearchList } from './fetchLifterNamesTypes' | ||
|
||
export default async function fetchLifterNames(nameQuery: string): Promise<LifterSearchList> { | ||
if (nameQuery.length < 3) { | ||
return {names: []} | ||
export default async function fetchLifterNames( | ||
name: string, | ||
): Promise<LifterSearchList> { | ||
if (name?.length < 3) { | ||
return { names: [] } | ||
} | ||
|
||
try { | ||
const response = await fetch(`${process.env.API}/search?name=${nameQuery}`); | ||
const jsonResponse = response.json(); | ||
const response = await fetch(`${process.env.API}/search?name=${name}`) | ||
const jsonResponse = response.json() | ||
|
||
return jsonResponse; | ||
} catch (error) { | ||
console.error('error in searching names', error) | ||
|
||
return {names: []} | ||
} | ||
} | ||
return jsonResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { RegistrationForm, FormResponse } from './submitLeagueFormTypes' | ||
|
||
export default async function submitLeagueForm( | ||
data: RegistrationForm, | ||
): Promise<FormResponse> { | ||
try { | ||
const response = await fetch('https://v2.openweightlifting.org/register', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(data), | ||
}) | ||
return response.json() | ||
} catch (error) { | ||
console.error('Error:', error) | ||
return { | ||
success: false, | ||
message: 'There was an error submitting your form. Please try again.', | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type RegistrationForm = { | ||
username: string | ||
clubname: string | ||
location: string | ||
email: string | ||
comments: string | ||
} | ||
|
||
export type FormResponse = { | ||
success: boolean | ||
message: string | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import useSWR from 'swr' | ||
import { Modal, ModalContent, ModalHeader, Spinner } from '@nextui-org/react' | ||
import fetchLifterGraphData from '@/api/fetchLifterGraphData/fetchLifterGraphData' | ||
import { LifterGraph } from './lifterGraph' | ||
|
||
function LifterGraphModal({ | ||
lifterName, | ||
onClose, | ||
}: { | ||
lifterName: string | ||
onClose: () => void | ||
}) { | ||
const { data, isLoading } = useSWR(lifterName, fetchLifterGraphData) | ||
|
||
return ( | ||
<Modal | ||
closeButton | ||
isOpen={true} | ||
size={'4xl'} | ||
onClose={onClose} | ||
placement={'center'} | ||
> | ||
<ModalContent> | ||
<ModalHeader>{lifterName}</ModalHeader> | ||
{isLoading ? ( | ||
<div className="w-full h-full z-10 flex justify-center items-center"> | ||
<Spinner size="lg" label="Loading..." /> | ||
</div> | ||
) : ( | ||
<LifterGraph lifterHistory={data} setRatio={1} /> | ||
)} | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default LifterGraphModal |
Oops, something went wrong.