Skip to content

Commit

Permalink
fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
hikahana committed Nov 14, 2024
1 parent 93c4a34 commit dce8c36
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
59 changes: 40 additions & 19 deletions app/src/app/camera/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";

import { Answered } from "@/components/Answered";
import { AssignmentBadge } from "@/components/AssignmentBadge";
import {
AlertDialog,
AlertDialogAction,
Expand All @@ -13,19 +15,17 @@ import {
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Toaster } from "@/components/ui/sonner";
import { shapeCaption } from "@/functions/shapeCaption";
import { postSimilarity } from "@/functions/simirality";
import type { todayAssignment } from "@/types";
import type React from "react";
import { useEffect, useRef, useState } from "react";
import { Camera, type CameraType } from "react-camera-pro";
import { toast } from "sonner";
import AddImageIcon from "../../../public/icons/icon-add-image.svg";
import RotateCameraIcon from "../../../public/icons/icon-rotate-camera.svg";
import ShutterIcon from "../../../public/icons/icon-shutter.svg";
import { toast } from "sonner";
import { Toaster } from "@/components/ui/sonner";
import { todayAssignment } from "@/types";
import { Answered } from "@/components/Answered";
import { AssignmentBadge } from "@/components/AssignmentBadge";

interface ImagePreviewProps {
image: string | null;
Expand Down Expand Up @@ -100,9 +100,13 @@ const CameraApp = () => {
const [tempImage, setTempImage] = useState<string | null>(null);
const camera = useRef<CameraType>(null);
const [devices, setDevices] = useState<MediaDeviceInfo[]>([]);
const [activeDeviceId, setActiveDeviceId] = useState<string | undefined>(undefined);
const [activeDeviceId, setActiveDeviceId] = useState<string | undefined>(
undefined,
);
const [currentDeviceIndex, setCurrentDeviceIndex] = useState<number>(0);
const [todayAssignment, setTodayAssignment] = useState<todayAssignment | undefined>();
const [todayAssignment, setTodayAssignment] = useState<
todayAssignment | undefined
>();
const [assignments, setAssignments] = useState<todayAssignment[]>([]);
const [isActive, setIsActive] = useState<boolean>(true);

Expand All @@ -114,7 +118,9 @@ const CameraApp = () => {
return;
}
const userInfo = JSON.parse(user);
const resAssignment = await fetch(`/api/assignment/today?uid=${userInfo?.uid}`);
const resAssignment = await fetch(
`/api/assignment/today?uid=${userInfo?.uid}`,
);
const assignmentData = await resAssignment.json();

if (assignmentData.length === 0) {
Expand Down Expand Up @@ -143,7 +149,9 @@ const CameraApp = () => {

try {
const devices = await navigator.mediaDevices.enumerateDevices();
const videoDevices = devices.filter((device) => device.kind === "videoinput");
const videoDevices = devices.filter(
(device) => device.kind === "videoinput",
);
setDevices(videoDevices);
if (videoDevices.length > 0) {
setActiveDeviceId(videoDevices[0].deviceId);
Expand Down Expand Up @@ -185,7 +193,9 @@ const CameraApp = () => {
// ランダム文字列を生成する関数
const generateRandomString = (charCount = 7): string => {
const str = Math.random().toString(36).substring(2).slice(-charCount);
return str.length < charCount ? str + "a".repeat(charCount - str.length) : str;
return str.length < charCount
? str + "a".repeat(charCount - str.length)
: str;
};

const randomStr = generateRandomString();
Expand All @@ -209,7 +219,9 @@ const CameraApp = () => {
}
};

const getCaption = async (imageName: string): Promise<{ caption: string }> => {
const getCaption = async (
imageName: string,
): Promise<{ caption: string }> => {
try {
const response = await fetch(`/api/image?imageName=${imageName}`);
if (!response.ok) {
Expand Down Expand Up @@ -318,8 +330,6 @@ const CameraApp = () => {
if (newAssignments.every((assignment) => assignment.isAnswered)) {
setIsActive(false);
}


} catch (error) {
setIsUploading(false);
console.error("アップロード中にエラーが発生しました:", error);
Expand All @@ -334,7 +344,9 @@ const CameraApp = () => {

const handleImageCapture = (capturedImage: string | ImageData) => {
const imageStr =
capturedImage instanceof ImageData ? imageDataToBase64(capturedImage) : capturedImage;
capturedImage instanceof ImageData
? imageDataToBase64(capturedImage)
: capturedImage;

setTempImage(imageStr);
setShowConfirmDialog(true);
Expand Down Expand Up @@ -409,10 +421,15 @@ const CameraApp = () => {
</Button>
</div>

<AlertDialog open={showConfirmDialog} onOpenChange={setShowConfirmDialog}>
<AlertDialog
open={showConfirmDialog}
onOpenChange={setShowConfirmDialog}
>
<AlertDialogContent className="w-5/6 rounded-lg">
<AlertDialogHeader>
<AlertDialogTitle className="text-center">画像のアップロード確認</AlertDialogTitle>
<AlertDialogTitle className="text-center">
画像のアップロード確認
</AlertDialogTitle>
<AlertDialogDescription className="text-center">
この画像をアップロードしてもよろしいですか?
</AlertDialogDescription>
Expand All @@ -421,8 +438,12 @@ const CameraApp = () => {
<DialogImagePreview image={tempImage} />

<AlertDialogFooter className="sm:space-x-4">
<AlertDialogCancel onClick={handleCancel}>いいえ</AlertDialogCancel>
<AlertDialogAction onClick={handleConfirm}>はい</AlertDialogAction>
<AlertDialogCancel onClick={handleCancel}>
いいえ
</AlertDialogCancel>
<AlertDialogAction onClick={handleConfirm}>
はい
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
Expand All @@ -437,7 +458,7 @@ const CameraApp = () => {
)}
</>
) : (
<Answered assignments={assignments}/>
<Answered assignments={assignments} />
)}
</>
);
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/Answered.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { todayAssignment } from "@/types";
import type { todayAssignment } from "@/types";

interface AssignmentProps {
assignments: todayAssignment[];
}

export const Answered = ({ assignments }: AssignmentProps) => {
// 本日は回答済みですの画面表示
const isNoAssignmentToday = assignments.length === 0
const isNoAssignmentToday = assignments.length === 0;

return (
<div className="flex flex-col items-center justify-center text-center fixed top-0 left-0 w-full h-full">
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/AssignmentBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { todayAssignment } from "@/types";
import type { todayAssignment } from "@/types";

interface AssignmentBadgeProps {
assignment: todayAssignment;
Expand Down

0 comments on commit dce8c36

Please sign in to comment.