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

ユーザーデータの型変更 #66

Merged
merged 2 commits into from
Nov 15, 2024
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: 2 additions & 2 deletions app/src/app/camera/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { PointDialog } from "@/components/view/PointDialog";
import { shapeCaption } from "@/functions/shapeCaption";
import { postSimilarity } from "@/functions/simirality";
import { usePointDialogOpen } from "@/lib/atom";
import type { ScoreResponse, User, todayAssignment } from "@/types";
import type { ScoreResponse, DBUser as User, todayAssignment } from "@/types";
import imageCompression from "browser-image-compression";
import type React from "react";
import { useEffect, useRef, useState } from "react";
Expand Down Expand Up @@ -107,7 +107,7 @@ const CameraApp = () => {
console.error("ユーザー情報が取得できませんでした。");
return;
}
const userInfo = JSON.parse(user);
const userInfo: User = JSON.parse(user);
setLoginUser(userInfo);
const resAssignment = await fetch(
`/api/assignment/today?uid=${userInfo?.uid}`,
Expand Down
13 changes: 10 additions & 3 deletions app/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { Progress } from "@/components/ui/progress";
import { PointDialog } from "@/components/view/PointDialog";
import Timer from "@/components/view/Timer";
import { useHasShownOnce, usePointDialogOpen } from "@/lib/atom";
import type { MyScoreDetail, Score, todayAssignment } from "@/types";
import type {
MyScoreDetail,
Score,
DBUser as User,
todayAssignment,
} from "@/types";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
Expand Down Expand Up @@ -37,7 +42,7 @@ export default function Home() {

try {
// get api/score/me
const userData = JSON.parse(userIdString);
const userData: User = JSON.parse(userIdString);
const uid = userData.uid;
if (!uid) {
throw new Error("User ID not found");
Expand Down Expand Up @@ -111,7 +116,9 @@ export default function Home() {

const latestAssignment = assignment
.filter((item) => item.assignTime)
.sort((a, b) => (b.assignTime?.getTime() ?? 0) - (a.assignTime?.getTime() ?? 0))[0];
.sort(
(a, b) => (b.assignTime?.getTime() ?? 0) - (a.assignTime?.getTime() ?? 0),
)[0];

return (
<div className="flex flex-col min-h-screen px-10 py-10 bg-gradient-to-t from-gray-300 via-gray-200 to-gray-50">
Expand Down
8 changes: 4 additions & 4 deletions app/src/app/user/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PlayerRankCard from "@/components/view/user/PlayerRankCard";
import StatusChangeDialog from "@/components/view/user/StatusChangeDialog";
import StatusList from "@/components/view/user/StatusList";
import { useStatusChangeDialog } from "@/lib/atom";
import type { MyScoreDetail, User } from "@/types";
import type { MyScoreDetail, DBUser as User } from "@/types";
import { useEffect, useState } from "react";
import { FiEdit2 } from "react-icons/fi";
import { LuClock, LuFlame, LuTrophy } from "react-icons/lu";
Expand Down Expand Up @@ -50,9 +50,9 @@ const UserPage = () => {
return (
<div className="w-screen min-h-screen flex flex-col gap-4 items-center p-4 pt-10 bg-gradient-to-t from-gray-300 via-gray-200 to-gray-50">
<div className="flex items-center mb-4">
{userData.photoURL ? (
{userData.photoUrl ? (
<img
src={userData.photoURL}
src={userData.photoUrl}
alt="User Icon"
className="w-16 h-16 rounded-full"
/>
Expand Down Expand Up @@ -80,7 +80,7 @@ const UserPage = () => {
) : (
<>
<span className="text-xl font-bold text-[#333333]">
{userData.displayName || "[email protected]"}
{userData.name || "[email protected]"}
</span>
<Button
variant={"primary"}
Expand Down
24 changes: 11 additions & 13 deletions app/src/lib/signInAndUp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { User } from "@/types";
import type { DBUser, User } from "@/types";
import type { User as FirebaseUser } from "@firebase/auth";

const storeStorageUser = (user: User) => {
const storeStorageUser = (user: DBUser) => {
localStorage.setItem("userID", JSON.stringify(user));
};

Expand All @@ -14,22 +14,18 @@ export const signInOrUp = async (firebaseUser: FirebaseUser) => {
},
});

const user: User = {
uid: firebaseUser.uid,
displayName: firebaseUser.displayName,
email: firebaseUser.email,
photoURL: firebaseUser.photoURL,
};
const userData = await res.json();

if (res.status === 200) {
const user: DBUser = { ...userData };

if (userData) {
storeStorageUser(user);
const userData = await res.json();
if (!userData.experiencePoint) {
await createExp(userData.id);
}
toRoot();
} else {
await signUp(user);
await signUp(firebaseUser);
}
} catch (error) {
console.error("エラーが発生しました:", error);
Expand All @@ -46,8 +42,10 @@ const signUp = async (user: User) => {
body: JSON.stringify(user),
});

if (res.status === 200) {
storeStorageUser(user);
const resUser = await res.json();

if (resUser) {
storeStorageUser(resUser);
toRoot();
} else {
throw new Error("ユーザー登録に失敗");
Expand Down
Loading