Skip to content

Commit

Permalink
fix(config-ui): adjust the connections request
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsweet committed Oct 23, 2023
1 parent 2871530 commit 517f0f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
18 changes: 1 addition & 17 deletions config-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
*
*/

import { useEffect } from 'react';
import { createBrowserRouter, Navigate, RouterProvider, json } from 'react-router-dom';

import { useAppDispatch, useAppSelector } from '@/app/hook';
import { init, selectStatus } from '@/features';
import { PageLoading } from '@/components';
import {
ConnectionHomePage,
Expand Down Expand Up @@ -103,17 +100,4 @@ const router = createBrowserRouter([
},
]);

export const App = () => {
const dispatch = useAppDispatch();
const status = useAppSelector(selectStatus);

useEffect(() => {
dispatch(init());
}, []);

if (['idle', 'loading'].includes(status)) {
return <PageLoading />;
}

return <RouterProvider router={router} fallbackElement={<PageLoading />} />;
};
export const App = () => <RouterProvider router={router} fallbackElement={<PageLoading />} />;
10 changes: 9 additions & 1 deletion config-ui/src/features/connections/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ const initialState: {
};

export const init = createAsyncThunk('connections/init', async () => {
const getConnections = async (plugin: string) => {
try {
return API.connection.list(plugin);
} catch {
return [];
}
};

const res = await Promise.all(
PluginConfig.map(async ({ plugin }) => {
const connections = await API.connection.list(plugin);
const connections = await getConnections(plugin);
return connections.map((connection) => transformConnection(plugin, connection));
}),
);
Expand Down
17 changes: 15 additions & 2 deletions config-ui/src/routes/layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
*
*/

import { useRef } from 'react';
import { useEffect, useRef } from 'react';
import { useLoaderData, Outlet, useNavigate, useLocation } from 'react-router-dom';
import { CSSTransition } from 'react-transition-group';
import { Menu, MenuItem, Navbar, Alignment } from '@blueprintjs/core';

import { Logo, ExternalLink, IconButton } from '@/components';
import { useAppDispatch, useAppSelector } from '@/app/hook';
import { PageLoading, Logo, ExternalLink, IconButton } from '@/components';
import { init, selectStatus } from '@/features';
import { DOC_URL } from '@/release';
import { TipsContextProvider, TipsContextConsumer } from '@/store';

Expand All @@ -42,10 +44,21 @@ export const Layout = () => {
const navigate = useNavigate();
const { pathname } = useLocation();

const dispatch = useAppDispatch();
const status = useAppSelector(selectStatus);

const menu = useMenu();

const tipsRef = useRef(null);

useEffect(() => {
dispatch(init());
}, []);

if (['idle', 'loading'].includes(status)) {
return <PageLoading />;
}

const handlePushPath = (it: MenuItemType) => {
if (!it.target) {
navigate(it.path);
Expand Down

0 comments on commit 517f0f8

Please sign in to comment.