Skip to content

Commit

Permalink
task/wg-199-react-query-initial-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sophia-massie committed Dec 15, 2023
1 parent e2b7ce6 commit 4d241fd
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 15 deletions.
143 changes: 136 additions & 7 deletions react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@reduxjs/toolkit": "^1.8.4",
"@testing-library/react": "^13.4.0",
"@types/leaflet.markercluster": "^1.5.1",
"axios": "^1.6.2",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-prettier": "^4.2.1",
Expand All @@ -34,6 +35,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-leaflet": "^4.2.0",
"react-query": "^3.39.3",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0"
},
Expand Down
1 change: 1 addition & 0 deletions react/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as useProjects } from './projects/useProjects';
14 changes: 14 additions & 0 deletions react/src/hooks/projects/useProjects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { UseQueryResult } from 'react-query';
import { Project } from '../../types';
import { useGet } from '../../requests';

const useProjects = (): UseQueryResult<Project[]> => {
const query = useGet<Project[]>({
endpoint: '/projects/',
key: ['project'],
baseUrl: 'https://agave.designsafe-ci.org/geo/v2',
});
return query;
};

export default useProjects;
7 changes: 6 additions & 1 deletion react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { QueryClient, QueryClientProvider } from 'react-query';
import App from './AppRouter';
import './index.css';
import store from './redux/store';
import { Provider } from 'react-redux';

const queryClient = new QueryClient();

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<Provider store={store}>
<App />
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</Provider>
</React.StrictMode>
);
15 changes: 8 additions & 7 deletions react/src/pages/MainMenu/MainMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import {
useGetGeoapiProjectsQuery,
useGetGeoapiUserInfoQuery,
} from '../../redux/api/geoapi';
import { useProjects } from '../../hooks';

function MainMenu() {
useGetGeoapiProjectsQuery();
useGetGeoapiUserInfoQuery();
return <h2>Main Menu</h2>;
const { data, isLoading, error } = useProjects();

Check warning on line 5 in react/src/pages/MainMenu/MainMenu.tsx

View workflow job for this annotation

GitHub Actions / React-Linting

'isLoading' is assigned a value but never used

Check warning on line 5 in react/src/pages/MainMenu/MainMenu.tsx

View workflow job for this annotation

GitHub Actions / React-Linting

'error' is assigned a value but never used
return (
<>
<h2>Main Menu</h2>
<h5>You have {data?.length} projects. </h5>
</>
);
}

export default MainMenu;
Loading

0 comments on commit 4d241fd

Please sign in to comment.