-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
added modal to select source documentation #103
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3941c4c
Merge pull request #5 from TaylorS15/taylor-working
TaylorS15 60b6e4e
Merge pull request #6 from TaylorS15/taylor-working
TaylorS15 af198ca
Merge branch 'arc53:main' into main
TaylorS15 e2fef9c
Merge pull request #7 from TaylorS15/taylor-working
TaylorS15 5902ca0
added modal to select source documentation
TaylorS15 112e7a2
removed unused import/export
TaylorS15 0ccac90
Merge pull request #8 from TaylorS15/taylor-working
TaylorS15 db9a416
fixed about page margin
TaylorS15 530e13b
Merge pull request #9 from TaylorS15/taylor-working
TaylorS15 d810438
small nav fix
TaylorS15 d295828
Merge pull request #10 from TaylorS15/taylor-working
TaylorS15 107cfcb
Merge pull request #11 from TaylorS15/taylor-working
TaylorS15 f61fc71
bug fix
TaylorS15 80ada47
fix
TaylorS15 dea949f
Moved Doc type to selectDocsApi
TaylorS15 e25c127
Merge pull request #12 from TaylorS15/taylor-working
TaylorS15 81180c2
Merge pull request #13 from TaylorS15/taylor-working
TaylorS15 8ee34d8
little change
TaylorS15 708c11b
removed logging
TaylorS15 7d99b6c
Merge pull request #14 from TaylorS15/taylor-working
TaylorS15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,132 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { ActiveState } from '../models/misc'; | ||
import { | ||
setSelectedDocs, | ||
setSourceDocs, | ||
selectSourceDocs, | ||
} from './preferenceSlice'; | ||
import { getDocs, Doc } from './selectDocsApi'; | ||
|
||
export default function APIKeyModal({ | ||
modalState, | ||
setModalState, | ||
isCancellable = true, | ||
}: { | ||
modalState: ActiveState; | ||
setModalState: (val: ActiveState) => void; | ||
isCancellable?: boolean; | ||
}) { | ||
const dispatch = useDispatch(); | ||
const docs = useSelector(selectSourceDocs); | ||
const [localSelectedDocs, setLocalSelectedDocs] = useState<Doc | null>(null); | ||
const [isDocsListOpen, setIsDocsListOpen] = useState(false); | ||
const [isError, setIsError] = useState(false); | ||
|
||
function handleSubmit() { | ||
if (!localSelectedDocs) { | ||
setIsError(true); | ||
} else { | ||
dispatch(setSelectedDocs(localSelectedDocs)); | ||
setModalState('INACTIVE'); | ||
setLocalSelectedDocs(null); | ||
setIsError(false); | ||
} | ||
} | ||
|
||
function handleCancel() { | ||
setLocalSelectedDocs(null); | ||
setIsError(false); | ||
setModalState('INACTIVE'); | ||
} | ||
|
||
useEffect(() => { | ||
async function requestDocs() { | ||
const data = await getDocs(); | ||
dispatch(setSourceDocs(data)); | ||
} | ||
|
||
requestDocs(); | ||
}, []); | ||
|
||
return ( | ||
<div | ||
className={`${ | ||
modalState === 'ACTIVE' ? 'visible' : 'hidden' | ||
} absolute z-30 h-screen w-screen bg-gray-alpha`} | ||
> | ||
<article className="mx-auto mt-24 flex w-[90vw] max-w-lg flex-col gap-4 rounded-lg bg-white p-6 shadow-lg"> | ||
<p className="text-xl text-jet">Select Source Documentation</p> | ||
<p className="text-lg leading-5 text-gray-500"> | ||
Please select the library of documentation that you would like to use | ||
with our app. | ||
</p> | ||
<div className="relative"> | ||
<div | ||
className="h-10 w-full cursor-pointer border-b-2" | ||
onClick={() => setIsDocsListOpen(!isDocsListOpen)} | ||
> | ||
{!localSelectedDocs ? ( | ||
<p className="py-3 text-gray-500">Select</p> | ||
) : ( | ||
<p className="py-3"> | ||
{localSelectedDocs.name} {localSelectedDocs.version} | ||
</p> | ||
)} | ||
</div> | ||
{isDocsListOpen && ( | ||
<div className="absolute top-10 left-0 max-h-52 w-full overflow-y-scroll bg-white"> | ||
{docs ? ( | ||
docs.map((doc, index) => { | ||
if (doc.model) { | ||
return ( | ||
<div | ||
key={index} | ||
onClick={() => { | ||
setLocalSelectedDocs(doc); | ||
setIsDocsListOpen(false); | ||
}} | ||
className="h-10 w-full cursor-pointer border-x-2 border-b-2 hover:bg-gray-100" | ||
> | ||
<p className="ml-5 py-3"> | ||
{doc.name} {doc.version} | ||
</p> | ||
</div> | ||
); | ||
} | ||
}) | ||
) : ( | ||
<div className="h-10 w-full cursor-pointer border-x-2 border-b-2 hover:bg-gray-100"> | ||
<p className="ml-5 py-3">No default documentation.</p> | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
<div className="flex flex-row-reverse"> | ||
{isCancellable && ( | ||
<button | ||
onClick={() => handleCancel()} | ||
className="ml-5 h-10 w-20 rounded-lg border border-violet-700 bg-white text-violet-800 transition-all hover:bg-violet-700 hover:text-white" | ||
> | ||
Cancel | ||
</button> | ||
)} | ||
<button | ||
onClick={() => { | ||
handleSubmit(); | ||
}} | ||
className="ml-auto h-10 w-20 rounded-lg bg-violet-800 text-white transition-all hover:bg-violet-700" | ||
> | ||
Save | ||
</button> | ||
{isError && ( | ||
<p className="mr-auto text-sm text-red-500"> | ||
Please select source documentation. | ||
</p> | ||
)} | ||
</div> | ||
</article> | ||
</div> | ||
); | ||
} |
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,33 @@ | ||
//Exporting Doc type from here since its the first place its used and seems needless to make an entire file for it. | ||
export type Doc = { | ||
name: string; | ||
language: string; | ||
version: string; | ||
description: string; | ||
fullName: string; | ||
dat: string; | ||
docLink: string; | ||
model: string; | ||
}; | ||
|
||
//Fetches all JSON objects from the source. We only use the objects with the "model" property in SelectDocsModal.tsx. Hopefully can clean up the source file later. | ||
export async function getDocs(): Promise<Doc[] | null> { | ||
try { | ||
//Fetch default source docs | ||
const response = await fetch( | ||
'https://d3dg1063dc54p9.cloudfront.net/combined.json', | ||
); | ||
const data = await response.json(); | ||
|
||
//Create array of Doc objects | ||
const docs: Doc[] = []; | ||
|
||
data.forEach((doc: object) => { | ||
docs.push(doc as Doc); | ||
}); | ||
|
||
return docs; | ||
} catch (error) { | ||
return null; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we gotta put the two modal opening in sequence, can do it in the next PR.