From d98b558ab0e0b0cfe7789664aaf68a813e1837cd Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 24 Feb 2023 12:02:48 +0000 Subject: [PATCH] merge --- frontend/src/preferences/preferenceApi.ts | 98 +++++++++++------------ frontend/src/preferences/selectDocsApi.ts | 33 ++++++++ 2 files changed, 82 insertions(+), 49 deletions(-) create mode 100644 frontend/src/preferences/selectDocsApi.ts diff --git a/frontend/src/preferences/preferenceApi.ts b/frontend/src/preferences/preferenceApi.ts index ab50fd0..6ede1b4 100644 --- a/frontend/src/preferences/preferenceApi.ts +++ b/frontend/src/preferences/preferenceApi.ts @@ -1,49 +1,49 @@ -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 { - try { - const response = await fetch( - 'https://d3dg1063dc54p9.cloudfront.net/combined.json', - ); - const data = await response.json(); - - const docs: Doc[] = []; - - data.forEach((doc: object) => { - docs.push(doc as Doc); - }); - - return docs; - } catch (error) { - console.log(error); - return null; - } -} - -export function getLocalApiKey(): string | null { - const key = localStorage.getItem('DocsGPTApiKey'); - return key; -} - -export function getLocalRecentDocs(): string | null { - const doc = localStorage.getItem('DocsGPTRecentDocs'); - return doc; -} - -export function setLocalApiKey(key: string): void { - localStorage.setItem('DocsGPTApiKey', key); -} - -export function setLocalRecentDocs(doc: Doc): void { - localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(doc)); -} +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 { + try { + const response = await fetch( + 'https://d3dg1063dc54p9.cloudfront.net/combined.json', + ); + const data = await response.json(); + + const docs: Doc[] = []; + + data.forEach((doc: object) => { + docs.push(doc as Doc); + }); + + return docs; + } catch (error) { + console.log(error); + return null; + } +} + +export function getLocalApiKey(): string | null { + const key = localStorage.getItem('DocsGPTApiKey'); + return key; +} + +export function getLocalRecentDocs(): string | null { + const doc = localStorage.getItem('DocsGPTRecentDocs'); + return doc; +} + +export function setLocalApiKey(key: string): void { + localStorage.setItem('DocsGPTApiKey', key); +} + +export function setLocalRecentDocs(doc: Doc): void { + localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(doc)); +} diff --git a/frontend/src/preferences/selectDocsApi.ts b/frontend/src/preferences/selectDocsApi.ts new file mode 100644 index 0000000..ff78e00 --- /dev/null +++ b/frontend/src/preferences/selectDocsApi.ts @@ -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 { + 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; + } +}