Skip to content

Commit 9d72b25

Browse files
committed
Misc
1 parent fbce0ea commit 9d72b25

29 files changed

+735
-763
lines changed

client/src/app/data/store.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import * as $ from 'react-exo/redux';
22
import {KV} from 'react-exo/kv';
33
import cfg from 'config';
4-
54
import app from 'app/store';
6-
import media from 'media/store';
75

86
const reducer = $.persistReducer({
97
key: cfg.APP_NAME,
@@ -18,7 +16,6 @@ const reducer = $.persistReducer({
1816
}, $.combineReducers({
1917
router: $.history.context.routerReducer,
2018
app: app.reducer,
21-
media: media.reducer,
2219
}));
2320

2421
const store = $.configureStore({
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {useState, useEffect} from 'react';
2+
import {useLocation} from 'react-exo/navigation';
3+
4+
export function useCurrentResource() {
5+
const {pathname, hash} = useLocation();
6+
const [path, setPath] = useState(hash ? `${pathname}/${hash?.slice(1)}` : '');
7+
const [maximized, setMaximized] = useState(true);
8+
9+
useEffect(() => {
10+
if (hash) {
11+
const _path = `${pathname}/${hash?.slice(1)}`;
12+
if (_path !== path) {
13+
setPath(_path);
14+
}
15+
setMaximized(true);
16+
} else {
17+
setMaximized(false);
18+
}
19+
}, [pathname, hash, path]);
20+
21+
return {path, maximized, setPath, setMaximized};
22+
}

client/src/app/interface/Menu.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {Trans} from '@lingui/macro';
2-
import {View, ScrollView, Text} from 'react-native';
2+
import {View, ScrollView} from 'react-native';
33
import {useStyles, createStyleSheet} from 'react-native-unistyles';
44
import {StorageIndicator} from 'media/stacks/StorageIndicator';
55
import {useFileSystem} from 'media/hooks/useFileSystem';
6-
import {useLists} from 'media/hooks/useLists';
76

87
import {MenuItem} from './MenuItem';
98
import {MenuHeader} from './MenuHeader';
@@ -16,9 +15,9 @@ export interface MenuProps {
1615
}
1716

1817
export function Menu(props: MenuProps) {
19-
const lists = useLists();
18+
// const lists = useLists();
2019
const {importFile} = useFileSystem();
21-
const {styles, theme} = useStyles(stylesheet);
20+
const {styles} = useStyles(stylesheet);
2221

2322
return (
2423
<View style={styles.bg}>
@@ -95,7 +94,7 @@ export function Menu(props: MenuProps) {
9594
path="/calendar"
9695
/>
9796
</MenuSection>
98-
<MenuSection label={<Trans>Favorites</Trans>}>
97+
{/* <MenuSection label={<Trans>Favorites</Trans>}>
9998
{lists.map(({id}) =>
10099
<MenuItem
101100
key={id}
@@ -106,7 +105,7 @@ export function Menu(props: MenuProps) {
106105
mode="subitem"
107106
/>
108107
)}
109-
</MenuSection>
108+
</MenuSection> */}
110109
{__DEV__ &&
111110
<MenuSection label={<Trans>Dev Mode</Trans>} closed>
112111
<MenuItem

client/src/app/layout.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import {useEffect} from 'react';
2+
import {useInitialTheme, UnistylesRuntime} from 'react-native-unistyles';
13
import {StatusBar, Appearance} from 'react-native';
24
import {GestureProvider} from 'react-exo/gesture';
35
import {ToastRoot} from 'react-exo/toast';
4-
import {useEffect} from 'react';
5-
import {useInitialTheme, UnistylesRuntime} from 'react-native-unistyles';
66
import {useScheme} from 'app/hooks/useScheme';
77
import {hideBootsplash} from 'app/utils/bootsplash';
88

@@ -23,9 +23,15 @@ export function Layout(props: React.PropsWithChildren) {
2323

2424
return (
2525
<GestureProvider style={{flex: 1}}>
26-
<StatusBar barStyle={`${theme}-content`}/>
26+
<StatusBar
27+
barStyle={`${theme}-content`}
28+
/>
2729
{props.children}
28-
<ToastRoot theme={theme} position="bottom-center" offset={12}/>
30+
<ToastRoot
31+
theme={theme}
32+
offset={12}
33+
position="bottom-center"
34+
/>
2935
</GestureProvider>
3036
);
3137
}

client/src/app/routes/MainLayout.tsx

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,54 @@
1-
import {useState, useEffect} from 'react';
2-
import {useLocation, Outlet} from 'react-exo/navigation';
3-
import {useWindowDimensions, View, StatusBar} from 'react-native';
1+
import {Outlet} from 'react-exo/navigation';
42
import {useStyles, createStyleSheet} from 'react-native-unistyles';
3+
import {useWindowDimensions, View, StatusBar} from 'react-native';
4+
import {useCurrentResource} from 'app/hooks/useCurrentResource';
55
import {useDeviceSession} from 'app/hooks/useDeviceSession';
66
import {useProfile} from 'app/data';
77
import {Menu} from 'app/interface/Menu';
88
import {Tabs} from 'app/interface/Tabs';
9-
import {File} from 'media/stacks/File';
9+
import {CurrentFile} from 'media/stacks/CurrentFile';
1010

1111
import type {useAppContext} from 'app/hooks/useAppContext';
1212

1313
export const APP_MENU_WIDTH = 146;
1414
export const APP_MENU_TAB_HEIGHT = 64;
1515

1616
export default function MainLayout() {
17+
const {styles, theme} = useStyles(stylesheet);
18+
const resource = useCurrentResource();
1719
const screen = useWindowDimensions();
1820
const device = useDeviceSession();
1921
const profile = useProfile();
20-
const {styles, theme} = useStyles(stylesheet);
21-
const {pathname, hash} = useLocation();
22-
const [pinnedFile, setPinnedFile] = useState(`${pathname}/${hash?.slice(1)}`);
23-
const [pinMaximized, setPinMaximized] = useState(true);
24-
const context: ReturnType<typeof useAppContext> = {device, profile};
25-
const tabs = screen.width < theme.breakpoints.xs;
26-
const vert = screen.width < theme.breakpoints.sm;
22+
23+
const isVertical = screen.width < theme.breakpoints.sm;
24+
const hasTabs = screen.width < theme.breakpoints.xs;
2725
const vstyles = {
28-
root: [styles.root, tabs && styles.rootTabs],
29-
menu: [styles.menu, tabs && styles.menuTabs],
30-
content: [styles.content, vert && styles.contentVert],
26+
root: [styles.root, hasTabs && styles.rootTabs],
27+
menu: [styles.menu, hasTabs && styles.menuTabs],
28+
content: [styles.content, isVertical && styles.contentVert],
3129
};
3230

33-
useEffect(() => {
34-
if (hash) {
35-
const path = `${pathname}/${hash?.slice(1)}`;
36-
if (path !== pinnedFile) {
37-
setPinnedFile(path);
38-
}
39-
setPinMaximized(true);
40-
} else {
41-
setPinMaximized(false);
42-
}
43-
}, [hash, pathname, pinnedFile]);
31+
const context: ReturnType<typeof useAppContext> = {
32+
profile,
33+
device,
34+
};
4435

4536
return <>
4637
<StatusBar networkActivityIndicatorVisible={!device?.online}/>
4738
<View style={vstyles.root}>
4839
<View style={vstyles.menu}>
49-
{tabs ? <Tabs/> : <Menu {...{profile}}/>}
40+
{hasTabs ? <Tabs/> : <Menu {...{profile}}/>}
5041
</View>
5142
<View style={vstyles.content}>
5243
<Outlet {...{context}}/>
53-
<File
54-
file={pinnedFile}
55-
vertical={vert}
56-
maximized={pinMaximized}
57-
close={() => setPinnedFile('')}
58-
/>
44+
{Boolean(resource.path) &&
45+
<CurrentFile
46+
path={resource.path}
47+
vertical={isVertical}
48+
maximized={resource.maximized}
49+
close={() => resource.setPath('')}
50+
/>
51+
}
5952
</View>
6053
</View>
6154
</>;

client/src/media/hooks/useDirectory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {fs} from 'react-exo/fs';
22
import {useState, useEffect} from 'react';
3-
import {INIT_DIRECTORIES} from './useInitDirectories';
3+
import {isInitDirectory} from 'media/utils/path';
44
import type {HfsDirectoryEntry} from 'react-exo/fs';
55

66
interface DirectoryOptions {
@@ -18,7 +18,7 @@ export function useDirectory(path: string, options?: DirectoryOptions) {
1818
for await (const entry of hfs.list?.(dirPath) ?? []) {
1919
if (entry.name.endsWith('.crswap')) continue;
2020
if (entry.name.startsWith('.') && !options?.showHidden) continue;
21-
if (dirPath === '.' && INIT_DIRECTORIES.includes(entry.name)) continue;
21+
if (dirPath === '.' && isInitDirectory(entry.name)) continue;
2222
entries.push(entry);
2323
}
2424
setEntries(entries.sort((a, b) => {
Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,25 @@
1-
import {useCallback} from 'react';
21
import {fs} from 'react-exo/fs';
3-
4-
import type {OpenDirectoryOptions} from 'react-exo/fs';
2+
import {useCallback} from 'react';
3+
import {getStartInDir} from 'media/utils/path';
54

65
export function useFileSystem() {
7-
const getOpenDirectoryInit = useCallback((path: string) => {
8-
let startIn: OpenDirectoryOptions['startIn'];
9-
switch (path) {
10-
case 'documents': startIn = 'documents'; break;
11-
case 'pictures': startIn = 'pictures'; break;
12-
case 'videos': startIn = 'videos'; break;
13-
case 'music': startIn = 'music'; break;
14-
case 'downloads': startIn = 'downloads'; break;
15-
default: startIn = 'desktop';
16-
}
17-
return startIn;
18-
}, []);
19-
20-
const importDirectory = useCallback(async (path = '.') => {
21-
const startIn = getOpenDirectoryInit(path);
22-
const dir = await fs.openDirectory({id: path, startIn, mode: 'read'});
23-
const start = performance.now();
24-
const copy = await fs.importDirectory(dir, path);
25-
console.log('[fs] import dir', copy, performance.now() - start);
26-
}, [getOpenDirectoryInit]);
27-
286
const importFile = useCallback(async () => {
7+
const perfStart = performance.now();
298
const file = await fs.openFile();
30-
console.log('[fs] file', file);
31-
const start = performance.now();
329
const copy = await fs.importFile(file);
33-
console.log('[fs] import file', copy, performance.now() - start);
10+
console.log('[fs] import file', file, copy, performance.now() - perfStart);
3411
}, []);
3512

36-
const hashFile = useCallback(async () => {
37-
const file = await fs.openFile();
38-
console.log('[fs] file', file);
39-
const start = performance.now();
40-
const hash = await fs.hashFile(file, (bytes, total) => {
41-
console.log('[fs] hashing', (bytes / total) * 100);
42-
});
43-
console.log('[fs] hash', hash, performance.now() - start);
13+
const importDirectory = useCallback(async (path = '.') => {
14+
const perfStart = performance.now();
15+
const startIn = getStartInDir(path);
16+
const dir = await fs.openDirectory({id: path, startIn, mode: 'read'});
17+
const copy = await fs.importDirectory(dir, path);
18+
console.log('[fs] import dir', dir, copy, performance.now() - perfStart);
4419
}, []);
4520

4621
return {
47-
getOpenDirectoryInit,
48-
importDirectory,
4922
importFile,
50-
hashFile,
23+
importDirectory,
5124
};
5225
}
53-

client/src/media/hooks/useInitDirectories.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import {fs} from 'react-exo/fs';
22
import {useEffect} from 'react';
3-
4-
export const INIT_DIRECTORIES = [
5-
'documents',
6-
'music',
7-
'pictures',
8-
'videos',
9-
'games',
10-
'books',
11-
'downloads',
12-
'uploads',
13-
];
3+
import {INIT_DIRECTORIES} from 'media/utils/path';
144

155
export function useInitDirectories() {
166
useEffect(() => {

client/src/media/hooks/useLists.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

client/src/media/hooks/useTasks.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)