Merge branch 'main' into 1059-migrating-database-to-new-model

This commit is contained in:
Alex
2024-09-09 23:55:25 +01:00
64 changed files with 3517 additions and 4971 deletions

View File

@@ -22,15 +22,11 @@ export default function APIKeyModal({
const modalRef = useRef(null);
const { isMobile } = useMediaQuery();
useOutsideAlerter(
modalRef,
() => {
if (isMobile && modalState === 'ACTIVE') {
setModalState('INACTIVE');
}
},
[modalState],
);
useOutsideAlerter(modalRef, () => {
if (isMobile && modalState === 'ACTIVE') {
setModalState('INACTIVE');
}
}, [modalState]);
function handleSubmit() {
if (key.length <= 1) {

View File

@@ -1,114 +0,0 @@
import { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { ActiveState } from '../models/misc';
import Modal from '../modals';
import {
setSelectedDocs,
setSourceDocs,
selectSourceDocs,
selectSelectedDocs,
} from './preferenceSlice';
import { Doc } from '../models/misc';
import { getDocs } from './preferenceApi';
export default function APIKeyModal({
modalState,
setModalState,
isCancellable = true,
}: {
modalState: ActiveState;
setModalState: (val: ActiveState) => void;
isCancellable?: boolean;
}) {
const dispatch = useDispatch();
const docs = useSelector(selectSourceDocs);
const selectedDoc = useSelector(selectSelectedDocs);
const [localSelectedDocs, setLocalSelectedDocs] = useState<Doc | null>(
selectedDoc,
);
const [isDocsListOpen, setIsDocsListOpen] = useState(false);
const [isError, setIsError] = useState(false);
function handleSubmit() {
if (!localSelectedDocs) {
setIsError(true);
} else {
dispatch(setSelectedDocs(localSelectedDocs));
setModalState('INACTIVE');
setIsError(false);
}
}
function handleCancel() {
setIsError(false);
setModalState('INACTIVE');
}
useEffect(() => {
async function requestDocs() {
const data = await getDocs();
dispatch(setSourceDocs(data));
}
requestDocs();
}, []);
return (
<Modal
handleSubmit={handleSubmit}
isCancellable={isCancellable}
handleCancel={handleCancel}
modalState={modalState}
errorMessage="Please select Source Documentation"
isError={isError}
render={() => {
return (
<article className="mx-auto mt-24 flex w-[90vw] max-w-lg flex-col gap-4 rounded-t-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}</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}</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>
</article>
);
}}
/>
);
}

View File

@@ -64,11 +64,11 @@ export function setLocalPrompt(prompt: string): void {
localStorage.setItem('DocsGPTPrompt', prompt);
}
export function setLocalRecentDocs(doc: Doc): void {
export function setLocalRecentDocs(doc: Doc | null): void {
localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(doc));
let docPath = 'default';
if (doc.type === 'local') {
if (doc?.type === 'local') {
docPath = 'local' + '/' + doc.name + '/';
}
userService

View File

@@ -93,8 +93,7 @@ prefListenerMiddleware.startListening({
matcher: isAnyOf(setSelectedDocs),
effect: (action, listenerApi) => {
setLocalRecentDocs(
(listenerApi.getState() as RootState).preference.selectedDocs ??
([] as unknown as Doc),
(listenerApi.getState() as RootState).preference.selectedDocs ?? null,
);
},
});