Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert CRA to Next #494

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ yarn-error.log*
public/rounds/

__pycache__/

.next
next-env.d.ts
dist
2 changes: 2 additions & 0 deletions .vercelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.github
automation
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions app/FaviconGenerator.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useEffect } from "react";

const faviconTemplate = (icon) => {
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><text y="24" font-size="26">${icon}</text></svg>`;
};

function FaviconGenerator() {
useEffect(() => {
const emojis = [
"🍗",
"🍔",
"🍞",
"🥪",
"🥨",
"🍕",
"🌭",
"🌮",
"🌯",
"🍖",
"🥩",
"🥧",
"🥓",
"🦀",
];

const linkForFavicon = document.querySelector(`head > link[rel='icon']`);

if (linkForFavicon) {
const favicon = faviconTemplate(
emojis[Math.floor(Math.random() * emojis.length)]
);

linkForFavicon.setAttribute("href", `data:image/svg+xml,${favicon}`);
}
}, []); // Empty dependency array ensures this runs only once

return null;
}

export default FaviconGenerator;
4 changes: 2 additions & 2 deletions src/app/Footer.jsx → app/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
Flex,
} from "@chakra-ui/react";
import * as React from "react";
import NeopointIcon from "./images/np-icon.svg";
import NeopointIcon from "../public/images/np-icon.svg";
import { VercelCredit } from "./components/VercelCredit";

function Logo() {
return (
<Stack direction="row">
<Box as="img" src={NeopointIcon} height="1.5em" width="1.5em" />
<Box as="img" src={NeopointIcon.src} height="1.5em" width="1.5em" />
<Heading as="h1" fontFamily="heading" fontWeight="bold" fontSize="xl">
NeoFoodClub
</Heading>
Expand Down
6 changes: 3 additions & 3 deletions src/app/Header.jsx → app/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Cookies from "universal-cookie";
import Moment from "react-moment";
import React, { useContext, useEffect, useState, useMemo } from "react";
import moment from "moment";
import NeopointIcon from "./images/np-icon.svg";
import NeopointIcon from "../public/images/np-icon.svg";

import {
calculateBaseMaxBet,
Expand Down Expand Up @@ -211,14 +211,14 @@ function MaxBetInput() {
);
}

function TitleHeading(props) {
function TitleHeading() {
return (
<>
<HStack display={{ base: "none", md: "block" }}>
<Center>
<Box
as="img"
src={NeopointIcon}
src={NeopointIcon.src}
height="1.5em"
width="1.5em"
display={{ base: "none", md: "inline-block" }}
Expand Down
File renamed without changes.
17 changes: 8 additions & 9 deletions src/app/RoundState.jsx → app/RoundState.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import {
} from "./util";
import DropZone from "./DropZone";

const RoundContext = createContext(null);
const { Provider } = RoundContext;
const RoundContext = createContext();

const initialState = parseBetUrl(window.location.hash.slice(1));
const StateProvider = ({ children }) => {
const initialState = parseBetUrl(global?.window?.location.hash.slice(1));

const initialViewMode =
Object.values(initialState.bets).filter((x) => x.some((val) => val > 0))
.length > 0;
const initialViewMode =
Object.values(initialState.bets).filter((x) => x.some((val) => val > 0))
.length > 0;

const StateProvider = ({ children }) => {
const [roundState, setRoundState] = useReducer(reducer, {
roundData: null,
currentRound: null,
Expand Down Expand Up @@ -79,7 +78,7 @@ const StateProvider = ({ children }) => {
};

return (
<Provider
<RoundContext.Provider
value={{
roundState,
setRoundState,
Expand All @@ -96,7 +95,7 @@ const StateProvider = ({ children }) => {
}}
>
<DropZone>{children}</DropZone>
</Provider>
</RoundContext.Provider>
);
};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const CopyWithDomain = () => {

return (
<Tooltip
label={`Include domain when copying bets\n(${window.location.origin}/)`}
label={`Include domain when copying bets\n(${global?.window?.location.origin}/)`}
openDelay="600"
>
<Button
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
19 changes: 19 additions & 0 deletions app/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const metadata = {
title: "NeoFoodClub",
};

export default function RootLayout({ children }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<link rel="icon" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<main>{children}</main>
</body>
</html>
);
}
File renamed without changes.
File renamed without changes.
35 changes: 31 additions & 4 deletions src/app/App.jsx → app/page.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
"use client";

import "firebase/database";

import React, { useEffect, useCallback, useContext, useMemo } from "react";
import { initializeApp } from "firebase/app";

import { makeBetURL, parseBetUrl } from "./util";
import HomePage from "./HomePage";
import { RoundContext } from "./RoundState";
import useRoundData from "./useRoundData";
import { ChakraProvider } from "@chakra-ui/react";
import theme from "./theme";
import FaviconGenerator from "./FaviconGenerator";
import Head from "next/head";

import { RoundContext, StateProvider } from "./RoundState";

const config = {
apiKey: "AIzaSyA1AJzRRbOTh7iVZi4DfK9lBuSJnfTTbr4",
Expand All @@ -21,7 +28,29 @@ const config = {

const firebase = initializeApp(config);

function App() {
export default function App() {
useEffect(() => {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/service-worker.js");
}
}, []);

return (
<>
<Head>
<link rel="icon" />
</Head>
<FaviconGenerator />
<ChakraProvider theme={theme}>
<StateProvider>
<Home />
</StateProvider>
</ChakraProvider>
</>
);
}

function Home() {
const { roundState, setRoundState } = useContext(RoundContext);

useRoundStateURLs();
Expand Down Expand Up @@ -111,5 +140,3 @@ function useRoundStateURLs() {
return () => window.removeEventListener("hashchange", onHashChange);
}, [onHashChange]);
}

export default App;
File renamed without changes.
2 changes: 1 addition & 1 deletion src/theme.js → app/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ const colors = {
},
};

const theme = extendTheme(config, { colors });
const theme = extendTheme({ config }, { colors });

export default theme;
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions automation/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ docker build -t nfc_values .
# Run the docker container
docker run --rm -v $(pwd):/app nfc_values

# copy file from ./output/javascript.js to ../src/app/constants_logit.js
cp ./output/javascript.js ../src/app/constants_logit.js
# copy file from ./output/javascript.js to ../app/constants_logit.js
cp ./output/javascript.js ../app/constants_logit.js

# stage the changes
git add ./output/
git add ../src/app/constants_logit.js
git add ../app/constants_logit.js

# commit the changes
git commit -m "Auto-update logit constants"
Expand Down
7 changes: 7 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./*"]
}
}
}
7 changes: 7 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "export", // Outputs a Single-Page Application (SPA).
distDir: "./dist", // Changes the build output directory to `./dist/`.
};

export default nextConfig;
Loading