Skip to content

Commit

Permalink
feat: 24시즌
Browse files Browse the repository at this point in the history
  • Loading branch information
innerstella committed Mar 23, 2024
1 parent fe1e468 commit beffbcc
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 95 deletions.
6 changes: 3 additions & 3 deletions build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"files": {
"main.css": "/static/css/main.1434f441.css",
"main.js": "/static/js/main.a20a7f46.js",
"main.js": "/static/js/main.4704456d.js",
"static/js/787.7cb63699.chunk.js": "/static/js/787.7cb63699.chunk.js",
"index.html": "/index.html",
"main.1434f441.css.map": "/static/css/main.1434f441.css.map",
"main.a20a7f46.js.map": "/static/js/main.a20a7f46.js.map",
"main.4704456d.js.map": "/static/js/main.4704456d.js.map",
"787.7cb63699.chunk.js.map": "/static/js/787.7cb63699.chunk.js.map"
},
"entrypoints": [
"static/css/main.1434f441.css",
"static/js/main.a20a7f46.js"
"static/js/main.4704456d.js"
]
}
2 changes: 1 addition & 1 deletion build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><meta property="og:title" content="직관일기"/><meta property="og:url" content="https://happybaseball-diary.web.app/"/><meta property="og:image" content="https://github.com/innerstella/happybaseball-diary/blob/main/public/assets/png/opengraph.png?raw=true"/><meta property="og:description" content="⚾️ 나의 직관 승률은?"/><meta name="twitter:card" content="summary_large_image"/><meta name="twitter:title" content="직관일기"/><meta name="twitter:description" content="⚾️ 나의 직관 승률은?"/><meta name="twitter:image" content="https://github.com/innerstella/happybaseball-diary/blob/main/public/assets/png/opengraph.png?raw=true"/><title>직관일기</title><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0"/><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0"/><script defer="defer" src="/static/js/main.a20a7f46.js"></script><link href="/static/css/main.1434f441.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body><script type="text/javascript" src="//wcs.naver.net/wcslog.js"></script><script type="text/javascript">if(!wcs_add)var wcs_add={};wcs_add.wa="1d106f0c7b05040",window.wcs&&wcs_do()</script></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><meta property="og:title" content="직관일기"/><meta property="og:url" content="https://happybaseball-diary.web.app/"/><meta property="og:image" content="https://github.com/innerstella/happybaseball-diary/blob/main/public/assets/png/opengraph.png?raw=true"/><meta property="og:description" content="⚾️ 나의 직관 승률은?"/><meta name="twitter:card" content="summary_large_image"/><meta name="twitter:title" content="직관일기"/><meta name="twitter:description" content="⚾️ 나의 직관 승률은?"/><meta name="twitter:image" content="https://github.com/innerstella/happybaseball-diary/blob/main/public/assets/png/opengraph.png?raw=true"/><title>직관일기</title><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0"/><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0"/><script defer="defer" src="/static/js/main.4704456d.js"></script><link href="/static/css/main.1434f441.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body><script type="text/javascript" src="//wcs.naver.net/wcslog.js"></script><script type="text/javascript">if(!wcs_add)var wcs_add={};wcs_add.wa="1d106f0c7b05040",window.wcs&&wcs_do()</script></html>
3 changes: 3 additions & 0 deletions build/static/js/main.4704456d.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/static/js/main.4704456d.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions build/static/js/main.a20a7f46.js

This file was deleted.

1 change: 0 additions & 1 deletion build/static/js/main.a20a7f46.js.map

This file was deleted.

25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"react-scripts": "5.0.1",
"recoil": "^0.7.7",
"styled-components": "^6.0.7",
"swiper": "^10.3.1",
"typescript": "^4.9.5",
Expand Down
5 changes: 4 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import "./App.css";
import AppRouter from "./Router";

import { ChakraProvider } from "@chakra-ui/react";
import { RecoilRoot } from "recoil";

function App() {
return (
<ChakraProvider>
<AppRouter />
<RecoilRoot>
<AppRouter />
</RecoilRoot>
</ChakraProvider>
);
}
Expand Down
1 change: 0 additions & 1 deletion src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BrowserRouter, Route, Routes } from "react-router-dom";
import LotteryPage from "./pages/lottery";
import HomePage from "./pages/home";
import CreatePage from "./pages/create/Create";
import LoginPage from "./pages/login";
Expand Down
11 changes: 11 additions & 0 deletions src/atom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { atom } from "recoil";

export const winningRate23State = atom({
key: "winningRate23State",
default: "0.000",
});

export const winningRate24State = atom({
key: "winningRate24State",
default: "0.000",
});
39 changes: 28 additions & 11 deletions src/pages/home/components/RecordList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { dbService } from "../../../firebase";
// ui
import { Spinner } from "@chakra-ui/react";
import FirstRecord from "./FirstRecord";
import { useRecoilState } from "recoil";
import { winningRate23State } from "../../../atom";
import { winningRate24State } from "../../../atom";

const RecordList = () => {
const [isLoading, setIsLoading] = useState(true);
Expand Down Expand Up @@ -41,20 +44,34 @@ const RecordList = () => {
}, []);

