Skip to content

Commit

Permalink
Merge branch 'main' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
lubomirsilny committed Apr 23, 2024
2 parents fe052ca + 4e18656 commit d68aad0
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 69 deletions.
79 changes: 37 additions & 42 deletions apps/saip-fe/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,24 @@ function App() {
const token = localStorage.getItem("token");
const currentDate = new Date();
const exp = localStorage.getItem("expiryDate");
const [tokenExpired, setTokenExpired] = useState(false)
// @ts-ignore
const exp_date = new Date(exp)
const [isLoading, setIsLoading] = useState(true);
const [comm, setComm] = useState(false);
const [connect, setConnect] = useState('')
const dataWs = useContext(MyContext);
const [data, setData] = useState({
num: null,
comm: null,
start: null
});
const [turnNum, setTurnNum] = useState(null);
useEffect(() => {
if (exp_date < currentDate){
console.log("token expired")
localStorage.removeItem("expiryDate")
localStorage.removeItem("token")

if(exp){
const exp_date = new Date(exp)
if (exp_date < currentDate){
localStorage.removeItem("token")
localStorage.removeItem("expiryDate")
console.log("token expired")
setTokenExpired(true)
}
}

}, []);
}, [token, comm]);
const { sendMessage,
sendJsonMessage,
lastMessage,
Expand All @@ -67,11 +66,8 @@ function App() {
if (e.data[0] === '{' && connect == 'yes') {
try {
const receivedData = JSON.parse(e.data);
setData({
num: receivedData.Number,
comm: receivedData.Committed,
start: receivedData.Start,
});
setTurnNum(receivedData.Number)
setComm(receivedData.Committed)
} catch (error) {
console.error('Error parsing JSON:', error);
}
Expand All @@ -80,14 +76,6 @@ function App() {

},
onClose: (event) => {
console.log(event)
// localStorage.removeItem("token");
// //setIsLoading(true)
// setData({
// num: null,
// comm: null,
// start: null
// });

},
share: true,
Expand All @@ -101,8 +89,6 @@ function App() {

const [enableArc] = useState(true);

const [, setTurn] = useAtom(currentTurn);

useEffect(() => {
document.documentElement.style.setProperty(
"--secondary",
Expand All @@ -128,19 +114,28 @@ function App() {
}, [enableArc]);

useEffect(() => {
// @ts-ignore
const savedTurn = dataWs.num
if (savedTurn && data && data.num !== parseInt(savedTurn, 10)) {
resetCompanyState();
resetUpgradeState();
resetMarketingState();
}

setTurn(data?.num || -1);
}, [data]);
resetCompanyState();
resetUpgradeState();
resetMarketingState();
}, [comm, turnNum]);
if (isLoading){
return <Spinner />;
}
if(tokenExpired){
return (
<div className="grid items-center">
<h1 className="flex justify-center mt-10">404</h1>
<h3 className="flex justify-center my-5">Váš token vypršal, prihláste sa prosím znovu!</h3>
<button
className="flex bg-accent-500 hover:bg-accent-700 text-white font-bold rounded-lg mx-40 mt-10"
type="button"
onClick={() =>{
setTokenExpired(false)
}}
>Späť na prihlásenie</button>
</div>
)
}

// kompletne dum-dum riešenie PREROBIŤ. Aj tu aj getTurn() !!!!!!!!!!!!!
if (token && connect === 'Company for this user not found') {
Expand All @@ -149,7 +144,7 @@ function App() {
);
}

if (data && data.num === 0 && token) {
if (turnNum === 0 && token) {
return (
<div className="flex flex-col justify-center items-center h-screen">
<h1 className="text-4xl font-bold pb-4">Hra sa ešte nezačala</h1>
Expand All @@ -164,9 +159,9 @@ function App() {
);
}

if (token && data.num != null) {
if (token && turnNum != null) {
return (
<MyContext.Provider value={{ ...data, isLoading, setIsLoading }}>
<MyContext.Provider value={{ turnNum, comm, isLoading, setIsLoading, setComm}}>
<Suspense>
<BrowserRouter>
<Navbar />
Expand All @@ -191,7 +186,7 @@ function App() {
}
if(!token){
return (
<MyContext.Provider value={{ ...data, isLoading, setIsLoading }}>
<MyContext.Provider value={{ turnNum, comm,isLoading, setIsLoading, setComm }}>
<BrowserRouter>
<Routes>
<Route path="/register" element={<Register />} />
Expand Down
8 changes: 4 additions & 4 deletions apps/saip-fe/src/api/MyContext.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createContext } from 'react';

export const MyContext = createContext({
num: null,
comm: null,
start: null,
turnNum: null,
comm: false,
isLoading: false,
setIsLoading: (isLoading: boolean) => {}
setIsLoading: (isLoading: boolean) => {},
setComm: (comm: boolean) => {}
});
18 changes: 4 additions & 14 deletions apps/saip-fe/src/components/bottombar/BottomBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,10 @@ import numberWithSpaces from "../../utils/numberWithSpaces";
export default function BottomBar() {
const [tooltipText, setTooltipText] = useState("");
const dataWs = useContext(MyContext);
const {setComm, comm} = useContext(MyContext)
const { isLoading, data, refetch} = useQuery("companyInfo", () => getGeneralInfo());
// @ts-ignore
const [committed, setCommitted] = useState(false);
const [bonusCash, setBonusCash] = useState(0);
// @ts-ignore
useEffect(() => {
// @ts-ignore
if (dataWs.comm != committed) {
setCommitted(!committed);
}
refetch()


}, [dataWs]);
const { Modal, isShowing, setIsShowing, setElement } = useModal(<div />);

const { reset: resetCompanyState } = useCompanyStore();
Expand Down Expand Up @@ -93,7 +83,7 @@ export default function BottomBar() {
};

const handleModalSubmit = async () => {
setCommitted(!committed);
setComm(true)
setIsShowing(false);
await handleEndTurn();
};
Expand All @@ -118,7 +108,7 @@ export default function BottomBar() {
<div className="fixed bottom-2 right-2 z-40">
{!isLoading ? (
<div className="bg-white px-3 py-1 rounded-lg border-2 accent-700-border">
{committed ? (
{comm ? (
<p className="text-center font-medium p-3">Čaká sa na ostatných hráčov</p>
) : (
<div className="flex flex-row gap-8 items-center">
Expand Down Expand Up @@ -163,7 +153,7 @@ export default function BottomBar() {
!getCheckedCompany() ||
!getCheckedUpgrages() ||
!getCheckedMarketing() ||
committed
comm
}
>
Ukončiť kolo
Expand Down
2 changes: 1 addition & 1 deletion apps/saip-fe/src/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Navbar() {

const dataWs = useContext(MyContext);
// @ts-ignore
const data = dataWs.num
const data = dataWs.turnNum

const tabs = [
{
Expand Down
4 changes: 2 additions & 2 deletions apps/saip-fe/src/components/reports/ArchiveReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import getCompanyReport from "../../api/GetCompanyReport";
function ArchiveReport() {
const dataWs = useContext(MyContext);
// @ts-ignore
const TURN = dataWs.num;
const TURN = dataWs.turnNum;
// @ts-ignore
const [turn, setTurn] = useState<number>(dataWs.num - 1);
const [turn, setTurn] = useState<number>(dataWs.turnNum - 1);
const { isLoading, data } = useQuery(["archiveReport", turn], () => getArchiveReport(turn));

// State for managing tutorial visibility
Expand Down
4 changes: 2 additions & 2 deletions apps/saip-fe/src/components/reports/CompanyReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { MyContext } from "../../api/MyContext";
function CompanyReport() {
const dataWs = useContext(MyContext);
// @ts-ignore
const TURN = dataWs.num;
const TURN = dataWs.turnNum;
// @ts-ignore
const [turn, setTurn] = useState<number>(dataWs.num - 1);
const [turn, setTurn] = useState<number>(dataWs.turnNum - 1);
const { isLoading, data } = useQuery(["companyReport", turn], () => getCompanyReport(turn));

// State for managing tutorial visibility
Expand Down
2 changes: 1 addition & 1 deletion apps/saip-fe/src/components/reports/IndustryReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function IndustryReport() {
const dataWs = useContext(MyContext);
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/naming-convention,no-underscore-dangle
const _turn = dataWs.num;
const _turn = dataWs.turnNum;

// @ts-ignore
const [turn, setTurn] = useState<number>(_turn - 1);
Expand Down
2 changes: 1 addition & 1 deletion apps/saip-fe/src/screens/Company.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import getGeneralInfo from "../api/CompanyInfo";
function Company() {
const data = useContext(MyContext);
// @ts-ignore
const turn = data.num;
const turn = data.turnNum;
const { isLoading: statsIsLoading, data: statsData } = useQuery(["getCompanyStats"], getCompanyStats);
// @ts-ignore
const { data: reportData } = useQuery(["companyReport", turn], () => getCompanyReport(turn - 1));
Expand Down
2 changes: 1 addition & 1 deletion apps/saip-fe/src/screens/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Plan() {
// @ts-ignore
const data = useContext(MyContext);
// @ts-ignore
const currentTurn = data.num
const currentTurn = data.turnNum
// @ts-ignore
useEffect(() => {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion apps/saip-fe/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

function-bind@^1.1.1, function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"
Expand Down

0 comments on commit d68aad0

Please sign in to comment.