Skip to content

Commit

Permalink
chore: update files
Browse files Browse the repository at this point in the history
  • Loading branch information
haru52 committed Jun 15, 2024
1 parent a8cb2ec commit a29dea9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/_components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function findDefinedAvatar(
avatars: AvatarWithSocial[],
currentSocialId: number,
) {
if (avatars.length === 0) throw new Error("avatars is empty");
const avatar = avatars.find((a) => a.social.id === currentSocialId);
if (avatar === undefined) throw new Error("avatar is undefined");

Expand All @@ -29,8 +30,19 @@ export function Home({
user: User;
avatars: AvatarWithSocial[];
}) {
if (avatars.length < 1) throw new Error("avatars is empty");
const router = useRouter();
const [currentSocialId, setCurrentSocialId] = useState(user.currentSocialId);
const initialCurrentSocialId = (() => {
if (user.currentSocialId !== null) return user.currentSocialId;
const socials = avatars.map((a) => a.social);
const social = socials.reduce((a, b) =>
a.screenName < b.screenName ? a : b,
);
return social.id;
})();
const [currentSocialId, setCurrentSocialId] = useState(
initialCurrentSocialId,
);
if (currentSocialId === null) throw new Error("currentSocialId is null");
const { mutate: userUpdateMutate } = api.user.update.useMutation({
onSuccess: () => {
Expand Down

0 comments on commit a29dea9

Please sign in to comment.