Skip to content

Commit

Permalink
FIX-파일첨부-url-변경 (#79)
Browse files Browse the repository at this point in the history
* Fix : 새로운 Axios 인스턴스 사용

* Refactor : 쿼리 enable 옵션 추가

* Refactor : 쿼리 enable 옵션 추가

* Minor : 스타일 변경
  • Loading branch information
jobkaeHenry authored Dec 9, 2023
1 parent 52ee665 commit 76f00b2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions client/src/components/newpost/SearchAlcoholInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface SearchAlcoholInputInterface {
}
const SearchAlcoholInput = ({ setAlcoholNo }: SearchAlcoholInputInterface) => {
// 유저가 검색한 키워드
const [searchKeyword, setSearchKeyword] = useState("");
const [searchKeyword, setSearchKeyword] = useState<string>();
// 검색한 키워드의 Debounced 값
const debouncedValue = useDebounce(searchKeyword, 300);
const [isSearchingAlcohol, setIsSearchingAlCohol] = useState(false);
Expand All @@ -36,7 +36,7 @@ const SearchAlcoholInput = ({ setAlcoholNo }: SearchAlcoholInputInterface) => {
useState<AlcoholDetailInterface>();

useEffect(() => {
setSearchKeyword(selectedAlcohol?.alcoholName ?? "");
setSearchKeyword(selectedAlcohol?.alcoholName);
setAlcoholNo(selectedAlcohol?.alcoholNo);
}, [selectedAlcohol]);

Expand Down Expand Up @@ -68,7 +68,7 @@ const SearchAlcoholInput = ({ setAlcoholNo }: SearchAlcoholInputInterface) => {
autoComplete="off"
/>
{/* FIXME List 컴포넌트로 분리 */}
{isSearchingAlcohol && (
{isSearchingAlcohol && data && (
<Box sx={WrapperStyle}>
<List sx={ListStyle}>
{isSuccess &&
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/wiki/AlcoholPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Pagination, Stack } from "@mui/material";
import usePushToWikiDetail from "@/hooks/wiki/usePushToWikiDetail";

const AlcoholPagenation = () => {
const { data: alcohols } = useGetAlcoholListQuery();
const { data: alcohols } = useGetAlcoholListQuery("");
const onClickElementHandler = usePushToWikiDetail();
return (
<Stack alignItems="center" gap={2}>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/wiki/WikiAlcoholSelectorBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const WikiAlcoholSelectorBtn = ({
>
{iconComponent}
</Stack>
<Typography sx={{ p: 1 }}>{title}</Typography>
<Typography sx={{ py: 1 }}>{title}</Typography>
</Stack>
</ButtonBase>
);
Expand Down
6 changes: 2 additions & 4 deletions client/src/queries/alcohol/useGetAlcoholListQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ const useGetAlcoholListQuery = (keyword?: string) => {
return useQuery({
queryKey: AlcohilListQueryKey.byKeyword(keyword),
queryFn: async () => await getAlcoholListByKeyword(keyword),
enabled: keyword!=undefined,
});
};

export const getAlcoholListByKeyword = async (keyword?: string) => {
if (keyword === "") {
return { list: [], totalCount: 0 };
}
const { data } = await axios.get<{
list: AlcoholDetailInterface[];
totalCount: number;
Expand All @@ -23,7 +21,7 @@ export const getAlcoholListByKeyword = async (keyword?: string) => {
size: 5,
searchKeyword: keyword,
},
});
});
return data;
};

Expand Down
7 changes: 4 additions & 3 deletions client/src/queries/attach/useNewAttachMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { getPostListInfiniteQueryKey } from "./../post/useGetPostListInfiniteQue
import { postDetailQueryKey } from "../post/useGetPostDetailQuery";
import { MyInfoQueryKeys } from "../auth/useMyInfoQuery";
import { UserInfoQueryKey } from "../user/useUserInfoQuery";
import useAxiosPrivate from "@/hooks/useAxiosPrivate";
import { ImageSize } from "@/types/attach/attachInterface";
import axios from "axios";
import getTokenFromLocalStorage from "@/utils/getTokenFromLocalStorage";

export const useNewAttachMutation = () => {
const errorHandler = useErrorHandler();
Expand Down Expand Up @@ -64,17 +65,17 @@ export const postImageFn = async (
{ type, pk }: NewAttatchRequestUrl,
size?: ImageSize
) => {
const axiosPrivate = useAxiosPrivate();
const formData = new FormData();
formData.append("image", file);

const { data } = await axiosPrivate.post<{ attachNo: number }>(
const { data } = await axios.post<{ attachNo: number }>(
ATTACH_FILE(type, pk),
formData,
{
params: size,
headers: {
"Content-Type": "multipart/form-data",
Authorization: getTokenFromLocalStorage(),
},
transformRequest: [
function () {
Expand Down
6 changes: 1 addition & 5 deletions client/src/queries/auth/useMyInfoQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ export const useMyInfoQuery = () => {
throw Error();
}
},
enabled: !!getTokenFromLocalStorage(),
});
};

export const getMyInfoByLocalStorage = async () => {
const accessToken = getTokenFromLocalStorage();

if (!accessToken) {
return null;
}
const axiosPrivate = useAxiosPrivate();
const { data } = await axiosPrivate.get<MyInfoInterface>(MY_INFO);
return data;
Expand Down

0 comments on commit 76f00b2

Please sign in to comment.