From 1fd055116d3435efddbc93b7c8bbd483e9ed92f7 Mon Sep 17 00:00:00 2001 From: Chen Junda Date: Mon, 26 Aug 2024 18:40:47 +0800 Subject: [PATCH] update --- .changeset/young-meals-raise.md | 5 +++++ libs/web/src/layouts/base/header/index.tsx | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .changeset/young-meals-raise.md diff --git a/.changeset/young-meals-raise.md b/.changeset/young-meals-raise.md new file mode 100644 index 0000000000..4e4ffa30b3 --- /dev/null +++ b/.changeset/young-meals-raise.md @@ -0,0 +1,5 @@ +--- +"@scow/lib-web": patch +--- + +UI 扩展当导航栏链接请求失败时,返回上一次请求的结果 diff --git a/libs/web/src/layouts/base/header/index.tsx b/libs/web/src/layouts/base/header/index.tsx index 625e884201..bc540934d3 100644 --- a/libs/web/src/layouts/base/header/index.tsx +++ b/libs/web/src/layouts/base/header/index.tsx @@ -13,7 +13,7 @@ import { LinkOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from "@ant-design/icons"; import { Space } from "antd"; import { join } from "path"; -import React, { useCallback, useState } from "react"; +import React, { useCallback, useRef, useState } from "react"; import { useAsync } from "react-async"; import { ExtensionRouteQuery, isUrl } from "src/extensions/common"; import { NavbarLink, navbarLinksRoute } from "src/extensions/navbarLinks"; @@ -221,15 +221,22 @@ interface FetcherProps { const NavbarLinkFetcher = ({ extension, from, routeQuery, onDataFetched }: FetcherProps) => { + const lastResultRef = useRef(undefined); + const { reload } = useAsync({ promiseFn: useCallback(async () => { const resp = await callExtensionRoute(navbarLinksRoute(from), routeQuery, {}, extension.url) + .then((resp) => { + const result = resp[200]?.navbarLinks; + lastResultRef.current = result; + return result; + }) .catch((e) => { console.warn(`Failed to call navbarLinks of extension ${extension.name ?? extension.url}. Error: `, e); - return { 200: { navbarLinks: [] as NavbarLink[] } }; + return lastResultRef.current; }); - const data = resp[200]?.navbarLinks?.map((x) => { + const data = resp?.map((x) => { if (!isUrl(x.path)) { const parts = ["/extensions"];