diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx
index e7a4ffd8..cfc7a825 100644
--- a/frontend/src/Navigation.tsx
+++ b/frontend/src/Navigation.tsx
@@ -108,17 +108,16 @@ export default function Navigation({
>
-
-
+
>
);
}
diff --git a/frontend/src/api/docs.ts b/frontend/src/api/docs.ts
deleted file mode 100644
index 6d93f36f..00000000
--- a/frontend/src/api/docs.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { Doc } from '../models/misc';
-
-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: Array = [];
-
- data.forEach((doc: Doc) => {
- docs.push(doc);
- });
-
- return docs;
- } catch (error) {
- return null;
- }
-}
diff --git a/frontend/src/models/misc.ts b/frontend/src/models/misc.ts
index 5f9ed136..dbf21aed 100644
--- a/frontend/src/models/misc.ts
+++ b/frontend/src/models/misc.ts
@@ -3,14 +3,3 @@ export type ActiveState = 'ACTIVE' | 'INACTIVE';
export type User = {
avatar: string;
};
-
-export type Doc = {
- name: string;
- language: string;
- version: string;
- description: string;
- fullName: string;
- dat: string;
- docLink: string;
- model: string;
-};
diff --git a/frontend/src/preferences/SelectDocsModal.tsx b/frontend/src/preferences/SelectDocsModal.tsx
index 3850daff..91a60ac1 100644
--- a/frontend/src/preferences/SelectDocsModal.tsx
+++ b/frontend/src/preferences/SelectDocsModal.tsx
@@ -1,8 +1,13 @@
import { useEffect, useState } from 'react';
-import { useDispatch } from 'react-redux';
-import { ActiveState, Doc } from '../models/misc';
-import { setSelectedDocs } from './preferenceSlice';
-import { getDocs } from '../api/docs';
+import { useDispatch, useSelector } from 'react-redux';
+import { ActiveState } from '../models/misc';
+import { Doc } from './selectDocsApi';
+import {
+ setSelectedDocs,
+ setSourceDocs,
+ selectSourceDocs,
+} from './preferenceSlice';
+import { getDocs } from './selectDocsApi';
export default function APIKeyModal({
modalState,
@@ -14,7 +19,7 @@ export default function APIKeyModal({
isCancellable?: boolean;
}) {
const dispatch = useDispatch();
- const [docs, setDocs] = useState(null);
+ const docs = useSelector(selectSourceDocs);
const [localSelectedDocs, setLocalSelectedDocs] = useState(null);
const [isDocsListOpen, setIsDocsListOpen] = useState(false);
const [isError, setIsError] = useState(false);
@@ -39,7 +44,7 @@ export default function APIKeyModal({
useEffect(() => {
async function requestDocs() {
const data = await getDocs();
- setDocs(data);
+ dispatch(setSourceDocs(data));
}
requestDocs();
diff --git a/frontend/src/preferences/preferenceSlice.ts b/frontend/src/preferences/preferenceSlice.ts
index 0ee3b8e5..a501df55 100644
--- a/frontend/src/preferences/preferenceSlice.ts
+++ b/frontend/src/preferences/preferenceSlice.ts
@@ -1,15 +1,17 @@
import { createSlice } from '@reduxjs/toolkit';
-import { Doc } from '../models/misc';
+import { Doc } from './selectDocsApi';
import store from '../store';
interface Preference {
apiKey: string;
selectedDocs: Doc | null;
+ sourceDocs: Doc[] | null;
}
const initialState: Preference = {
apiKey: '',
selectedDocs: null,
+ sourceDocs: null,
};
export const prefSlice = createSlice({
@@ -21,11 +23,16 @@ export const prefSlice = createSlice({
},
setSelectedDocs: (state, action) => {
state.selectedDocs = action.payload;
+ console.log('setSelectedDocs', state.selectedDocs);
+ },
+ setSourceDocs: (state, action) => {
+ state.sourceDocs = action.payload;
+ console.log('setSourceDocs', state.sourceDocs);
},
},
});
-export const { setApiKey, setSelectedDocs } = prefSlice.actions;
+export const { setApiKey, setSelectedDocs, setSourceDocs } = prefSlice.actions;
export default prefSlice.reducer;
type RootState = ReturnType;
@@ -35,3 +42,5 @@ export const selectApiKeyStatus = (state: RootState) =>
!!state.preference.apiKey;
export const selectSelectedDocsStatus = (state: RootState) =>
!!state.preference.selectedDocs;
+export const selectSourceDocs = (state: RootState) =>
+ state.preference.sourceDocs;
diff --git a/frontend/src/preferences/selectDocsApi.ts b/frontend/src/preferences/selectDocsApi.ts
new file mode 100644
index 00000000..5c700cff
--- /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: Doc) => {
+ docs.push(doc);
+ });
+
+ return docs;
+ } catch (error) {
+ return null;
+ }
+}