Skip to content

Commit

Permalink
Merge pull request #47 from capstone-maru/feat/shared-api
Browse files Browse the repository at this point in the history
feat: Shared API 일부 적용
  • Loading branch information
cjeongmin authored Apr 4, 2024
2 parents a9d6626 + 720588b commit 4aef317
Show file tree
Hide file tree
Showing 44 changed files with 452 additions and 227 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"tsx": "never"
}
],
"no-empty-pattern": ["warn", { "allowObjectPatternsAsParameters": true }],
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-empty-function": ["warn", {}],
Expand Down
2 changes: 2 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
// reactStrictMode: false,
reactStrictMode: true,
compiler: {
styledComponents: true,
},
Expand Down
15 changes: 4 additions & 11 deletions src/app/pages/main-page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use client';

import { useQuery } from '@tanstack/react-query';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useEffect, useRef, useState } from 'react';
import styled from 'styled-components';

import { CircularButton } from '@/components';
import { UserCard } from '@/components/main-page';
import { getUserData, useAuthActions, useAuthValue } from '@/features/auth';
import { useAuthActions, useAuthValue, useUserData } from '@/features/auth';

const styles = {
container: styled.div`
Expand Down Expand Up @@ -67,11 +66,7 @@ export function MainPage() {
const auth = useAuthValue();
const { setAuthUserData } = useAuthActions();

const { data } = useQuery({
queryKey: ['/api/auth/initial/info'],
queryFn: getUserData,
enabled: auth?.refreshToken !== null,
});
const { data } = useUserData(auth?.accessToken !== undefined);

const [, setMap] = useState<naver.maps.Map | null>(null);

Expand Down Expand Up @@ -102,10 +97,8 @@ export function MainPage() {

useEffect(() => {
if (data !== undefined) {
const userData = data.data;

setAuthUserData(userData);
if (userData.initialized) {
setAuthUserData(data);
if (data.initialized) {
// router.replace('/profile');
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/pages/shared-post-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
ImageGrid,
MiniCircularProfileImage,
} from '@/components/shared-post-page';
import { type SharedPost } from '@/entities/shared-post';

const styles = {
container: styled.div`
Expand Down Expand Up @@ -350,7 +349,7 @@ const dummyParticipants = [
];

interface Props {
post: SharedPost;
post: { title: string; content: string };
}

function Item({ label, data }: { label: string; data: string }) {
Expand Down
61 changes: 23 additions & 38 deletions src/app/pages/shared-posts.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import { useQuery } from '@tanstack/react-query';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
Expand All @@ -14,8 +13,8 @@ import {
PostCard,
} from '@/components/shared-posts';
import { type SharedPostsType } from '@/entities/shared-posts-filter';
import { getUserData, useAuthActions, useAuthValue } from '@/features/auth';
import { usePaging } from '@/features/shared';
import { useAuthActions, useAuthValue, useUserData } from '@/features/auth';
import { usePaging, useSharedPosts } from '@/features/shared';

const styles = {
container: styled.div`
Expand Down Expand Up @@ -114,44 +113,43 @@ export function SharedPostsPage() {

const auth = useAuthValue();
const [selected, setSelected] = useState<SharedPostsType>('hasRoom');
const [totalPageCount, setTotalPageCount] = useState(0);
const { setAuthUserData } = useAuthActions();

const { data } = useQuery({
queryKey: ['/api/auth/initial/info'],
queryFn: getUserData,
enabled: auth?.refreshToken !== null,
});
const { data: userData } = useUserData(auth?.accessToken !== undefined);

const {
page,
maxPostPage,
sliceSize,
currentSlice,
isFirstPage,
isLastPage,
handleNextPage,
handlePrevPage,
} = usePaging({
maxPostPage: 12,
totalPages: totalPageCount,
sliceSize: 10,
});

const { data: sharedPosts } = useSharedPosts({
enabled: auth?.accessToken !== undefined && selected === 'hasRoom',
page: page - 1,
});

useEffect(() => {
if (data !== undefined) {
const userData = data.data;
if (sharedPosts !== undefined) {
setTotalPageCount(sharedPosts.data.totalPages);
}
}, [sharedPosts]);

useEffect(() => {
if (userData !== undefined) {
setAuthUserData(userData);
if (userData.initialized) {
// router.replace('/profile');
}
}
}, [data, router, setAuthUserData]);

useEffect(() => {
if (data?.data.initialized === true) {
// router.replace('/profile');
}
}, [data, router]);
}, [userData, router, setAuthUserData]);

return (
<styles.container>
Expand All @@ -165,24 +163,11 @@ export function SharedPostsPage() {
</Link>
</styles.createButtonRow>
<styles.posts>
<Link href="/shared/1">
<PostCard />
</Link>
<Link href="/shared/1">
<PostCard />
</Link>
<Link href="/shared/1">
<PostCard />
</Link>
<Link href="/shared/1">
<PostCard />
</Link>
<Link href="/shared/1">
<PostCard />
</Link>
<Link href="/shared/1">
<PostCard />
</Link>
{sharedPosts?.data.content.map(post => (
<Link key={post.id} href={`/shared/${post.id}`}>
<PostCard />
</Link>
))}
</styles.posts>
<styles.pagingRow>
<styles.CircularButton
Expand All @@ -193,7 +178,7 @@ export function SharedPostsPage() {
<styles.paging>
{Array.from({
length: Math.min(
maxPostPage - currentSlice * sliceSize,
totalPageCount - currentSlice * sliceSize,
sliceSize,
),
}).map((_, index) => (
Expand Down
11 changes: 3 additions & 8 deletions src/components/NavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import { useQuery } from '@tanstack/react-query';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import styled from 'styled-components';
Expand All @@ -9,10 +8,10 @@ import { SearchBox } from './SearchBox';

import {
getAuthLogout,
getUserData,
useAuthActions,
useAuthIsLogin,
useAuthValue,
useUserData,
} from '@/features/auth';
import { load } from '@/shared/storage';

Expand Down Expand Up @@ -76,11 +75,7 @@ export function NavigationBar() {
const auth = useAuthValue();
const { logout } = useAuthActions();

const { data } = useQuery({
queryKey: ['/api/auth/initial/info'],
queryFn: getUserData,
enabled: auth?.refreshToken !== null,
});
const { data } = useUserData(auth?.accessToken !== undefined);

const handleLogout = () => {
const refreshToken = load<string>({ type: 'local', key: 'refreshToken' });
Expand All @@ -107,7 +102,7 @@ export function NavigationBar() {
<styles.links>
<Link href="/shared">메이트찾기</Link>
<Link href="/community">커뮤니티</Link>
<Link href={`/profile/${data?.data.memberId}`}>마이페이지</Link>
<Link href={`/profile/${data?.memberId}`}>마이페이지</Link>
{isLogin && (
<styles.logout
onClick={() => {
Expand Down
6 changes: 0 additions & 6 deletions src/entities/address/address.model.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/address/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/entities/follow/follow.model.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/follow/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/member-account/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/entities/member-account/member-account.model.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/member-card/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/entities/member-card/member-card.model.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/room-image/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/entities/room-image/room-image.model.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/room-info/index.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/entities/room-info/room-info.model.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/shared-post/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/entities/shared-post/shared-post.model.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/entities/shared-posts-filter/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './shared-posts-filter.model';
export * from './shared-posts-filter.type';
export * from './shared-posts-filter.hook';
1 change: 0 additions & 1 deletion src/entities/shared-room-post/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/entities/shared-room-post/shared-room-post.model.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/studio-room-post/index.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/entities/studio-room-post/studio-room-post.model.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/entities/user/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type { User } from './user.model';
export type { User } from './user.type';
File renamed without changes.
48 changes: 0 additions & 48 deletions src/features/auth/auth.action.ts

This file was deleted.

Loading

0 comments on commit 4aef317

Please sign in to comment.