pull/122/head
Alex 1 year ago
parent 287f75dfe8
commit d98b558ab0

@ -1,49 +1,49 @@
export type Doc = { export type Doc = {
name: string; name: string;
language: string; language: string;
version: string; version: string;
description: string; description: string;
fullName: string; fullName: string;
dat: string; dat: string;
docLink: string; docLink: string;
model: 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. //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> { export async function getDocs(): Promise<Doc[] | null> {
try { try {
const response = await fetch( const response = await fetch(
'https://d3dg1063dc54p9.cloudfront.net/combined.json', 'https://d3dg1063dc54p9.cloudfront.net/combined.json',
); );
const data = await response.json(); const data = await response.json();
const docs: Doc[] = []; const docs: Doc[] = [];
data.forEach((doc: object) => { data.forEach((doc: object) => {
docs.push(doc as Doc); docs.push(doc as Doc);
}); });
return docs; return docs;
} catch (error) { } catch (error) {
console.log(error); console.log(error);
return null; return null;
} }
} }
export function getLocalApiKey(): string | null { export function getLocalApiKey(): string | null {
const key = localStorage.getItem('DocsGPTApiKey'); const key = localStorage.getItem('DocsGPTApiKey');
return key; return key;
} }
export function getLocalRecentDocs(): string | null { export function getLocalRecentDocs(): string | null {
const doc = localStorage.getItem('DocsGPTRecentDocs'); const doc = localStorage.getItem('DocsGPTRecentDocs');
return doc; return doc;
} }
export function setLocalApiKey(key: string): void { export function setLocalApiKey(key: string): void {
localStorage.setItem('DocsGPTApiKey', key); localStorage.setItem('DocsGPTApiKey', key);
} }
export function setLocalRecentDocs(doc: Doc): void { export function setLocalRecentDocs(doc: Doc): void {
localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(doc)); localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(doc));
} }

@ -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;
}
}
Loading…
Cancel
Save