-
Notifications
You must be signed in to change notification settings - Fork 1
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
WIPフォロー・フォロワー一覧 #391
Open
AyumuAkimoto
wants to merge
9
commits into
main
Choose a base branch
from
feature/isues351
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
WIPフォロー・フォロワー一覧 #391
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2d6e421
save
AyumuAkimoto e79def5
ざっくりレイアウト確認
AyumuAkimoto dd3be0c
フォロー一覧表示
takecchi 78cb878
アカウント情報の取り込み成功
AyumuAkimoto 7c8190c
作業保存
AyumuAkimoto 7cac4db
作業保存
AyumuAkimoto a617623
作業保存
AyumuAkimoto 0209cc8
Props修正
takecchi 53fdaf2
レイアウト微修正
AyumuAkimoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/app/(menu)/(public)/[username]/_components/Following.tsx
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,14 @@ | ||
'use client'; | ||
|
||
import FollowList from '@/app/(menu)/(public)/[username]/_components/layouts/FollowList'; | ||
import { useFollowing } from '@/swr/client/follows'; | ||
import { UserWithFollows } from '@cuculus/cuculus-api'; | ||
|
||
/** | ||
* フォロー一覧表示コンポーネント | ||
* @param user | ||
* @constructor | ||
*/ | ||
export default function Following({ user }: { user: UserWithFollows }) { | ||
return <FollowList follows={useFollowing(user.id)} />; | ||
} |
112 changes: 112 additions & 0 deletions
112
src/app/(menu)/(public)/[username]/_components/layouts/FFProfileCard.tsx
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,112 @@ | ||
'use client'; | ||
import FollowButton from '@/app/(menu)/(public)/[username]/_components/elements/FollowButton'; | ||
import UserIcon from '@/app/(menu)/(public)/[username]/_components/elements/UserIcon'; | ||
import { UserWithFollows } from '@cuculus/cuculus-api'; | ||
import { Box, Typography, styled } from '@mui/material'; | ||
|
||
const UnselectableCard = styled('div')` | ||
border-bottom: 1px solid ${({ theme }) => theme.palette.grey[100]}; | ||
background-color: ${({ theme }) => theme.palette.background.paper}; | ||
color: rgba(0, 0, 0, 0.87); | ||
`; | ||
|
||
const Flex = styled(Box)` | ||
display: flex; | ||
flex-wrap: nowrap; | ||
`; | ||
|
||
const VFlex = styled(Flex)` | ||
flex-direction: column; | ||
`; | ||
|
||
const HFlex = styled(Flex)` | ||
flex-direction: row; | ||
`; | ||
|
||
const HFlexS = styled(Flex)` | ||
flex-direction: row; | ||
justify-content: space-between; | ||
`; | ||
|
||
const FillFlex = styled(Box)` | ||
flex-grow: 1; | ||
`; | ||
|
||
const DisplayName = styled(Typography)` | ||
word-wrap: break-word; | ||
font-weight: bold; | ||
font-size: 20px; | ||
`; | ||
|
||
const ButtonArea = styled(Box)` | ||
hight: 20px; | ||
`; | ||
|
||
const UserName = styled(Typography)` | ||
color: #8899a6; | ||
font-size: 15px; | ||
`; | ||
|
||
const Avater = styled(UserIcon)` | ||
aspect-ratio: 1; | ||
height: 64px; | ||
width: 64px; | ||
margin: auto 10px; | ||
margin-top: 0; | ||
|
||
${({ theme }) => theme.breakpoints.down('desktop')} { | ||
margin: auto 10px; | ||
margin-top: 0; | ||
height: 64px; | ||
width: 64px; | ||
} | ||
`; | ||
|
||
const Bio = styled(Typography)` | ||
white-space: pre-wrap; | ||
margin-bottom: 12px; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
display: -webkit-box; | ||
-webkit-line-clamp: 2; | ||
-webkit-box-orient: vertical; | ||
`; | ||
|
||
type Props = { | ||
name: string; | ||
username: string; | ||
profileImageUrl: string; | ||
bio: string; | ||
} & UserWithFollows; | ||
|
||
export default function FFProfileCard({ | ||
name, | ||
username, | ||
profileImageUrl, | ||
bio, | ||
id, | ||
}: Props) { | ||
return ( | ||
<UnselectableCard> | ||
<HFlex> | ||
<Avater src={profileImageUrl} alt={'プロフィール画像'} /> | ||
<VFlex style={{ margin: '12px 0' }}> | ||
<HFlexS> | ||
<VFlex> | ||
<DisplayName>{name}</DisplayName> | ||
<UserName>@{username}</UserName> | ||
</VFlex> | ||
{/* フォローされてるか表示 */} | ||
{/* <FollowedDisplay/> */} | ||
<ButtonArea> | ||
<FollowButton userId={id} /> | ||
</ButtonArea> | ||
</HFlexS> | ||
<FillFlex> | ||
<Bio>{bio}</Bio> | ||
</FillFlex> | ||
</VFlex> | ||
</HFlex> | ||
</UnselectableCard> | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
src/app/(menu)/(public)/[username]/_components/layouts/FollowList.tsx
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,52 @@ | ||
import { SWRInfiniteResponse } from 'swr/infinite'; | ||
import { FollowList } from '@cuculus/cuculus-api'; | ||
import { CircularProgress } from '@mui/material'; | ||
import FFProfileCard from '@/app/(menu)/(public)/[username]/_components/layouts/FFProfileCard'; | ||
|
||
type Props = { | ||
follows: SWRInfiniteResponse<FollowList | undefined, Error>; | ||
}; | ||
|
||
/** | ||
* フォロー/フォロワーリスト | ||
* @param follows | ||
* @constructor | ||
*/ | ||
export default function FollowList({ follows }: Props) { | ||
const { data, isLoading, size, setSize } = follows; | ||
|
||
if (isLoading) { | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<CircularProgress /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<div>現在のページ: {size}</div> | ||
<button onClick={() => void setSize(size + 1)}>次のページへ</button> | ||
{data?.map((follows, index) => ( | ||
<div key={index}> | ||
{follows?.users.map((User, number) => ( | ||
<FFProfileCard | ||
Check failure on line 39 in src/app/(menu)/(public)/[username]/_components/layouts/FollowList.tsx
|
||
key={number} | ||
name={User.name} | ||
username={User.username} | ||
bio={User.bio} | ||
profileImageUrl={User.profileImageUrl} | ||
id={User.id} | ||
/> | ||
))} | ||
</div> | ||
))} | ||
</> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,40 @@ | ||
import ComingSoon from '@/app/(menu)/_components/main/ComingSoon'; | ||
import PrimaryColumn from '@/app/(menu)/_components/main/PrimaryColumn'; | ||
import { cache } from 'react'; | ||
import { usersApi } from '@/libs/cuculus-client'; | ||
import { notFound } from 'next/navigation'; | ||
import Following from '@/app/(menu)/(public)/[username]/_components/Following'; | ||
|
||
type Params = { params: { username: string } }; | ||
|
||
const getUser = cache(async (username: string) => { | ||
try { | ||
return await usersApi.getUserByUsername( | ||
{ username }, | ||
{ | ||
next: { | ||
revalidate: 300, | ||
}, | ||
}, | ||
); | ||
} catch { | ||
return undefined; | ||
} | ||
}); | ||
|
||
/** | ||
* フォロワー一覧ページ | ||
* @param params | ||
*/ | ||
export default async function page({ params }: Params) { | ||
const username = decodeURIComponent(params.username); | ||
const user = await getUser(username); | ||
if (!user) { | ||
notFound(); | ||
} | ||
|
||
export default function page({}: { params: { userName: string } }) { | ||
return ( | ||
<PrimaryColumn hideHeader={true}> | ||
<ComingSoon /> | ||
{/* <Following user={user} /> */} | ||
</PrimaryColumn> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,40 @@ | ||
import ComingSoon from '@/app/(menu)/_components/main/ComingSoon'; | ||
import PrimaryColumn from '@/app/(menu)/_components/main/PrimaryColumn'; | ||
import { cache } from 'react'; | ||
import { usersApi } from '@/libs/cuculus-client'; | ||
import { notFound } from 'next/navigation'; | ||
import Following from '@/app/(menu)/(public)/[username]/_components/Following'; | ||
|
||
type Params = { params: { username: string } }; | ||
|
||
const getUser = cache(async (username: string) => { | ||
try { | ||
return await usersApi.getUserByUsername( | ||
{ username }, | ||
{ | ||
next: { | ||
revalidate: 300, | ||
}, | ||
}, | ||
); | ||
} catch { | ||
return undefined; | ||
} | ||
}); | ||
|
||
/** | ||
* フォロー一覧ページ | ||
* @param params | ||
*/ | ||
export default async function page({ params }: Params) { | ||
const username = decodeURIComponent(params.username); | ||
const user = await getUser(username); | ||
if (!user) { | ||
notFound(); | ||
} | ||
|
||
export default function page({}: { params: { userName: string } }) { | ||
return ( | ||
<PrimaryColumn hideHeader={true}> | ||
<ComingSoon /> | ||
<Following user={user} /> | ||
</PrimaryColumn> | ||
); | ||
} |
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 @@ | ||
import { useAuth } from '@/swr/client/auth'; | ||
import { usersApi } from '@/libs/cuculus-client'; | ||
import { getAuthorizationHeader } from '@/libs/auth'; | ||
import useSWRInfinite from 'swr/infinite'; | ||
import { FollowList } from '@cuculus/cuculus-api'; | ||
|
||
// FIXME 確認用に一旦10件にしている | ||
const LIMIT = 10; | ||
|
||
type SWRKey = { | ||
key: string; | ||
authId?: number; | ||
userId: number; | ||
nextUntil?: Date; | ||
}; | ||
|
||
/** | ||
* フォロー一覧の取得 | ||
* @param userId | ||
*/ | ||
export const useFollowing = (userId: number) => { | ||
const { data: authId } = useAuth(); | ||
return useSWRInfinite< | ||
FollowList | undefined, | ||
Error, | ||
(index: number, prev: FollowList | undefined) => SWRKey | null | ||
>( | ||
(index, previousPageData) => { | ||
// 取得結果が空の場合は次のページがないと判断して終了 | ||
if (previousPageData && !previousPageData.users.length) { | ||
return null; | ||
} | ||
return { | ||
key: 'useFollowing', | ||
authId, | ||
userId, | ||
nextUntil: previousPageData?.nextUntil, | ||
}; | ||
}, | ||
async (args) => { | ||
try { | ||
return await usersApi.getUserFollowing( | ||
{ id: args.userId, until: args.nextUntil, limit: LIMIT }, | ||
{ | ||
headers: await getAuthorizationHeader(authId), | ||
}, | ||
); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}, | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo!