Skip to content
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
18 changes: 12 additions & 6 deletions app/components/odd-even-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface BetSummaryResponseDto {
};
myBet: { betType: 'odd' | 'even'; betAmount: number } | null;
resultType: 'odd' | 'even' | null;
userGameResults?: string[][];
}

interface OddEvenGameModalProps {
Expand Down Expand Up @@ -69,6 +70,7 @@ export default function OddEvenGameModal({
betAmount: number;
} | null>(null);
const [timeLeft, setTimeLeft] = useState(0);
const [userGameResults, setUserGameResults] = useState<string[][]>([]);

const previousPoolRef = useRef<{ oddTotal: number; evenTotal: number }>({
oddTotal: 0,
Expand Down Expand Up @@ -172,16 +174,19 @@ export default function OddEvenGameModal({
if (gamePhase !== 'betting') {
setSelectedSide(data.myBet?.betType ?? null);
}
if (data.userGameResults) {
setUserGameResults(data.userGameResults);
}
}
} catch (error) {
console.error(error);
alert('게임 데이터를 불러오는 중 오류가 발생했습니다.');
}
}, [username, initialized]);

useEffect(() => {
if (gamePhase === 'result') {
fetchGameData();
fetchUserPoints();
}
}, [gamePhase, fetchGameData]);

Expand All @@ -206,7 +211,7 @@ export default function OddEvenGameModal({
} else if (minutes === 50 && seconds < 30) {
setTimeLeft(30 - seconds);
setGamePhase('rolling'); // 결과 계산 중
} else {
} else if (minutes === 50 && seconds >= 30) {
setTimeLeft(nextRoundStartSeconds);
setGamePhase('result'); // 결과 보여주고 다음 라운드까지 대기
fetchGameData();
Expand Down Expand Up @@ -307,7 +312,9 @@ export default function OddEvenGameModal({
<span>🎲 홀짝 게임</span>
<Dice2 className="w-8 h-8 text-red-400" />
</div>
<span className="text-yellow-400">결과 적중시 포인트 2배!</span>
<span className="text-yellow-400">
배팅은 기술! 이기면 상대 포인트도 나눠가져요 😎
</span>
<Button
variant="ghost"
onClick={onClose}
Expand All @@ -324,17 +331,16 @@ export default function OddEvenGameModal({
<CardContent className="p-4 flex justify-between items-center">
<div className="flex space-x-6">
<div className="text-center">
<div className="text-[28px] font-bold text-yellow-400 leading-none h-[40px] w-[80px] font-mono text-center">
<div className="text-[28px] font-bold text-yellow-400 leading-none h-[40px] w-[80px] text-center">
{displayTimeValue}

<div className="text-xs font-semibold text-gray-300 mt-1 whitespace-nowrap text-center">
{displayTimeText}
</div>
</div>
</div>
<div className="text-center">
<div className="text-yellow-400 font-bold">내 포인트</div>
<div className="text-2xl font-bold text-white">
<div className="text-xl font-bold text-white h-[40px] w-[80px]">
{userPoints.toLocaleString()}P
</div>
</div>
Expand Down
39 changes: 31 additions & 8 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TrendingUp,
TrendingDown,
Crown,
AwardIcon,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
Expand All @@ -25,11 +26,14 @@ import TodayNotice from './components/TodayNotice';
import RankingCard from './components/RankingCard';
import Navbar from './components/Navbar';

const baseURL = process.env.NEXT_PUBLIC_API_BASE_URL;

export default function CoteHouse() {
const [currentTime, setCurrentTime] = useState(new Date());
const [userPoints, setUserPoints] = useState(15420);
const [selectedTab, setSelectedTab] = useState('전체');
const [isOddEvenModalOpen, setIsOddEvenModalOpen] = useState(false);
const [username, setUsername] = useState<string | null>(null);

interface Problem {
id: number;
Expand All @@ -40,15 +44,20 @@ export default function CoteHouse() {
}

const [problemsState, setProblemsState] = useState<Problem[]>([]);
const username = 'leehk_py';
// const userId = '6658f86789d4af26695f8910'

const { user, logout, isAuthenticated } = useAuth();

useEffect(() => {
const saved = localStorage.getItem("username") || null;
setUsername(saved);
}, []);

useEffect(() => {
const fetchData = async () => {
try {
const today = new Date().toISOString().slice(0, 10);
const problemRes = await axios.get(`http://localhost:8080/api/admin/problem/${today}`);
const problemRes = await axios.get(`${baseURL}/admin/problem/${today}`);
const problemList = problemRes.data.data;
console.log(problemList)

Expand All @@ -60,7 +69,10 @@ export default function CoteHouse() {
checked: false,
}));

const solvedRes = await axios.get(`http://localhost:8080/users/${username}/solved`);
const storageUsername = localStorage.getItem("username");
setUsername(storageUsername);

const solvedRes = await axios.get(`${baseURL}/users/${storageUsername}/solved`);
const solvedIds: string[] = solvedRes.data;

const updated = problems.map((problem: Problem) =>
Expand All @@ -81,30 +93,41 @@ export default function CoteHouse() {

const handleProblemCheckClick = async (problemId: number) => {
try {
const response = await axios.get('http://localhost:8080/solvedCheck/check', {
const response = await axios.get(`${baseURL}/solvedCheck/check`, {
params: {
user: username,
problem: problemId,
},
});

const result = response.data;
const point = problemsState.find((p) => p.id === problemId)?.points ?? 0;
if (result === true) {
// 문제 점수 찾아서 delta 설정
const delta = problemsState.find((p) => p.id === problemId)?.points ?? 0;
const delta = point;

// 1. solved 기록 등록
await axios.post(`http://localhost:8080/users/${username}/solved/${problemId}`);
await axios.post(`${baseURL}/users/${username}/solved/${problemId}`);

// 2. 포인트 증가 요청
const userScoreRequestData = {
username: username,
delta: delta,
};

await axios.patch('http://localhost:8080/api/admin/points', userScoreRequestData);
await axios.patch(`${baseURL}/admin/points`, userScoreRequestData);

// 3. history 업데이트
const historyRequestData = {
username: username,
type: '문제해결',
amount: point,
reason: `문제 ${problemId}번 풀어서 적립`,
}

const res = await axios.post(`${baseURL}/history/add`, historyRequestData);

// 3. 상태 업데이트
// 4. 상태 업데이트
const updated = problemsState.map((problem) =>
problem.id === problemId ? { ...problem, checked: true } : problem
);
Expand Down
Loading
Loading