Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lijiahao committed Sep 24, 2024
1 parent 80c2dc1 commit 19599a9
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 144 deletions.
2 changes: 0 additions & 2 deletions next-i18next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-check

/**
* @type {import('next-i18next').UserConfig}
*/
Expand Down
8 changes: 6 additions & 2 deletions renderer/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import { useTranslation } from "next-i18next";

import Ipc from "../lib/ipc";

const Nav = ({ current, isLogined, locale }) => {
const Nav = ({ current, isLogined }) => {
console.log("isLogined:", isLogined);

const { t } = useTranslation("common");
const { t, i18n: {language: locale} } = useTranslation("common");
const [userState, setUserState] = useState(null);

const metas = [
Expand All @@ -35,6 +35,10 @@ const Nav = ({ current, isLogined, locale }) => {
name: t("Settings"),
href: "/settings",
},
// {
// name: 'Stream',
// href: "/stream?serverid=123",
// },
];

useEffect(() => {
Expand Down
7 changes: 5 additions & 2 deletions renderer/components/TitleModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const XCLOUD_PREFIX = "xcloud_";

function TitleModal(props) {
const router = useRouter();
const { t } = useTranslation('cloud');
const { t, i18n: {language: locale} } = useTranslation('cloud');

const titleItem = props.title || {};

Expand All @@ -27,7 +27,10 @@ function TitleModal(props) {
const handleStartGame = () => {
console.log("titleItem:", titleItem);
const titleId = titleItem.titleId || titleItem.XCloudTitleId;
router.push("stream/" + XCLOUD_PREFIX + titleId);
router.push({
pathname: `/${locale}/stream`,
query: { serverid: XCLOUD_PREFIX + titleId }
});
};

return (
Expand Down
32 changes: 32 additions & 0 deletions renderer/lib/get-static.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {serverSideTranslations} from "next-i18next/serverSideTranslations"

import i18next from "../../next-i18next.config.js"

export function getI18nPaths() {
return ["en", "zh"].map(locale => ({
params: {
locale,
},
}))
}

export function getStaticPaths() {
return {
fallback: false, paths: getI18nPaths(),
}
}

export async function getI18nProperties(context, namespaces = ["common"]) {
const locale = context?.params?.locale ?? i18next.i18n.defaultLocale;
return {
...(await serverSideTranslations(locale, namespaces)),
}
}

export function makeStaticProperties(namespaces = []) {
return async function (context) {
return {
props: await getI18nProperties(context, namespaces),
};
};
}
5 changes: 2 additions & 3 deletions renderer/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { i18n } = require('../next-i18next.config.js')

/** @type {import('next').NextConfig} */
module.exports = {
// i18n,
webpack: (config, { isServer }) => {
if (!isServer) {
// config.target = 'electron-renderer';
Expand All @@ -10,6 +8,7 @@ module.exports = {

return config;
},
trailingSlash: true,

images: {
unoptimized: true,
Expand Down
16 changes: 0 additions & 16 deletions renderer/pages/404.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions renderer/pages/500.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions renderer/pages/[locale]/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import Head from "next/head";
import { getStaticPaths, makeStaticProperties } from "../../lib/get-static";

function Error404Page() {
return (
<React.Fragment>
<Head>
<title>XStreaming - Error</title>
</Head>

<p>Oopsie 404.. Action not found</p>
</React.Fragment>
);
}

export default Error404Page;

// eslint-disable-next-line react-refresh/only-export-components
export const getStaticProps = makeStaticProperties(["common"]);

// eslint-disable-next-line react-refresh/only-export-components
export { getStaticPaths };
23 changes: 23 additions & 0 deletions renderer/pages/[locale]/500.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import Head from "next/head";
import { getStaticPaths, makeStaticProperties } from "../../lib/get-static";

function Error500Page() {
return (
<React.Fragment>
<Head>
<title>XStreaming - Error</title>
</Head>

<p>Oopsie 500.. Application has an error</p>
</React.Fragment>
);
}

export default Error500Page;

// eslint-disable-next-line react-refresh/only-export-components
export const getStaticProps = makeStaticProperties(["common"]);

// eslint-disable-next-line react-refresh/only-export-components
export { getStaticPaths };
38 changes: 17 additions & 21 deletions renderer/pages/home.tsx → renderer/pages/[locale]/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import {
} from "@nextui-org/react";
import { useTranslation } from "next-i18next";
import { useRouter } from 'next/router';
import Layout from "../components/Layout";
import AuthModal from "../components/AuthModal";
import Ipc from "../lib/ipc";
import Loading from "../components/Loading";
import Nav from "../components/Nav";
import Layout from "../../components/Layout";
import AuthModal from "../../components/AuthModal";
import Ipc from "../../lib/ipc";
import Loading from "../../components/Loading";
import Nav from "../../components/Nav";

import Image from "next/image";

import type { GetStaticProps } from 'next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import { getStaticPaths, makeStaticProperties } from "../../lib/get-static";

function Home() {
const { t } = useTranslation('home');
const { t, i18n: {language: locale} } = useTranslation('home');

const router = useRouter();
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -130,12 +129,15 @@ function Home() {

const startSession = (sessionId) => {
console.log("sessionId:", sessionId);
router.push(router.locale + "/stream/" + sessionId);
router.push({
pathname: `/${locale}/stream`,
query: { serverid: sessionId }
});
};

return (
<>
<Nav current={t("Consoles")} isLogined={isLogined} locale={router.locale} />
<Nav current={t("Consoles")} isLogined={isLogined} />

{loading && <Loading loadingText={loadingText} />}

Expand Down Expand Up @@ -187,16 +189,10 @@ function Home() {
);
}

export default Home;

// eslint-disable-next-line react-refresh/only-export-components
export const getStaticProps: GetStaticProps = async ({
locale,
}) => ({
props: {
...(await serverSideTranslations(locale ?? 'en', [
'common',
'home',
])),
},
})
export const getStaticProps = makeStaticProperties(["common", "home"]);

export default Home;
// eslint-disable-next-line react-refresh/only-export-components
export {getStaticPaths};
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import MapItem from "../../components/MapItem";
import Nav from "../../components/Nav";
import { useSettings } from "../../context/userContext";

import type { GetStaticProps } from "next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { getStaticPaths, makeStaticProperties } from "../../lib/get-static";

const defaultMaping = {
A: 0,
Expand Down Expand Up @@ -109,7 +108,7 @@ function Map() {

return (
<div className="map-page">
<Nav current={t("Settings")} isLogined={isLogined} locale={router.locale} />
<Nav current={t("Settings")} isLogined={isLogined} />

{showModal && (
<GamepadMapModal
Expand Down Expand Up @@ -157,11 +156,10 @@ function Map() {
);
}

export default Map;

// eslint-disable-next-line react-refresh/only-export-components
export const getStaticProps: GetStaticProps = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale ?? "en", ["common", "settings"])),
},
});
export const getStaticProps = makeStaticProperties(["common", "settings"]);

export default Map;
// eslint-disable-next-line react-refresh/only-export-components
export {getStaticPaths};
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ import React, { useEffect, useState } from "react";
import { Button, Tabs, Tab, Card, CardBody } from "@nextui-org/react";
import { useTranslation } from "next-i18next";
import { useRouter } from "next/router";
import { useSettings } from "../context/userContext";

import Ipc from "../lib/ipc";
import Layout from "../components/Layout";
import SettingItem from "../components/SettingItem";
import Alert from "../components/Alert";
import getSettingsMetas from "../common/settings";
import Nav from "../components/Nav";
import FeedbackModal from "../components/FeedbackModal";
import ConfirmModal from "../components/ConfirmModal";
import KeyboardMap from "../components/KeyboardMap";
import updater from "../lib/updater";
import pkg from "../../package.json";

import type { GetStaticProps } from "next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { useSettings } from "../../context/userContext";

import Ipc from "../../lib/ipc";
import Layout from "../../components/Layout";
import SettingItem from "../../components/SettingItem";
import Alert from "../../components/Alert";
import getSettingsMetas from "../../common/settings";
import Nav from "../../components/Nav";
import FeedbackModal from "../../components/FeedbackModal";
import ConfirmModal from "../../components/ConfirmModal";
import KeyboardMap from "../../components/KeyboardMap";
import updater from "../../lib/updater";
import pkg from "../../../package.json";

import { getStaticPaths, makeStaticProperties } from "../../lib/get-static";

function Settings() {
const { t, i18n } = useTranslation("settings");
const { t, i18n: {language: locale} } = useTranslation("settings");
const { resetSettings } = useSettings();
const router = useRouter();

Expand All @@ -35,8 +34,6 @@ function Settings() {
const [isChecking, setIsChecking] = useState(false);
const [settings, setSettings] = useState<any>({});

const currentLanguage = i18n.language;

useEffect(() => {
const _isLogined = window.sessionStorage.getItem("isLogined") || "0";
if (_isLogined === "1") {
Expand Down Expand Up @@ -80,7 +77,7 @@ function Settings() {

return (
<>
<Nav current={t("Settings")} isLogined={isLogined} locale={router.locale} />
<Nav current={t("Settings")} isLogined={isLogined} />

{showAlert && (
<Alert content={alertMessage} onClose={() => setShowAlert(false)} />
Expand Down Expand Up @@ -163,7 +160,9 @@ function Settings() {
<Button
color="default"
onClick={() => {
router.push(`${router.locale}/gamepad/map`);
router.push({
pathname: `/${locale}/map`
});
}}
>
{t('Settings')}
Expand Down Expand Up @@ -209,7 +208,9 @@ function Settings() {
<Button
color="default"
onClick={() => {
router.push("gamepad/test");
router.push({
pathname: `/${locale}/test`
});
}}
>
test
Expand Down Expand Up @@ -250,7 +251,7 @@ function Settings() {
</CardBody>
</Card>

{(currentLanguage === "zh" || currentLanguage === "zht") && (
{(locale === "zh" || locale === "zht") && (
<Card className="setting-item">
<CardBody>
<div className="setting-title">反馈及支持</div>
Expand Down Expand Up @@ -284,11 +285,10 @@ function Settings() {
);
}

export default Settings;

// eslint-disable-next-line react-refresh/only-export-components
export const getStaticProps: GetStaticProps = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale ?? "en", ["common", "settings"])),
},
});
export const getStaticProps = makeStaticProperties(["common", "settings"]);

export default Settings;
// eslint-disable-next-line react-refresh/only-export-components
export {getStaticPaths};
Loading

0 comments on commit 19599a9

Please sign in to comment.