-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: restore hidden-item implementation for pillar-info and drop…
…down
- Loading branch information
Showing
8 changed files
with
150 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { atom } from 'jotai'; | ||
|
||
import { TPillarItemMap } from '@/search/core/types'; | ||
|
||
export const searchQueryAtom = atom<string>(''); | ||
export const hiddenMainPillarItemsAtom = atom<TPillarItemMap>(new Map()); | ||
export const hiddenAltPillarItemsAtom = atom<TPillarItemMap>(new Map()); | ||
|
||
type TPillarItemMap = Record<string, string[]>; | ||
export const hiddenPillarItemsAtom = atom<TPillarItemMap>({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,46 @@ | ||
// import { MW_URL } from '@/shared/core/envs'; | ||
// import { mwGET } from '@/shared/utils/mw-get'; | ||
|
||
// import { | ||
// dtoToPillarInfo, | ||
// pillarInfoResponseSchema, | ||
// TPillarInfo, | ||
// } from '@/search/core/schemas'; | ||
// import { GetPillarInfoProps } from '@/search/core/types'; | ||
|
||
// export const getPillarInfo = async ( | ||
// props: GetPillarInfoProps, | ||
// ): Promise<TPillarInfo> => { | ||
// const { nav, pillar, item, pillar2, item2, limit } = props; | ||
import { MW_URL } from '@/shared/core/envs'; | ||
import { mwGET } from '@/shared/utils/mw-get'; | ||
|
||
import { | ||
dtoToPillarInfo, | ||
pillarInfoResponseSchema, | ||
TPillarInfo, | ||
} from '@/search/core/schemas'; | ||
import { GetPillarInfoProps } from '@/search/core/types'; | ||
|
||
// const url = new URL(`${MW_URL}/search/pillar`); | ||
// url.searchParams.set('nav', nav); | ||
// url.searchParams.set('pillar', pillar); | ||
// url.searchParams.set('item', item); | ||
export const getPillarInfo = async ( | ||
props: GetPillarInfoProps, | ||
): Promise<TPillarInfo> => { | ||
const { nav, pillar, item, limit } = props; | ||
|
||
// if (typeof pillar2 === 'string' && typeof item2 === 'string') { | ||
// url.searchParams.set('pillar2', pillar2); | ||
// url.searchParams.set('item2', item2); | ||
// } | ||
const url = new URL(`${MW_URL}/search/pillar`); | ||
url.searchParams.set('nav', nav); | ||
url.searchParams.set('pillar', pillar); | ||
url.searchParams.set('item', item); | ||
|
||
// if (limit) url.searchParams.set('limit', limit.toString()); | ||
if (limit) url.searchParams.set('limit', limit.toString()); | ||
|
||
// const response = await mwGET({ | ||
// url: url.toString(), | ||
// label: 'getPillarInfo', | ||
// responseSchema: pillarInfoResponseSchema, | ||
// }); | ||
const response = await mwGET({ | ||
url: url.toString(), | ||
label: 'getPillarInfo', | ||
responseSchema: pillarInfoResponseSchema, | ||
}); | ||
|
||
// if (!response.success) { | ||
// throw new Error(response.message); | ||
// } | ||
if (!response.success) { | ||
throw new Error(response.message); | ||
} | ||
|
||
// return dtoToPillarInfo(response.data); | ||
// }; | ||
return dtoToPillarInfo(response.data); | ||
}; | ||
|
||
import { TPillarInfo } from '@/search/core/schemas'; | ||
import { GetPillarInfoProps } from '@/search/core/types'; | ||
// import { TPillarInfo } from '@/search/core/schemas'; | ||
// import { GetPillarInfoProps } from '@/search/core/types'; | ||
|
||
import { fakePillarInfo } from '@/search/testutils/fake-pillar-info'; | ||
// import { fakePillarInfo } from '@/search/testutils/fake-pillar-info'; | ||
|
||
export const getPillarInfo = async ( | ||
props: GetPillarInfoProps, | ||
): Promise<TPillarInfo> => { | ||
await new Promise((r) => setTimeout(r, 500)); | ||
return fakePillarInfo(props.limit); | ||
}; | ||
// export const getPillarInfo = async ( | ||
// props: GetPillarInfoProps, | ||
// ): Promise<TPillarInfo> => { | ||
// await new Promise((r) => setTimeout(r, 500)); | ||
// return fakePillarInfo(props.limit); | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createContext, useContext } from 'react'; | ||
|
||
import { TPillarItem } from '@/search/core/types'; | ||
|
||
interface PillarItemsCtx { | ||
items: TPillarItem[]; | ||
} | ||
|
||
export const PillarItemsContext = createContext<PillarItemsCtx | undefined>( | ||
undefined, | ||
); | ||
|
||
export const usePillarItemsContext = () => { | ||
const context = useContext(PillarItemsContext); | ||
|
||
if (!context) { | ||
throw new Error( | ||
'usePillarItemsContext must be used within a PillarItemsContext', | ||
); | ||
} | ||
|
||
return context; | ||
}; | ||
|
||
// NOTE: items can be a lot, and we dont want to serialize all items for every item | ||
// This provider lets us not serialize all items for every item | ||
export const PillarItemsProvider = ({ | ||
items, | ||
children, | ||
}: { | ||
items: TPillarItem[]; | ||
children: React.ReactNode; | ||
}) => { | ||
return ( | ||
<PillarItemsContext.Provider value={{ items }}> | ||
{children} | ||
</PillarItemsContext.Provider> | ||
); | ||
}; |