From 7d9bc98aaa633175bc8e9f84028bcf0aa41df457 Mon Sep 17 00:00:00 2001 From: ResetPower Date: Thu, 10 Jun 2021 22:27:33 +0800 Subject: [PATCH] feat: simple profile management --- src/components/Dialogs.tsx | 11 +++++ src/components/List.tsx | 2 +- src/components/ListItemText.tsx | 3 +- src/lang/en-us.ts | 5 ++- src/lang/ja-jp.ts | 4 ++ src/lang/zh-cn.ts | 3 ++ src/pages/DownloadsPage.tsx | 28 ++++++++++-- src/pages/ProfileManagementPage.tsx | 69 ++++++++++++++++++++++++++--- src/router/history.ts | 4 +- 9 files changed, 113 insertions(+), 16 deletions(-) diff --git a/src/components/Dialogs.tsx b/src/components/Dialogs.tsx index 9ebc3310..c93b1591 100644 --- a/src/components/Dialogs.tsx +++ b/src/components/Dialogs.tsx @@ -399,3 +399,14 @@ export function ErrorDialog(props: ErrorDialogProps): JSX.Element { ); } + +export function DownloadDialog(props: CustomDialogProps): JSX.Element { + return ( + + {t("downloadNotSupported")} +
+ +
+
+ ); +} diff --git a/src/components/List.tsx b/src/components/List.tsx index cd76c477..5b16b618 100644 --- a/src/components/List.tsx +++ b/src/components/List.tsx @@ -1,5 +1,5 @@ import { ReactNode } from "react"; export default function List(props: { children: ReactNode; className?: string }): JSX.Element { - return
{props.children}
; + return
{props.children}
; } diff --git a/src/components/ListItemText.tsx b/src/components/ListItemText.tsx index 4db5ffb1..5ecf17c9 100644 --- a/src/components/ListItemText.tsx +++ b/src/components/ListItemText.tsx @@ -4,9 +4,10 @@ export default function ListItemText(props: { primary?: string; secondary?: string; className?: string; + onClick?: () => void; }): JSX.Element { return ( -
+
{props.primary}

{props.secondary}

diff --git a/src/lang/en-us.ts b/src/lang/en-us.ts index 65d30138..3881353d 100644 --- a/src/lang/en-us.ts +++ b/src/lang/en-us.ts @@ -74,5 +74,8 @@ export default { downloading: "Downloading", official: "Official", downloadProvider: "Download Provider", - downloadProviderIsNotAble: "Sorry, It's not supported to change download providers now.", + downloadProviderIsNotAble: "Sorry, it's not supported to change download providers now.", + downloadNotSupported: "Sorry, it's not supported to download Minecraft client now.", + maps: "Maps", + resourcePacks: "Resource Packs", }; diff --git a/src/lang/ja-jp.ts b/src/lang/ja-jp.ts index 6c554b4d..4394257d 100644 --- a/src/lang/ja-jp.ts +++ b/src/lang/ja-jp.ts @@ -77,4 +77,8 @@ export default { downloadProvider: "ダウンロードソース", downloadProviderIsNotAble: "申し訳ありませんが、現在、ダウンロードソースの変更はサポートされていません。", + downloadNotSupported: + "申し訳ありませんが、Minecraft クライアントのダウンロードは現在サポートされていません。", + maps: "マップ", + resourcePacks: "リソースパック", }; diff --git a/src/lang/zh-cn.ts b/src/lang/zh-cn.ts index e0b68d8c..2b59dc7a 100644 --- a/src/lang/zh-cn.ts +++ b/src/lang/zh-cn.ts @@ -76,4 +76,7 @@ export default { official: "官方", downloadProvider: "下载源", downloadProviderIsNotAble: "暂不支持更换下载源,请谅解。", + downloadNotSupported: "很抱歉,目前暂不支持 Minecraft 客户端的下载。", + maps: "地图", + resourcePacks: "资源包", }; diff --git a/src/pages/DownloadsPage.tsx b/src/pages/DownloadsPage.tsx index 5529f3e7..668db9f9 100644 --- a/src/pages/DownloadsPage.tsx +++ b/src/pages/DownloadsPage.tsx @@ -6,13 +6,18 @@ import List from "../components/List"; import { ephFetch } from "../tools/http"; import { isSuccess } from "../tools/auth"; import { MinecraftVersion, MinecraftVersionType } from "../core/rules"; -import Typography from "../components/Typography"; import { t } from "../renderer/global"; +import ListItem from "../components/ListItem"; +import ListItemText from "../components/ListItemText"; +import Spin from "../components/Spin"; +import { showDialog } from "../renderer/overlay"; +import { DownloadDialog } from "../components/Dialogs"; interface DownloadsPageState { release: boolean; snapshot: boolean; old: boolean; + loading: boolean; versions: MinecraftVersion[]; } @@ -21,6 +26,7 @@ export default class DownloadsPage extends Component
- + {this.state.loading && } + {this.state.versions.map((item, index) => { - return this.matchType(item.type) && {item.id}; + return ( + this.matchType(item.type) && ( + + { + showDialog((close) => ); + }} + /> + + ) + ); })} diff --git a/src/pages/ProfileManagementPage.tsx b/src/pages/ProfileManagementPage.tsx index 726c2433..7b733dc2 100644 --- a/src/pages/ProfileManagementPage.tsx +++ b/src/pages/ProfileManagementPage.tsx @@ -1,31 +1,86 @@ import Container from "../components/Container"; import Alert from "../components/Alert"; -import { Component } from "react"; +import { Component, ReactNode } from "react"; import { t } from "../renderer/global"; -import { getProfile } from "../renderer/profiles"; +import { getProfile, MinecraftProfile } from "../renderer/profiles"; +import fs from "fs"; import Typography from "../components/Typography"; export interface ProfileManagementPageProps { params: { [key: string]: string }; } -export type ProfileManagementPageState = Record; +export interface ProfileManagementPageState { + value: number; + mapsList: string[]; + resourcePacksList: string[]; +} export default class ProfileManagementPage extends Component< ProfileManagementPageProps, ProfileManagementPageState > { + state: ProfileManagementPageState = { + value: 0, + mapsList: [], + resourcePacksList: [], + }; + TabItem = (props: { children: ReactNode; value: number }): JSX.Element => { + return ( + + ); + }; + profile: MinecraftProfile | null; constructor(props: ProfileManagementPageProps) { super(props); + this.profile = getProfile(Number(this.props.params.id)); + } + async componentDidMount(): Promise { + if (this.profile !== null) { + const mapsDir = fs.readdirSync(`${this.profile.dir}/saves`); + const resourcesDir = fs.readdirSync(`${this.profile.dir}/resourcepacks`); + this.setState({ mapsList: mapsDir, resourcePacksList: resourcesDir }); + } } render(): JSX.Element { - const profile = getProfile(Number(this.props.params.id)); return ( - {profile === null ? ( + {this.profile === null ? ( Sorry. Profile Id Not Found. ) : ( -
- {t("notSupportedYet")} +
+
+ {t("maps")} + {t("resourcePacks")} +
+
+ + +
)} diff --git a/src/router/history.ts b/src/router/history.ts index 456035d4..a8a2336a 100644 --- a/src/router/history.ts +++ b/src/router/history.ts @@ -9,8 +9,8 @@ export interface EphLocation { export class EphHistory { loc = { pathname: "/", params: {} }; paths = ["/"]; - // animation lasts 100 ms - animationTimeout = 100; + // animation lasts 120 ms + animationTimeout = 120; // the only instance of EphHistory static inst = new EphHistory(); private constructor() {