-
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.
- Loading branch information
Showing
7 changed files
with
136 additions
and
60 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,38 +1,40 @@ | ||
// import { FRONTEND_URL } from '@/shared/core/envs'; | ||
// import { mwGET } from '@/shared/utils/mw-get'; | ||
|
||
// import { pillarItemsResponseDtoSchema } from '@/search/core/schemas'; | ||
// import { GetPillarItemsProps } from '@/search/core/types'; | ||
|
||
// export const getPillarItems = async (props: GetPillarItemsProps): Promise<string[]> => { | ||
// const { nav, pillar, query, page = 1, limit = 20 } = props; | ||
|
||
// const url = new URL(`${FRONTEND_URL}/search/pillar-items`); | ||
// const searchParams = new URLSearchParams({ | ||
// nav, | ||
// pillar, | ||
// query, | ||
// page: `${page}`, | ||
// limit: `${limit}`, | ||
// }); | ||
// url.search = searchParams.toString(); | ||
|
||
// const response = await mwGET({ | ||
// url: url.toString(), | ||
// label: 'getPillarItems', | ||
// responseSchema: pillarItemsResponseDtoSchema, | ||
// }); | ||
|
||
// return response.data; | ||
// }; | ||
import { MW_URL } from '@/shared/core/envs'; | ||
import { mwGET } from '@/shared/utils/mw-get'; | ||
|
||
import { pillarItemsResponseDtoSchema } from '@/search/core/schemas'; | ||
import { GetPillarItemsProps } from '@/search/core/types'; | ||
|
||
import { fakePillarItems } from '@/search/testutils/fake-pillar-items'; | ||
|
||
export const getPillarItems = async ( | ||
_props: GetPillarItemsProps, | ||
props: GetPillarItemsProps, | ||
): Promise<string[]> => { | ||
await new Promise((r) => setTimeout(r, 500)); | ||
return fakePillarItems(); | ||
const { nav, pillar, query, page = 1, limit = 20 } = props; | ||
|
||
const url = new URL(`${MW_URL}/search/pillar/items`); | ||
const searchParams = new URLSearchParams({ | ||
nav, | ||
pillar, | ||
page: `${page}`, | ||
limit: `${limit}`, | ||
}); | ||
if (query) searchParams.set('query', query); | ||
url.search = searchParams.toString(); | ||
|
||
const response = await mwGET({ | ||
url: url.toString(), | ||
label: 'getPillarItems', | ||
responseSchema: pillarItemsResponseDtoSchema, | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
// import { GetPillarItemsProps } from '@/search/core/types'; | ||
|
||
// import { fakePillarItems } from '@/search/testutils/fake-pillar-items'; | ||
|
||
// export const getPillarItems = async ( | ||
// _props: GetPillarItemsProps, | ||
// ): Promise<string[]> => { | ||
// await new Promise((r) => setTimeout(r, 500)); | ||
// return fakePillarItems(); | ||
// }; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
export const useDebouncedValue = <T>(value: T, delay: number): T => { | ||
const [debouncedValue, setDebouncedValue] = useState<T>(value); | ||
|
||
useEffect(() => { | ||
const timeoutId = setTimeout(() => { | ||
setDebouncedValue(value); | ||
}, delay); | ||
|
||
return () => { | ||
clearTimeout(timeoutId); | ||
}; | ||
}, [value, delay]); | ||
|
||
return debouncedValue; | ||
}; |