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

Feature/#1566 비크루 권한 처리 및 조회수 API 추가 #1567

Merged
merged 3 commits into from
Oct 6, 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
4 changes: 4 additions & 0 deletions frontend/src/apis/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ export const requestGetFilteredArticle = (course: string, bookmark: boolean) =>
export const requestPutArticleLike = ({ articleId, like }: ArticleLikePutRequest) => {
return client.put(`/articles/${articleId}/like`, { like });
};

export const requestPostArticleView = (articleId: number) => {
return client.post(`/articles/${articleId}/views`);
};
4 changes: 3 additions & 1 deletion frontend/src/components/Article/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ArticleType } from '../../models/Article';
import Scrap from '../Reaction/Scrap';
import { useRef, useState } from 'react';
import {
usePostArticleViewsMutation,
usePutArticleBookmarkMutation,
usePutArticleLikeMutation,
} from '../../hooks/queries/article';
Expand All @@ -25,6 +26,7 @@ const Article = ({
const [like, setLike] = useState(isLiked);
const { mutate: putBookmark } = usePutArticleBookmarkMutation();
const { mutate: putLike } = usePutArticleLikeMutation();
const { mutate: postViews } = usePostArticleViewsMutation();

const toggleBookmark: React.MouseEventHandler<HTMLButtonElement> = (e) => {
e.preventDefault();
Expand All @@ -49,7 +51,7 @@ const Article = ({
};

return (
<Styled.Container>
<Styled.Container onClick={() => postViews(id)}>
<Styled.Anchor href={url} target="_blank" rel="noopener noreferrer">
<Styled.ThumbnailWrapper>
<Styled.Thumbnail src={imageUrl} />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/contexts/UserProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const DEFAULT_USER = {
userId: null,
username: null,
nickname: null,
role: null,
role: '',
imageUrl: null,
accessToken: null,
isLoggedIn: false,
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/hooks/queries/article.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMutation, useQuery, useQueryClient } from 'react-query';
import {
requestGetFilteredArticle,
requestPostArticleView,
requestPostArticles,
requestPutArticleBookmark,
requestPutArticleLike,
Expand Down Expand Up @@ -48,3 +49,7 @@ export const usePutArticleLikeMutation = () => {
onError: () => {},
});
};

export const usePostArticleViewsMutation = () => {
return useMutation(requestPostArticleView);
};
4 changes: 4 additions & 0 deletions frontend/src/mocks/handlers/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ export const articlesHandler = [

return res(ctx.status(200), ctx.json(filteredArticle));
}),

rest.post(`${BASE_URL}/articles/:articleId/views`, (req, res, ctx) => {
return res(ctx.status(200));
}),
];
6 changes: 4 additions & 2 deletions frontend/src/pages/ArticleListPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const ArticleListPage = () => {
const [checked, setChecked] = useState(false);

const { user } = useContext(UserContext);
const { isLoggedIn } = user;
const { isLoggedIn, role } = user;

const authorized = role === 'CREW' && isLoggedIn;

const { data: filteredArticles = [], refetch: getFilteredArticles } = useGetFilteredArticleQuery(
selectedCourse.value,
Expand Down Expand Up @@ -66,7 +68,7 @@ const ArticleListPage = () => {
<ArticleBookmarkFilter checked={checked} handleCheckBookmark={handleCheckBookmark} />
)}
</FilteringWrapper>
{isLoggedIn && (
{authorized && (
<Button
type="button"
size="X_SMALL"
Expand Down
Loading