Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT]: 북마크 title 조회 API에 memberId 추가 #231

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/bookmarks/api/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,19 @@ export const useGETCategoryListQuery = ({
type GETBookmarkTitleResponse = string;

interface GetBookmarkTitleRequest {
memberId: number;
url: string;
setTitle?: (title: string) => void;
}

const getBookmarkTitleAPI = async ({ url }: GetBookmarkTitleRequest) => {
const getBookmarkTitleAPI = async ({
memberId,
url,
}: GetBookmarkTitleRequest) => {
const { data } = await client<GETBookmarkTitleResponse>({
method: 'get',
url: '/bookmark/title',
params: { url },
url: `/members/${memberId}/bookmark/title`,
params: { memberId, url },
data: {},
});
return data;
Expand All @@ -281,20 +285,25 @@ const getBookmarkTitleAPI = async ({ url }: GetBookmarkTitleRequest) => {
const GET_BOOKMARK_TITLE = (url: string) => ['GET_BOOKMARK_TITLE', url];

export const useGETBookmarkTitleQuery = ({
memberId,
url,
setTitle,
}: GetBookmarkTitleRequest) => {
const { fireToast } = useToast();
return useQuery(GET_BOOKMARK_TITLE(url), () => getBookmarkTitleAPI({ url }), {
enabled: !!url,
retry: 0,
onSuccess: (data) => {
setTitle && setTitle(data);
},
onError: () => {
fireToast({ message: '앗! 유효하지 않은 주소에요', mode: 'DELETE' });
return useQuery(
GET_BOOKMARK_TITLE(url),
() => getBookmarkTitleAPI({ memberId, url }),
{
enabled: !!url,
retry: 0,
onSuccess: (data) => {
setTitle && setTitle(data);
},
onError: () => {
fireToast({ message: '앗! 유효하지 않은 주소에요', mode: 'DELETE' });
},
},
});
);
};

interface POSTBookmarkRequest {
Expand Down
3 changes: 3 additions & 0 deletions src/bookmarks/service/hooks/add/useInputUrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import checkValidateURL from '@/utils/checkValidateURL';
import { useEffect, useState } from 'react';
import { debounce } from 'lodash';
import useBookmarkStore from '@/store/bookmark';
import useAuthStore from '@/store/auth';

interface InputUrlProps {
defaultUrl?: string;
defaultTitle?: string;
}

const useInputUrl = ({ defaultTitle, defaultUrl }: InputUrlProps) => {
const { userInfo } = useAuthStore();
const { url, setUrl, title, setTitle } = useBookmarkStore();
const [debouncedUrl, setDebouncedUrl] = useState<string>('');

Expand Down Expand Up @@ -50,6 +52,7 @@ const useInputUrl = ({ defaultTitle, defaultUrl }: InputUrlProps) => {
};

useGETBookmarkTitleQuery({
memberId: userInfo.id,
url: checkValidateURL(debouncedUrl) ? checkValidateURL(debouncedUrl) : '',
setTitle: onChangeTitle,
});
Expand Down
Loading