Skip to content

Commit

Permalink
fix: Search
Browse files Browse the repository at this point in the history
  • Loading branch information
ybgbob committed Nov 17, 2023
1 parent b150f1e commit a79b01e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import React from 'react';
import { Detail } from './pages/Detail';
import { Redirect } from './pages/Redirect';

export interface IRoute {
children?: Array<IRoute>;
Expand Down Expand Up @@ -57,6 +58,10 @@ const routes: Array<IRoute> = [
path: '/detail',
element: <Detail></Detail>,
},
{
path: '/redirect',
element: <Redirect />,
},
{
path: '/folder',
element: <Folder></Folder>,
Expand Down
22 changes: 12 additions & 10 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { SearchInput } from './SearchInput';

import styled from '@emotion/styled';
import { Box, Flex } from '@totejs/uikit';
import ScrollSelect from './ScrollSelect';
import { useDebounce } from '../hooks/useDebounce';
import { searchKey } from '../utils/gfSDK';
import { parseGroupName } from '../utils';
import { searchKey } from '../utils/gfSDK';
import ScrollSelect from './ScrollSelect';
// import { multiCallFun } from '../base/contract/multiCall';
// import { MarketPlaceContract } from '../base/contract/marketPlaceContract';
import Web3 from 'web3';
Expand Down Expand Up @@ -64,6 +64,7 @@ const Search = (props: ISearch) => {
return reg.test(name);
}
});
// console.log('searchList', groups);
if (groups.length) {
const res = await Promise.all(
groups.map((item: any) => {
Expand All @@ -82,13 +83,14 @@ const Search = (props: ISearch) => {
// }),
// );
const list: any = groups
.map((item: string, index: number) => {
const { price } = res[index];
if (price.length > 1) {
return Object.assign(item, { price });
}
return false;
})
// .map((item: string, index: number) => {
// const { price } = res[index];
// console.log(res, price);
// // if (price.length > 1) {
// // return Object.assign(item, { price });
// // }
// return false;
// })
.filter((item: any) => !!item);

setList(list);
Expand All @@ -110,7 +112,7 @@ const Search = (props: ISearch) => {
const {
group: { group_name, id, owner },
} = item;
return `resource?gid=${id}&gn=${group_name}&address=${owner}&tab=dataList`;
return `/redirect?gid=${id}`;
};
const filteredData = useMemo(() => {
if (searchValue) {
Expand Down
13 changes: 13 additions & 0 deletions src/hooks/useGetItemByGroupId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useQuery } from '@tanstack/react-query';
import { getItemByGroupId } from '../utils/apis';

export const useGetItemByGroupId = (groupId: string) => {
return useQuery({
enabled: !!groupId,
queryKey: ['GET_ITEM_BY_GROUP_ID'],
queryFn: async () => {
return await getItemByGroupId(groupId);
},
staleTime: 10000,
});
};
32 changes: 32 additions & 0 deletions src/pages/Redirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Box } from '@totejs/uikit';
import { Loader } from '../components/Loader';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useGetItemByGroupId } from '../hooks/useGetItemByGroupId';
import { NoData } from '../components/NoData';
import { useEffect } from 'react';

export const Redirect = () => {
const [p] = useSearchParams();
const groupId = p.get('gid') as string;

const navigator = useNavigate();
const { data: itemInfo, isLoading } = useGetItemByGroupId(groupId);

useEffect(() => {
navigator(`/resource?id=${itemInfo.id}`, {
replace: true,
});
}, [itemInfo.id, navigator]);

if (isLoading) {
return <Loader />;
}

if (!itemInfo) return <NoData />;

return (
<Box>
<Loader />
</Box>
);
};

0 comments on commit a79b01e

Please sign in to comment.