Skip to content

Commit

Permalink
feat: simple profile management
Browse files Browse the repository at this point in the history
  • Loading branch information
ResetPower committed Jun 10, 2021
1 parent 43f4ebf commit 7d9bc98
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/components/Dialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,14 @@ export function ErrorDialog(props: ErrorDialogProps): JSX.Element {
</Dialog>
);
}

export function DownloadDialog(props: CustomDialogProps): JSX.Element {
return (
<Dialog indentBottom>
<Typography>{t("downloadNotSupported")}</Typography>
<div className="flex justify-end">
<Button onClick={props.onClose}>{t("ok")}</Button>
</div>
</Dialog>
);
}
2 changes: 1 addition & 1 deletion src/components/List.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode } from "react";

export default function List(props: { children: ReactNode; className?: string }): JSX.Element {
return <div className={`space-y-4 ${props.className}`}>{props.children}</div>;
return <div className={`space-y-3 ${props.className}`}>{props.children}</div>;
}
3 changes: 2 additions & 1 deletion src/components/ListItemText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ export default function ListItemText(props: {
primary?: string;
secondary?: string;
className?: string;
onClick?: () => void;
}): JSX.Element {
return (
<div className={props.className}>
<div className={props.className} onClick={props.onClick}>
<Typography>{props.primary}</Typography>
<p className="text-shallow">{props.secondary}</p>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/lang/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
4 changes: 4 additions & 0 deletions src/lang/ja-jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ export default {
downloadProvider: "ダウンロードソース",
downloadProviderIsNotAble:
"申し訳ありませんが、現在、ダウンロードソースの変更はサポートされていません。",
downloadNotSupported:
"申し訳ありませんが、Minecraft クライアントのダウンロードは現在サポートされていません。",
maps: "マップ",
resourcePacks: "リソースパック",
};
3 changes: 3 additions & 0 deletions src/lang/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ export default {
official: "官方",
downloadProvider: "下载源",
downloadProviderIsNotAble: "暂不支持更换下载源,请谅解。",
downloadNotSupported: "很抱歉,目前暂不支持 Minecraft 客户端的下载。",
maps: "地图",
resourcePacks: "资源包",
};
28 changes: 24 additions & 4 deletions src/pages/DownloadsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}

Expand All @@ -21,6 +26,7 @@ export default class DownloadsPage extends Component<EmptyProps, DownloadsPageSt
release: true,
snapshot: false,
old: false,
loading: true,
versions: [],
};
matchType(type: MinecraftVersionType): boolean {
Expand All @@ -37,7 +43,7 @@ export default class DownloadsPage extends Component<EmptyProps, DownloadsPageSt
if (isSuccess(res.status)) {
const parsed = JSON.parse(res.text);
if (parsed.hasOwnProperty("versions")) {
this.setState({ versions: parsed.versions });
this.setState({ versions: parsed.versions, loading: false });
}
}
});
Expand Down Expand Up @@ -65,9 +71,23 @@ export default class DownloadsPage extends Component<EmptyProps, DownloadsPageSt
{t("old")}
</Checkbox>
</div>
<List>
{this.state.loading && <Spin />}
<List className="space-y-0">
{this.state.versions.map((item, index) => {
return this.matchType(item.type) && <Typography key={index}>{item.id}</Typography>;
return (
this.matchType(item.type) && (
<ListItem key={index}>
<ListItemText
primary={item.id}
secondary={item.type}
className="cursor-pointer"
onClick={() => {
showDialog((close) => <DownloadDialog onClose={close} />);
}}
/>
</ListItem>
)
);
})}
</List>
</Container>
Expand Down
69 changes: 62 additions & 7 deletions src/pages/ProfileManagementPage.tsx
Original file line number Diff line number Diff line change
@@ -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<string, never>;
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 (
<button
className={`block focus:outline-none ${
this.state.value === props.value ? "text-pink-500" : "text-black dark:text-white"
}`}
onClick={() => this.setState({ value: props.value })}
>
{props.children}
</button>
);
};
profile: MinecraftProfile | null;
constructor(props: ProfileManagementPageProps) {
super(props);
this.profile = getProfile(Number(this.props.params.id));
}
async componentDidMount(): Promise<void> {
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 (
<Container>
{profile === null ? (
{this.profile === null ? (
<Alert severity="error">Sorry. Profile Id Not Found.</Alert>
) : (
<div>
<Typography>{t("notSupportedYet")}</Typography>
<div className="flex">
<div className="p-6 border-r border-divide">
<this.TabItem value={0}>{t("maps")}</this.TabItem>
<this.TabItem value={1}>{t("resourcePacks")}</this.TabItem>
</div>
<div className="p-3 flex-grow">
<div hidden={this.state.value !== 0}>
{this.state.mapsList.map(
(m, index) =>
m !== ".DS_Store" && (
/* avoid useless .DS_Store file on macOS */ <Typography key={index}>
{m}
</Typography>
)
)}
</div>
<div hidden={this.state.value !== 1}>
{this.state.resourcePacksList.map(
(m, index) =>
m !== ".DS_Store" && (
/* avoid useless .DS_Store file on macOS */ <Typography key={index}>
{m}
</Typography>
)
)}
</div>
</div>
</div>
)}
</Container>
Expand Down
4 changes: 2 additions & 2 deletions src/router/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7d9bc98

Please sign in to comment.