Parcourir la source

比赛进行中无法提交预测

charles_c il y a 5 mois
Parent
commit
67f19ef7c2
2 fichiers modifiés avec 55 ajouts et 13 suppressions
  1. 2 2
      src/app/api/match/route.js
  2. 53 11
      src/app/ui/MatchPrediction.jsx

+ 2 - 2
src/app/api/match/route.js

@@ -95,7 +95,7 @@ export async function GET(request) {
         // 查询未来的未开始比赛
         const futureMatches = await Match.find({
           date: { $gte: currentDate.toDate() },
-          status: "未开始",
+          status: { $in: ["未开始", "进行中"] },
         }).sort("date");
 
         // 使用原有的 formatMatches 函数格式化比赛
@@ -119,7 +119,7 @@ export async function GET(request) {
 
         const matches = await Match.find({
           date: { $gte: startDate, $lte: endDate },
-          status: "未开始",
+          status: { $in: ["未开始", "进行中"] },
         }).sort({ time: 1 });
 
         response = NextResponse.json({ success: true, data: matches });

+ 53 - 11
src/app/ui/MatchPrediction.jsx

@@ -89,7 +89,11 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
     selectedFirstTeamToScoreOfMatch,
   ]);
 
-  const incrementGoal = (matchId, whoWillWin, totalGoals) => {
+  const incrementGoal = (matchId, whoWillWin, totalGoals, matchStatus) => {
+    if (matchStatus === "进行中") {
+      setAlert({ type: "error", message: "比赛已开始,无法提交预测" });
+      return;
+    }
     setSelectedMatchId(matchId);
     if (!selectedWinTeams[matchId] && whoWillWin == null) {
       setAlert({ type: "error", message: "请先选择球队" });
@@ -112,7 +116,11 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
     }, 1000);
   };
 
-  const decrementGoal = (matchId, whoWillWin, totalGoals) => {
+  const decrementGoal = (matchId, whoWillWin, totalGoals, matchStatus) => {
+    if (matchStatus === "进行中") {
+      setAlert({ type: "error", message: "比赛已开始,无法提交预测" });
+      return;
+    }
     setSelectedMatchId(matchId);
     if (!selectedWinTeams[matchId] && whoWillWin == null) {
       setAlert({ type: "error", message: "请先选择球队" });
@@ -135,7 +143,11 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
   };
 
   // 选择who wins
-  const handleWinTeamSelect = (matchId, selectedTeam) => {
+  const handleWinTeamSelect = (matchId, selectedTeam, matchStatus) => {
+    if (matchStatus === "进行中") {
+      setAlert({ type: "error", message: "比赛已开始,无法提交预测" });
+      return;
+    }
     console.log("selectedWhoWinTeam", matchId, selectedTeam);
     setSelectedMatchId(matchId);
     setSelectedWinTeams((prevState) => ({
@@ -159,6 +171,10 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
   // 打开 FirstScoreTeam 选择框
   const openSelectFirstTeamModal = (match, whoWillWin, firstTeamToScore) => {
     console.log("match", match);
+    if (match.status === "进行中") {
+      setAlert({ type: "error", message: "比赛已开始,无法提交预测" });
+      return;
+    }
     const matchId = match._id;
     console.log("whoWillWin", whoWillWin);
     console.log("matchId", matchId);
@@ -178,7 +194,6 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
   // 提交预测
   const handleSubmitPredictions = async () => {
     console.log(
-      333,
       totalGoalCountOfMatch,
       selectedWinTeams,
       selectedFirstTeamToScoreOfMatch
@@ -269,8 +284,19 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
               <div className="flex justify-between items-center bg-blue-800 text-white py-2 px-4 rounded-lg">
                 <span className="text-sm">{formattedDate}</span>
                 <div className="flex items-center">
-                  <Clock className="w-5 h-5 mr-1" />
-                  <span className="font-bold text-lg">{match.time}</span>
+                  {match.status === "未开始" ? (
+                    <>
+                      <Clock className="w-5 h-5 mr-1" />
+                      <span className="font-bold text-lg">{match.time}</span>
+                    </>
+                  ) : match.status === "进行中" ? (
+                    <div className="flex items-center">
+                      <span className="w-2 h-2 bg-green-400 rounded-full mr-2 animate-pulse"></span>
+                      <span className="text-gray-200">进行中</span>
+                    </div>
+                  ) : (
+                    <span className="text-gray-200">{match.status}</span>
+                  )}
                 </div>
               </div>
 
@@ -292,13 +318,17 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
                         ? "home" == selectedWinTeams[match._id]
                         : "home" == whoWillWin
                     }
-                    onClick={() => handleWinTeamSelect(match._id, "home")}
+                    onClick={() =>
+                      handleWinTeamSelect(match._id, "home", match.status)
+                    }
                   />
                 </div>
 
                 <div
                   className="flex flex-col items-center  flex-1 pt-2 bg-[hsla(0,0%,100%,0.1)] rounded-md relative"
-                  onClick={() => handleWinTeamSelect(match._id, "draw")}
+                  onClick={() =>
+                    handleWinTeamSelect(match._id, "draw", match.status)
+                  }
                 >
                   <div className="w-10 h-10 mb-2">
                     <img
@@ -343,7 +373,9 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
                         ? "away" == selectedWinTeams[match._id]
                         : "away" == whoWillWin
                     }
-                    onClick={() => handleWinTeamSelect(match._id, "away")}
+                    onClick={() =>
+                      handleWinTeamSelect(match._id, "away", match.status)
+                    }
                   />
                 </div>
               </div>
@@ -409,7 +441,12 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
                       <button
                         className="bg-red-500 w-6 h-6 rounded-full flex items-center justify-center"
                         onClick={() =>
-                          decrementGoal(match._id, whoWillWin, totalGoals)
+                          decrementGoal(
+                            match._id,
+                            whoWillWin,
+                            totalGoals,
+                            match.status
+                          )
                         }
                       >
                         <Minus size={20} />
@@ -423,7 +460,12 @@ const MatchPrediction = ({ selectedDayMatches, currentUser }) => {
                     <button
                       className="bg-red-500 w-6 h-6 rounded-full flex items-center justify-center"
                       onClick={() =>
-                        incrementGoal(match._id, whoWillWin, totalGoals)
+                        incrementGoal(
+                          match._id,
+                          whoWillWin,
+                          totalGoals,
+                          match.status
+                        )
                       }
                     >
                       <Plus size={20} />