Skip to content

Commit 97f1e1d

Browse files
authored
New welcome page (#93)
* New welcome page * Fix lint * Fix tests * Fix diff issues * More fixes and improvements * star
1 parent 9c59633 commit 97f1e1d

20 files changed

Lines changed: 325 additions & 65 deletions

src/logic/Decompiler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export function decompileResultPipeline(jar: Observable<MinecraftJar>): Observab
4545
distinctUntilChanged(),
4646
throttleTime(250),
4747
switchMap(([className, jar, bytecode]) => {
48+
if (!className) {
49+
return of();
50+
}
51+
4852
if (bytecode) {
4953
return from(getClassBytecode(className, jar.jar));
5054
}

src/logic/Permalink.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { diffView, selectedFile, selectedLines, selectedMinecraftVersion } from
55
export interface State {
66
version: number; // Allows us to change the permalink structure in the future
77
minecraftVersion: string;
8-
file: string;
8+
file: string | undefined;
99
selectedLines: {
1010
line: number;
1111
lineEnd?: number;
@@ -15,7 +15,7 @@ export interface State {
1515
const DEFAULT_STATE: State = {
1616
version: 0,
1717
minecraftVersion: "",
18-
file: "net/minecraft/ChatFormatting.class",
18+
file: undefined,
1919
selectedLines: null
2020
};
2121

@@ -100,6 +100,13 @@ if (typeof window !== "undefined") {
100100
supported,
101101
diffView
102102
]) => {
103+
if (!file) {
104+
document.title = "mcsrc.dev";
105+
window.location.hash = '';
106+
window.history.replaceState({}, '', '/');
107+
return;
108+
}
109+
103110
const className = file.split('/').pop()?.replace('.class', '') || file;
104111
document.title = className;
105112

src/logic/State.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BehaviorSubject } from "rxjs";
2-
import { pairwise } from "rxjs/operators";
2+
import { filter, pairwise } from "rxjs/operators";
33
import { Tab } from "./Tabs";
44
import { getInitialState } from "./Permalink";
55

@@ -10,9 +10,9 @@ const initialState = getInitialState();
1010
export const selectedMinecraftVersion = new BehaviorSubject<string | null>(initialState.minecraftVersion);
1111

1212
export const mobileDrawerOpen = new BehaviorSubject(false);
13-
export const selectedFile = new BehaviorSubject<string>(initialState.file);
14-
export const openTabs = new BehaviorSubject<Tab[]>([new Tab(initialState.file)]);
15-
export const tabHistory = new BehaviorSubject<string[]>([initialState.file]);
13+
export const selectedFile = new BehaviorSubject<string | undefined>(initialState.file);
14+
export const openTabs = new BehaviorSubject<Tab[]>(initialState.file ? [new Tab(initialState.file)] : []);
15+
export const tabHistory = new BehaviorSubject<string[]>(initialState.file ? [initialState.file] : []);
1616
export const searchQuery = new BehaviorSubject("");
1717
export const referencesQuery = new BehaviorSubject("");
1818

src/logic/Tabs.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export const openTab = (key: string) => {
6262
selectedFile.next(key);
6363
currentTab.invalidateCachedView();
6464
openTabs.next([new Tab(key)]);
65+
} else if (!currentTab) {
66+
openTabs.next([new Tab(key)]);
6567
}
6668

6769
return;
@@ -89,8 +91,6 @@ export const openTab = (key: string) => {
8991
};
9092

9193
export const closeTab = (key: string) => {
92-
if (openTabs.value.length <= 1) return;
93-
9494
const tab = openTabs.value.find(o => o.key === key);
9595

9696
tab?.invalidateCachedView();
@@ -102,15 +102,20 @@ export const closeTab = (key: string) => {
102102
let newKey = history.pop();
103103
tabHistory.next(history);
104104

105-
if (!newKey) {
105+
if (!newKey && modifiedOpenTabs.length > 0) {
106106
// If undefined, open tab left of it
107107
let i = openTabs.value.findIndex(tab => tab.key === key) - 1;
108108
i = Math.max(i, 0);
109109
i = Math.min(i, modifiedOpenTabs.length - 1);
110110
newKey = modifiedOpenTabs[i].key;
111111
}
112112

113-
openTab(newKey);
113+
if (newKey) {
114+
openTab(newKey);
115+
} else {
116+
// No tabs left, clear selectedFile
117+
selectedFile.next("");
118+
}
114119
}
115120

116121
openTabs.next(modifiedOpenTabs);

src/ui/AboutModal.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import { Button, Checkbox, Modal } from "antd";
1+
import { Checkbox, Modal } from "antd";
22
import { useState } from "react";
33
import { agreedEula } from "../logic/Settings";
4-
import { InfoCircleOutlined } from '@ant-design/icons';
54
import { useObservable } from "../utils/UseObservable";
65
import { BehaviorSubject } from "rxjs";
76

87
export const aboutModalOpen = new BehaviorSubject<boolean>(false);
98

10-
export const AboutModalButton = () => {
11-
return (
12-
<Button type="default" onClick={() => aboutModalOpen.next(true)}>
13-
<InfoCircleOutlined />
14-
</Button>
15-
);
16-
};
17-
189
const AboutModal = () => {
1910
const accepted = useObservable(agreedEula.observable);
2011
const isModalOpen = useObservable(aboutModalOpen);
@@ -43,10 +34,6 @@ const AboutModal = () => {
4334
footer={null}
4435
>
4536
<p>NOTE! This website is not redistributing any Minecraft code or compiled bytecode. The minecraft jar is downloaded directly from Mojang's servers to your device when you use this tool. Check your browser's network requests!</p>
46-
<p>The <a href="https://github.com/Vineflower/vineflower">Vineflower</a> decompiler is used after being compiled to wasm as part of the <a href="https://www.npmjs.com/package/@run-slicer/vf">@run-slicer/vf</a> project.</p>
47-
48-
<p><a href="https://github.com/FabricMC/mcsrc">GitHub</a></p>
49-
5037
<Eula onAccept={() => aboutModalOpen.next(false)} />
5138
</Modal>
5239
);

src/ui/App.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { Button, ConfigProvider, Drawer, Flex, Splitter, theme } from 'antd';
22
import Code from "./Code.tsx";
33
import SideBar from './SideBar.tsx';
4-
import { useState } from 'react';
4+
import { useEffect, useState } from 'react';
55
import { useObservable } from '../utils/UseObservable.ts';
66
import { isThin } from '../logic/Browser.ts';
7-
import { diffView, mobileDrawerOpen } from '../logic/State';
7+
import { diffView, mobileDrawerOpen, openTabs, selectedFile } from '../logic/State';
88
import DiffView from './diff/DiffView.tsx';
99
import { FilepathHeader } from './FilepathHeader.tsx';
1010
import { enableTabs } from '../logic/Settings.ts';
1111
import { MenuFoldOutlined } from '@ant-design/icons';
1212
import { TabsComponent } from './TabsComponent.tsx';
1313
import Modals from './Modals.tsx';
14+
import { EmptyState } from './EmptyState.tsx';
1415

1516
const App = () => {
1617
const isSmall = useObservable(isThin);
@@ -36,6 +37,11 @@ const App = () => {
3637
);
3738
};
3839

40+
const CodeOrEmpty = () => {
41+
const tabs = useObservable(openTabs);
42+
return tabs && tabs.length > 0 ? <Code /> : <EmptyState />;
43+
};
44+
3945
const LargeApp = () => {
4046
const [sizes, setSizes] = useState<(number | string)[]>(['25%', '75%']);
4147
const tabsEnabled = useObservable(enableTabs.observable);
@@ -49,7 +55,9 @@ const LargeApp = () => {
4955
<Flex vertical style={{ height: "100%" }}>
5056
{tabsEnabled && <TabsComponent />}
5157
<FilepathHeader />
52-
<div style={{ flexGrow: 1 }}><Code /></div>
58+
<div style={{ flexGrow: 1 }}>
59+
<CodeOrEmpty />
60+
</div>
5361
</Flex>
5462
</Splitter.Panel>
5563
</Splitter>
@@ -59,6 +67,7 @@ const LargeApp = () => {
5967
const MobileApp = () => {
6068
const open = useObservable(mobileDrawerOpen);
6169
const tabsEnabled = useObservable(enableTabs.observable);
70+
const currentFile = useObservable(selectedFile);
6271

6372
const showDrawer = () => {
6473
mobileDrawerOpen.next(true);
@@ -68,6 +77,10 @@ const MobileApp = () => {
6877
mobileDrawerOpen.next(false);
6978
};
7079

80+
useEffect(() => {
81+
mobileDrawerOpen.next(false);
82+
}, [currentFile]);
83+
7184
return (
7285
<Flex vertical style={{ height: "100%" }}>
7386
<Drawer
@@ -95,7 +108,9 @@ const MobileApp = () => {
95108
}
96109
</Flex>
97110
<FilepathHeader />
98-
<div style={{ flexGrow: 1 }}><Code /></div>
111+
<div style={{ flexGrow: 1, overflow: "auto" }}>
112+
<CodeOrEmpty />
113+
</div>
99114
</Flex>
100115
);
101116
};

0 commit comments

Comments
 (0)