From 27a524f05dcb4b6d56fbb20a22e942473dd1575a Mon Sep 17 00:00:00 2001 From: jordan-ae Date: Mon, 6 Jan 2025 09:22:49 +0100 Subject: [PATCH 1/3] fix: update fetch to run multiple times --- src/components/form/bounty/index.tsx | 52 +++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/components/form/bounty/index.tsx b/src/components/form/bounty/index.tsx index a530bc1c..80e97d89 100644 --- a/src/components/form/bounty/index.tsx +++ b/src/components/form/bounty/index.tsx @@ -171,28 +171,48 @@ function Form(props: FormProps) { useEffect(() => { (async () => { try { - const features = await main.getWorkspaceFeatures(workspaceid, { - page: 1, - status: 'active' - }); + interface Feature { + uuid: string; + name: string; + } + let allFeatures: Feature[] = []; + let currentPage = 1; + let hasMoreData = true; + + while (hasMoreData) { + const features = await main.getWorkspaceFeatures(workspaceid, { + page: currentPage, + status: 'active' + }); + + console.log(features); + + if (Array.isArray(features)) { + allFeatures = [...allFeatures, ...features]; + console.log(allFeatures); + hasMoreData = features.length > 0; // If no features returned, stop fetching + console.log(hasMoreData); + currentPage++; + } else { + console.log('Unexpected features object:', features); + hasMoreData = false; // Stop loop on unexpected response + } + } - if (Array.isArray(features)) { - const filteredFeatures = features.map( - ({ uuid, name }: { uuid: string; name: string }) => ({ - value: uuid, - label: name - }) - ); + // Process features once all pages are fetched + const filteredFeatures = allFeatures.map( + ({ uuid, name }: { uuid: string; name: string }) => ({ + value: uuid, + label: name + }) + ); - setWorkspaceFeatures(filteredFeatures); - } else { - console.log('Features object:', features); - } + setWorkspaceFeatures(filteredFeatures); } catch (error) { console.error('Error fetching or parsing features:', error); } })(); - }, [main, featureid, workspaceFeature, workspaceid]); + }, [main, workspaceid]); useEffect(() => { (async () => { From af7098400caba9bbdb070d76d45f918dec7db484 Mon Sep 17 00:00:00 2001 From: jordan-ae Date: Mon, 6 Jan 2025 11:21:39 +0100 Subject: [PATCH 2/3] chore: fetch all features in workspace --- src/people/widgetViews/WorkspaceMission.tsx | 79 +++++++++++++-------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/src/people/widgetViews/WorkspaceMission.tsx b/src/people/widgetViews/WorkspaceMission.tsx index 3295d21e..1f9a5feb 100644 --- a/src/people/widgetViews/WorkspaceMission.tsx +++ b/src/people/widgetViews/WorkspaceMission.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-vars */ import { EuiDragDropContext, EuiDraggable, @@ -78,7 +79,6 @@ import AddRepoModal from './workspace/AddRepoModal'; import EditSchematic from './workspace/EditSchematicModal'; import ManageWorkspaceUsersModal from './workspace/ManageWorkspaceUsersModal'; import { BudgetWrapComponent } from './BudgetWrap'; -import { LoadMoreContainer } from './WidgetSwitchViewer'; import { EditableField } from './workspace/EditableField'; import { Toast } from './workspace/interface'; @@ -301,7 +301,6 @@ const WorkspaceMission = () => { const [modalType, setModalType] = useState('add'); const [featureModal, setFeatureModal] = useState(false); const [features, setFeatures] = useState([]); - const [currentPage, setCurrentPage] = useState(1); const [featuresCount, setFeaturesCount] = useState(0); const [isOpenUserManage, setIsOpenUserManage] = useState(false); const [users, setUsers] = useState([]); @@ -321,6 +320,7 @@ const WorkspaceMission = () => { const [missionPreviewMode, setMissionPreviewMode] = useState<'preview' | 'edit'>('edit'); const [tacticsPreviewMode, setTacticsPreviewMode] = useState<'preview' | 'edit'>('edit'); const [toasts, setToasts] = useState([]); + const [holding, setHolding] = useState(false); const fetchCodeGraph = useCallback(async () => { try { @@ -559,18 +559,18 @@ const WorkspaceMission = () => { getWorkspaceUsers(); }, [getWorkspaceData, getWorkspaceUsers]); - const getFeaturesCount = useCallback(async () => { - if (!uuid) return; - const featuresCount = await main.getWorkspaceFeaturesCount(uuid); - if (!featuresCount) return; - setFeaturesCount(featuresCount); + // const getFeaturesCount = useCallback(async () => { + // if (!uuid) return; + // const featuresCount = await main.getWorkspaceFeaturesCount(uuid); + // if (!featuresCount) return; + // setFeaturesCount(featuresCount); - setLoading(false); - }, [uuid, main]); + // setLoading(false); + // }, [uuid, main]); - useEffect(() => { - getFeaturesCount(); - }, [getFeaturesCount]); + // useEffect(() => { + // getFeaturesCount(); + // }, [getFeaturesCount]); const updateFeatures = (newFeatures: Feature[]) => { const updatedFeatures: Feature[] = [...features]; @@ -585,17 +585,40 @@ const WorkspaceMission = () => { const getFeatures = useCallback(async () => { if (!uuid) return; - const featuresRes = await main.getWorkspaceFeatures(uuid, { - page: currentPage, - status: 'active' - }); - if (!featuresRes) return; - updateFeatures(featuresRes); - getFeaturesCount(); + setLoading(true); // Set loading to true when the fetch starts + setHolding(true); // Set holding to true to show fetching is in progress - setLoading(false); - }, [uuid, main, getFeaturesCount, currentPage]); + let allFeatures: Feature[] = []; + let page = 1; + let hasMoreData = true; + + try { + while (hasMoreData) { + const featuresRes = await main.getWorkspaceFeatures(uuid, { + page, + status: 'active' + }); + + if (featuresRes && Array.isArray(featuresRes)) { + allFeatures = [...allFeatures, ...featuresRes]; + hasMoreData = featuresRes.length > 0; // Stop fetching if no data returned + page++; + } else { + hasMoreData = false; // Stop on unexpected response + } + } + + if (allFeatures.length > 0) { + updateFeatures(allFeatures); // Update features with all data + } + } catch (error) { + console.error('Error fetching features:', error); + } finally { + setLoading(false); // Reset loading state after fetch completes + setHolding(false); // Reset holding state after fetch completes + } + }, [uuid, main]); useEffect(() => { getFeatures(); @@ -712,10 +735,10 @@ const WorkspaceMission = () => { setSchematicModal(!schematicModal); }; - const loadMore = () => { - const nextPage = currentPage + 1; - setCurrentPage(nextPage); - }; + // const loadMore = () => { + // const nextPage = currentPage + 1; + // setCurrentPage(nextPage); + // }; const handleReorderFeatures = async (feat: Feature, priority: number) => { await main.addWorkspaceFeature({ @@ -757,7 +780,7 @@ const WorkspaceMission = () => { [users] ); - if (loading) { + if (loading || holding) { return ( @@ -1337,7 +1360,7 @@ const WorkspaceMission = () => { - {featuresCount > features.length ? ( + {/* {featuresCount > features.length ? ( { Load More - ) : null} + ) : null} */} Date: Mon, 6 Jan 2025 11:22:56 +0100 Subject: [PATCH 3/3] chore: fetch all features in workspace --- src/people/widgetViews/WorkspaceMission.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/people/widgetViews/WorkspaceMission.tsx b/src/people/widgetViews/WorkspaceMission.tsx index 1f9a5feb..08d84355 100644 --- a/src/people/widgetViews/WorkspaceMission.tsx +++ b/src/people/widgetViews/WorkspaceMission.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable no-unused-vars */ import { EuiDragDropContext,