라우팅 추가 및 CSS 구성
- 개인 블로그 - 로또 - 여행 로고 이미지 추가 및 변경
This commit is contained in:
317
src/App.jsx
317
src/App.jsx
@@ -1,306 +1,17 @@
|
||||
// src/App.jsx
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { deleteHistory, getHistory, getLatest, recommend } from "./api";
|
||||
import React from 'react';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import Navbar from './components/Navbar';
|
||||
import './App.css';
|
||||
|
||||
function fmtKST(iso) {
|
||||
// sqlite datetime('now') -> "YYYY-MM-DD HH:MM:SS" (UTC 로 저장될 수도)
|
||||
// 그냥 표시용으로만 사용
|
||||
return iso?.replace("T", " ") ?? "";
|
||||
function App() {
|
||||
return (
|
||||
<div className="app-shell">
|
||||
<Navbar />
|
||||
<main className="site-main">
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Ball({ n }) {
|
||||
// 범위별 톤만 다르게(색 직접 지정 안 하고, hue를 계산해도 되지만 여기선 단순)
|
||||
const cls =
|
||||
n <= 10 ? "ball ball-a" : n <= 20 ? "ball ball-b" : n <= 30 ? "ball ball-c" : n <= 40 ? "ball ball-d" : "ball ball-e";
|
||||
return <span className={cls}>{n}</span>;
|
||||
}
|
||||
|
||||
function NumberRow({ nums }) {
|
||||
return (
|
||||
<div className="row numbers">
|
||||
{nums.map((n) => (
|
||||
<Ball key={n} n={n} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [latest, setLatest] = useState(null);
|
||||
|
||||
const [params, setParams] = useState({
|
||||
recent_window: 200,
|
||||
recent_weight: 2.0,
|
||||
avoid_recent_k: 5,
|
||||
});
|
||||
|
||||
const presets = useMemo(
|
||||
() => [
|
||||
{ name: "기본", recent_window: 200, recent_weight: 2.0, avoid_recent_k: 5 },
|
||||
{ name: "최근 가중↑", recent_window: 100, recent_weight: 3.0, avoid_recent_k: 10 },
|
||||
{ name: "안전(분산)", recent_window: 300, recent_weight: 1.6, avoid_recent_k: 8 },
|
||||
{ name: "공격(최근)", recent_window: 80, recent_weight: 3.5, avoid_recent_k: 12 },
|
||||
],
|
||||
[]
|
||||
);
|
||||
|
||||
const [result, setResult] = useState(null);
|
||||
const [history, setHistory] = useState([]);
|
||||
|
||||
const [loading, setLoading] = useState({ latest: false, recommend: false, history: false });
|
||||
const [error, setError] = useState("");
|
||||
|
||||
const refreshLatest = async () => {
|
||||
setLoading((s) => ({ ...s, latest: true }));
|
||||
setError("");
|
||||
try {
|
||||
const data = await getLatest();
|
||||
setLatest(data);
|
||||
} catch (e) {
|
||||
setError(e?.message ?? String(e));
|
||||
} finally {
|
||||
setLoading((s) => ({ ...s, latest: false }));
|
||||
}
|
||||
};
|
||||
|
||||
const refreshHistory = async () => {
|
||||
setLoading((s) => ({ ...s, history: true }));
|
||||
setError("");
|
||||
try {
|
||||
const data = await getHistory(30);
|
||||
setHistory(data.items ?? []);
|
||||
} catch (e) {
|
||||
setError(e?.message ?? String(e));
|
||||
} finally {
|
||||
setLoading((s) => ({ ...s, history: false }));
|
||||
}
|
||||
};
|
||||
|
||||
const onRecommend = async () => {
|
||||
setLoading((s) => ({ ...s, recommend: true }));
|
||||
setError("");
|
||||
try {
|
||||
const data = await recommend(params);
|
||||
setResult(data);
|
||||
// 추천 생성 시 DB에 저장되므로 히스토리도 바로 갱신
|
||||
await refreshHistory();
|
||||
} catch (e) {
|
||||
setError(e?.message ?? String(e));
|
||||
} finally {
|
||||
setLoading((s) => ({ ...s, recommend: false }));
|
||||
}
|
||||
};
|
||||
|
||||
const onDelete = async (id) => {
|
||||
const ok = confirm(`히스토리 #${id} 삭제할까?`);
|
||||
if (!ok) return;
|
||||
|
||||
setError("");
|
||||
try {
|
||||
await deleteHistory(id);
|
||||
setHistory((prev) => prev.filter((x) => x.id !== id));
|
||||
} catch (e) {
|
||||
setError(e?.message ?? String(e));
|
||||
}
|
||||
};
|
||||
|
||||
const copyNumbers = async (nums) => {
|
||||
const text = nums.join(", ");
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
alert(`복사됨: ${text}`);
|
||||
} catch {
|
||||
// fallback
|
||||
prompt("복사해서 사용하세요:", text);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// 첫 로드
|
||||
refreshLatest();
|
||||
refreshHistory();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
<header className="header">
|
||||
<div>
|
||||
<h1>로또 추천기</h1>
|
||||
<p className="sub">
|
||||
최신 회차 기준 추천 + 히스토리 저장/삭제
|
||||
</p>
|
||||
</div>
|
||||
<div className="headerActions">
|
||||
<button className="btn ghost" onClick={refreshLatest} disabled={loading.latest}>
|
||||
최신 불러오기
|
||||
</button>
|
||||
<button className="btn ghost" onClick={refreshHistory} disabled={loading.history}>
|
||||
히스토리 새로고침
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{error ? (
|
||||
<div className="card error">
|
||||
<div className="row between">
|
||||
<strong>에러</strong>
|
||||
<button className="btn tiny" onClick={() => setError("")}>닫기</button>
|
||||
</div>
|
||||
<pre className="pre">{error}</pre>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="grid">
|
||||
{/* LEFT */}
|
||||
<section className="card">
|
||||
<div className="row between">
|
||||
<h2>최신 회차</h2>
|
||||
{loading.latest ? <span className="pill">로딩...</span> : null}
|
||||
</div>
|
||||
|
||||
{latest ? (
|
||||
<>
|
||||
<div className="row between">
|
||||
<div className="meta">
|
||||
<div><strong>{latest.drawNo}회</strong></div>
|
||||
<div className="muted">{latest.date}</div>
|
||||
</div>
|
||||
<button className="btn" onClick={() => copyNumbers(latest.numbers)}>
|
||||
번호 복사
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<NumberRow nums={latest.numbers} />
|
||||
<div className="muted small">보너스: <strong>{latest.bonus}</strong></div>
|
||||
</>
|
||||
) : (
|
||||
<div className="muted">최신 데이터 없음</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* RIGHT */}
|
||||
<section className="card">
|
||||
<div className="row between">
|
||||
<h2>추천 생성</h2>
|
||||
{loading.recommend ? <span className="pill">계산중...</span> : null}
|
||||
</div>
|
||||
|
||||
<div className="row wrap">
|
||||
{presets.map((p) => (
|
||||
<button
|
||||
key={p.name}
|
||||
className="btn ghost"
|
||||
onClick={() => setParams({ recent_window: p.recent_window, recent_weight: p.recent_weight, avoid_recent_k: p.avoid_recent_k })}
|
||||
>
|
||||
{p.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="form">
|
||||
<label>
|
||||
recent_window <span className="muted">(최근 N회 가중)</span>
|
||||
<input
|
||||
type="number"
|
||||
min={20}
|
||||
max={1000}
|
||||
value={params.recent_window}
|
||||
onChange={(e) => setParams((s) => ({ ...s, recent_window: Number(e.target.value) }))}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
recent_weight <span className="muted">(최근 가중치)</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.1"
|
||||
min={0.5}
|
||||
max={10}
|
||||
value={params.recent_weight}
|
||||
onChange={(e) => setParams((s) => ({ ...s, recent_weight: Number(e.target.value) }))}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
avoid_recent_k <span className="muted">(최근 K회 번호 회피)</span>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
max={50}
|
||||
value={params.avoid_recent_k}
|
||||
onChange={(e) => setParams((s) => ({ ...s, avoid_recent_k: Number(e.target.value) }))}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<button className="btn primary" onClick={onRecommend} disabled={loading.recommend}>
|
||||
추천 받기
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{result ? (
|
||||
<div className="result">
|
||||
<div className="row between">
|
||||
<div>
|
||||
<div className="muted small">추천 ID: #{result.id}</div>
|
||||
<div className="muted small">기준 회차: {result.based_on_latest_draw ?? "-"}</div>
|
||||
</div>
|
||||
<button className="btn" onClick={() => copyNumbers(result.numbers)}>
|
||||
번호 복사
|
||||
</button>
|
||||
</div>
|
||||
<NumberRow nums={result.numbers} />
|
||||
|
||||
<details className="details">
|
||||
<summary>설명 보기</summary>
|
||||
<pre className="pre">{JSON.stringify(result.explain, null, 2)}</pre>
|
||||
</details>
|
||||
</div>
|
||||
) : (
|
||||
<div className="muted">아직 추천 결과 없음</div>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section className="card">
|
||||
<div className="row between">
|
||||
<h2>히스토리</h2>
|
||||
<div className="muted small">{history.length}개</div>
|
||||
</div>
|
||||
|
||||
{loading.history ? <div className="muted">불러오는 중...</div> : null}
|
||||
|
||||
{history.length === 0 ? (
|
||||
<div className="muted">저장된 히스토리가 없습니다.</div>
|
||||
) : (
|
||||
<div className="table">
|
||||
{history.map((h) => (
|
||||
<div key={h.id} className="tr">
|
||||
<div className="td">
|
||||
<div className="muted small">#{h.id}</div>
|
||||
<div className="muted small">{fmtKST(h.created_at)}</div>
|
||||
<div className="muted small">기준: {h.based_on_draw ?? "-"}</div>
|
||||
</div>
|
||||
|
||||
<div className="td grow">
|
||||
<NumberRow nums={h.numbers} />
|
||||
<div className="muted small">
|
||||
window={h.params?.recent_window}, weight={h.params?.recent_weight}, avoid_k={h.params?.avoid_recent_k}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="td actions">
|
||||
<button className="btn" onClick={() => copyNumbers(h.numbers)}>복사</button>
|
||||
<button className="btn danger" onClick={() => onDelete(h.id)}>삭제</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<footer className="footer muted small">
|
||||
backend: FastAPI / nginx proxy / DB: sqlite
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default App;
|
||||
|
||||
Reference in New Issue
Block a user