-
Notifications
You must be signed in to change notification settings - Fork 0
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 #61 from Quiddlee/feat/add_suspense_to_docs
Feat/add suspense to docs
- Loading branch information
Showing
10 changed files
with
124 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
import { SetStateAction } from 'react'; | ||
import { Dispatch, SetStateAction } from 'react'; | ||
|
||
import introspectionQuery from '@/shared/constants/introspectionQuery'; | ||
import { DocsSchemaType } from '@/shared/types'; | ||
|
||
export default async function getEndpointSchema( | ||
endpoint: string, | ||
setter: (value: SetStateAction<DocsSchemaType>) => void, | ||
schemaSetter: (value: SetStateAction<DocsSchemaType>) => void, | ||
loadingSetter: Dispatch<SetStateAction<boolean>>, | ||
) { | ||
const response = await fetch(endpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(introspectionQuery), | ||
}); | ||
if (response.ok && response.status === 200) { | ||
const res = await response.json(); | ||
return setter(res.data.__schema); | ||
try { | ||
loadingSetter(true); | ||
const response = await fetch(endpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(introspectionQuery), | ||
}); | ||
if (response.ok && response.status === 200) { | ||
const res = await response.json(); | ||
loadingSetter(false); | ||
return schemaSetter(res.data.__schema); | ||
} | ||
loadingSetter(false); | ||
return schemaSetter(null); | ||
} catch (e) { | ||
loadingSetter(false); | ||
return schemaSetter(null); | ||
} | ||
return setter(null); | ||
} |
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,15 @@ | ||
import DocsModalLayout from '@/layouts/DocsModalLayout'; | ||
import Spinner from '@/shared/ui/Spinner'; | ||
|
||
const DocsLoader = () => { | ||
return ( | ||
<DocsModalLayout> | ||
<div className="flex h-full w-full flex-col items-center justify-center"> | ||
<Spinner indeterminate /> | ||
<p className="mt-10 text-on-surface">We are loading your docs...</p> | ||
</div> | ||
</DocsModalLayout> | ||
); | ||
}; | ||
|
||
export default DocsLoader; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { FC, SetStateAction } from 'react'; | ||
|
||
import DocsModalLayout from '@/layouts/DocsModalLayout'; | ||
|
||
import CloseDocsBtn from './CloseDocsBtn'; | ||
|
||
type PropsType = { | ||
closeModal: (value: SetStateAction<boolean>) => void; | ||
}; | ||
|
||
const SchemaFallbackUi: FC<PropsType> = ({ closeModal }) => { | ||
return ( | ||
<DocsModalLayout> | ||
<CloseDocsBtn | ||
onClick={() => { | ||
closeModal((prev) => !prev); | ||
}} | ||
className="absolute right-[20px] top-[20px] z-20" | ||
/> | ||
<div className="flex h-full w-full items-center p-6"> | ||
<p className="w-full text-center text-on-surface">There is no schema at provided endpoint :(</p> | ||
</div> | ||
</DocsModalLayout> | ||
); | ||
}; | ||
|
||
export default SchemaFallbackUi; |
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,15 @@ | ||
import DocsModalLayout from '@/layouts/DocsModalLayout'; | ||
import Spinner from '@/shared/ui/Spinner'; | ||
|
||
const SuspenseFallback = () => { | ||
return ( | ||
<DocsModalLayout> | ||
<div className="flex h-full w-full flex-col items-center justify-center"> | ||
<Spinner indeterminate /> | ||
<p className="mt-10 text-on-surface">Soon here will be docs section...</p> | ||
</div> | ||
</DocsModalLayout> | ||
); | ||
}; | ||
|
||
export default SuspenseFallback; |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
type PropsType = { children: JSX.Element | JSX.Element[] }; | ||
|
||
const DocsModalLayout = ({ children }: PropsType) => { | ||
return ( | ||
<section className="relative z-20 h-[100dvh] w-[270px] cursor-auto rounded-r-[28px] bg-surface p-3 sm:w-[420px]"> | ||
{children} | ||
</section> | ||
); | ||
}; | ||
|
||
export default DocsModalLayout; |
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 @@ | ||
import React from 'react'; | ||
|
||
import { createComponent } from '@lit/react'; | ||
import { MdCircularProgress } from '@material/web/progress/circular-progress'; | ||
|
||
const Spinner = createComponent({ | ||
react: React, | ||
tagName: 'md-circular-progress', | ||
elementClass: MdCircularProgress, | ||
}); | ||
|
||
export default Spinner; |
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