// 승률 계산
const [odds, setOdds] = useState("");
const [winningRate23, setWinningRate23] = useRecoilState(winningRate23State);
const [winningRate24, setWinningRate24] = useRecoilState(winningRate24State);

useEffect(() => {
let sum = 0;
let num = 0;
let season24 = [0, 0]; // sum, cnt
let season23 = [0, 0];

userData.forEach((data) => {
sum += data.count;
num++;
if (data.date.slice(0, 2) === "24") {
season24[0] += data.count;
season24[1]++;
} else if (data.date.slice(0, 2) === "23") {
season23[0] += data.count;
season23[1]++;
}
});
let div = (sum / num).toFixed(3);
setOdds(div);

let div24 = (season24[0] / season24[1]).toFixed(3);
let div23 = (season23[0] / season23[1]).toFixed(3);

if (div24 !== "NaN") {
setWinningRate24(div24);
}
if (div23 !== "NaN") {
setWinningRate23(div23);
}
}, [userData]);

console.log(userData, odds, isLoading);
return (
<Container>
{isLoading ? (
Expand All @@ -65,13 +82,13 @@ const RecordList = () => {
emptyColor="gray.200"
color="#464646"
size="xl"
/>{" "}
/>
</div>
) : (
<>
{userData.length > 0 ? (
<>
{odds === "NaN" ? (
{winningRate23 === "NaN" ? (
<div className="padding">
<Spinner
thickness="4px"
Expand All @@ -83,7 +100,7 @@ const RecordList = () => {
</div>
) : (
<>
<p className="text">🏆 {odds}</p>
<p className="text">🏆 {winningRate24}</p>
{userData.map((data, id) => {
return (
<Record
Expand Down
3 changes: 0 additions & 3 deletions src/pages/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { styled } from "styled-components";
import TopAppBar from "../../components/TopAppBar";
import Button from "../home/components/CreateButton";
import { signInGoogle } from "../../firebase";
import { useNavigate } from "react-router-dom";
// import { GoogleAuthProvider } from "firebase/auth";

const LoginPage = () => {
const login = () => {
Expand All @@ -24,7 +22,6 @@ const LoginPage = () => {
export default LoginPage;

const MainContainer = styled.div`
/* width: 100vw; */
height: 100vh;
padding-bottom: 10rem;
background-color: #fafafa;
Expand Down
83 changes: 12 additions & 71 deletions src/pages/mypage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,16 @@
import { styled } from "styled-components";
import { useRecoilValue } from "recoil";

import { winningRate23State, winningRate24State } from "../../atom";

import TopAppBar from "../../components/TopAppBar";
import OddBox from "./components/OddBox";
import { useEffect, useState } from "react";
import Banner from "../../components/Banner";
import { collection, getDocs } from "firebase/firestore";
import { dbService } from "../../firebase";
import Lottery from "../lottery/components/Lottery";

const MyPage = () => {
// 유저 정보
const uid = sessionStorage.getItem("uid");
const [userData, setUserData] = useState<any[]>([]);
let newUserData: any[] = [];

useEffect(() => {
if (uid) {
const docRef = collection(dbService, uid);
getDocs(docRef)
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
newUserData.push(doc.data());
});

newUserData.sort((a, b) => {
return b.realDate - a.realDate;
});

// 이전 userData 배열과 새로운 데이터를 병합
setUserData((prev) => [...prev, ...newUserData]);
})
.catch((error) => {
console.error("Error getting documents: ", error);
});
}
}, []);

// 승률 계산
const [odds23, setOdds23] = useState("");
const [odds22, setOdds22] = useState("");

useEffect(() => {
let sum = 0,
num = 0;
userData.forEach((data) => {
let yr = +data.date.slice(0, 2);
if (yr === 23) {
sum += data.count;
num++;
}
});
let div = (sum / num).toFixed(3);
setOdds23(div);
}, [userData]);

useEffect(() => {
let sum = 0;
let num = 0;
userData.forEach((data) => {
let yr = +data.date.slice(0, 2);
if (yr === 22) {
sum += data.count;
num++;
}
});
let div = (sum / num).toFixed(3);
setOdds22(div);
}, [userData]);
const winningRate23 = useRecoilValue(winningRate23State);
const winningRate24 = useRecoilValue(winningRate24State);

return (
<MainContainer>
Expand All @@ -74,27 +19,23 @@ const MyPage = () => {
<Banner />
</div>
<Odds>
<p className="title">23 시즌</p>
{odds23 === "NaN" ? (
<p className="title">24 시즌</p>
{winningRate24 === "NaN" ? (
<OddBox ratio="0.000" />
) : (
<OddBox ratio={odds23} />
<OddBox ratio={winningRate24} />
)}
</Odds>
<Odds>
<p className="title">22 시즌</p>
{odds22 === "NaN" ? (
<p className="title">23 시즌</p>
{winningRate23 === "NaN" ? (
<OddBox ratio="0.000" />
) : (
<OddBox ratio={odds22} />
<OddBox ratio={winningRate23} />
)}
</Odds>
<div className="gap"></div>
<Lottery />
{/* <Odds>
<p className="title">팀별</p>
<OddBox ratio="0.555" />
</Odds> */}
</MainContainer>
);
};
Expand Down

0 comments on commit beffbcc

Please sign in to comment.