This pull request includes major changes to the routing and data fetching in the client-side codebase, as well as a small change to the server-side settings controller. The changes mainly involve moving the data fetching logic from individual components to the router, and using the useLoaderData hook to access the fetched data in the components. This simplifies the components by removing unnecessary state and effect hooks related to data fetching, and centralizes the data fetching logic in the router.
Changes to the router:
src/client/routes.jsx: Added a loader prop to each Route component under the /account path. Each loader is an asynchronous function that imports and calls the appropriate API function to fetch the necessary data for the route.
src/server/controllers/admin/settings.js: Changed the findMany call to findFirst when fetching admin settings, as there should only be one set of admin settings.
This pull request includes major changes to the routing and data fetching in the client-side codebase, as well as a small change to the server-side settings controller. The changes mainly involve moving the data fetching logic from individual components to the router, and using the
useLoaderData
hook to access the fetched data in the components. This simplifies the components by removing unnecessary state and effect hooks related to data fetching, and centralizes the data fetching logic in the router.Changes to the router:
src/client/routes.jsx
: Added aloader
prop to eachRoute
component under the/account
path. Each loader is an asynchronous function that imports and calls the appropriate API function to fetch the necessary data for the route.Changes to components:
src/client/routes/account/account.jsx
: Removed thegetUser
call and the associated state and effect hook. Now usesuseLoaderData
to get the user data. [1] [2] [3]src/client/routes/account/index.jsx
: Similar changes asaccount.jsx
. [1] [2]src/client/routes/account/secrets.jsx
: Similar changes asaccount.jsx
, but for fetching secrets. [1] [2] [3] [4]src/client/routes/account/settings.jsx
: Similar changes asaccount.jsx
, but for fetching settings. [1] [2]src/client/routes/account/users.jsx
: Similar changes asaccount.jsx
, but for fetching users. Also moved the user row rendering logic to a separateUserRows
component. [1] [2] [3] [4] [5] [6]Change to server-side controller:
src/server/controllers/admin/settings.js
: Changed thefindMany
call tofindFirst
when fetching admin settings, as there should only be one set of admin settings.