-
Notifications
You must be signed in to change notification settings - Fork 1
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
8 changed files
with
284 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { useQuery, UseQueryResult } from "@tanstack/react-query"; | ||
|
||
import { StoredSearchRequest } from "@/interface/profile"; | ||
import { Page } from "@/interface/search"; | ||
import { AiResponseData } from "@/interface/searchDetail"; | ||
|
||
import { API_KEY } from "./constants"; | ||
|
||
/** @TODO api 아직 안나옴! */ | ||
const getStoredLaws = async ({ | ||
type, | ||
page, | ||
size, | ||
}: StoredSearchRequest): Promise<AiResponseData[]> => { | ||
/** @TODO api 아직 안나옴! */ | ||
// }: StoredSearchRequest): Promise<Page<GetLawsResponseType<typeof type>>> => { | ||
|
||
const response: AiResponseData[] = JSON.parse( | ||
localStorage.getItem(`stored-${type}`) ?? | ||
JSON.stringify([] as AiResponseData[]), | ||
); | ||
|
||
return new Promise((res) => { | ||
setTimeout(() => { | ||
res(response); | ||
}, 100); | ||
}); | ||
// const url = `/laws/${type}?q=${q}&page=${page}&take=${size}`; | ||
// const response: Page<GetLawsResponseType<typeof type>> | undefined = | ||
// await http.get(url); | ||
// const newList = response?.list.map((l) => ({ ...l, type })); | ||
// return { ...response, list: newList } as Page< | ||
// GetLawsResponseType<typeof type> | ||
// >; | ||
}; | ||
|
||
const useGetStoredLaws = ({ | ||
type, | ||
page, | ||
size, | ||
}: StoredSearchRequest): UseQueryResult< | ||
// Page<AiResponseData> | ||
AiResponseData[] | ||
> => { | ||
return useQuery( | ||
[API_KEY.STORED_LAWS, { type, page, size }], | ||
() => getStoredLaws({ type, page, size }), | ||
{ suspense: true }, | ||
); | ||
}; | ||
|
||
export default useGetStoredLaws; |
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,42 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { AiResponseData, StoreDetailRequest } from "@/interface/searchDetail"; | ||
|
||
import { API_KEY } from "./constants"; | ||
|
||
const putStoredLaws = async ({ | ||
type, | ||
actionType, | ||
content, | ||
}: StoreDetailRequest) => { | ||
/** @TODO api 안나옴 */ | ||
const curArr: AiResponseData[] = JSON.parse( | ||
localStorage.getItem(`stored-${type}`) ?? | ||
JSON.stringify([] as AiResponseData[]), | ||
); | ||
if (content === undefined) { | ||
// do nothing | ||
} else if (actionType === "add") { | ||
const newArr = [...curArr, content]; | ||
localStorage.setItem(`stored-${type}`, JSON.stringify(newArr)); | ||
} else if (actionType === "delete") { | ||
// 일단 냅두자 | ||
} | ||
|
||
return new Promise((res) => { | ||
setTimeout(() => { | ||
res({ success: true }); | ||
}, 100); | ||
}); | ||
}; | ||
|
||
const usePutStoredLaws = () => { | ||
const queryClient = useQueryClient(); | ||
return useMutation(putStoredLaws, { | ||
onSuccess: () => { | ||
queryClient.invalidateQueries([API_KEY.STORED_LAWS]); | ||
}, | ||
}); | ||
}; | ||
|
||
export default usePutStoredLaws; |
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,20 @@ | ||
import { ReactElement } from "react"; | ||
|
||
const SavedIcon = (): ReactElement => { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="18" | ||
height="20" | ||
viewBox="0 0 18 20" | ||
fill="#fff" | ||
> | ||
<path | ||
d="M0.981323 1C0.981323 0.447715 1.42904 0 1.98132 0H16.9813C17.5336 0 17.9813 0.447715 17.9813 1V19C17.9813 19.3648 17.7826 19.7007 17.4629 19.8764C17.1431 20.0521 16.753 20.0397 16.4451 19.8441L9.48132 15.42L2.51756 19.8441C2.2096 20.0397 1.81954 20.0521 1.49978 19.8764C1.18002 19.7007 0.981323 19.3648 0.981323 19V1Z" | ||
fill="white" | ||
/> | ||
</svg> | ||
); | ||
}; | ||
|
||
export default SavedIcon; |
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