From 381fc8ef5ad7607e52e4ead7ecce73f0b2f7ef47 Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 22 Dec 2021 23:55:50 -0800 Subject: [PATCH 1/2] this commit is OLD, been on my pc for months --- package.json | 4 +- src-tauri/Cargo.lock | 4 +- src-tauri/Cargo.toml | 4 +- src-tauri/src/commands.rs | 19 +- src-tauri/src/jobs/job.rs | 28 + src-tauri/src/jobs/mod.rs | 1 + src-tauri/swift-lib/Package.resolved | 4 +- src-tauri/swift-lib/Package.swift | 2 +- src/App.tsx | 10 +- src/Debug.tsx | 2 +- src/assets/svg/drive.svg | 0 src/components/file/FileList.tsx | 95 +- src/components/file/Inspector.tsx | 2 +- src/components/file/Sidebar.tsx | 15 +- src/components/layout/TopBar.tsx | 21 +- src/screens/Overview.tsx | 36 + src/screens/Spaces.tsx | 9 + src/store/{app.ts => global.ts} | 0 src/style.css | 5 +- yarn-error.log | 34 +- yarn.lock | 1466 ++++++++++++++------------ 21 files changed, 956 insertions(+), 805 deletions(-) create mode 100644 src-tauri/src/jobs/job.rs create mode 100644 src-tauri/src/jobs/mod.rs create mode 100644 src/assets/svg/drive.svg create mode 100644 src/screens/Overview.tsx create mode 100644 src/screens/Spaces.tsx rename src/store/{app.ts => global.ts} (100%) diff --git a/package.json b/package.json index e4f2a1c2a..634f6f4be 100644 --- a/package.json +++ b/package.json @@ -50,9 +50,7 @@ "react-hotkeys-hook": "^3.4.4", "react-router-dom": "^5.2.0", "react-spline": "^1.2.1", - "react-virtualized": "^9.22.3", - "react-virtualized-auto-sizer": "^1.0.6", - "react-window": "^1.8.6", + "react-virtuoso": "^2.2.6", "rooks": "^5.7.1", "tailwindcss": "^2.2.16", "vite": "^2.4.4", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 10f919f71..763e682d2 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4115,9 +4115,9 @@ dependencies = [ [[package]] name = "swift-rs" -version = "0.1.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e56047444883f07ced9a621d23c8af8c7a3bbdafc16e02e00f4799943002e20" +checksum = "429fcb93ca0ca9c60efba60a7f842254781c60d3e006f716c731e9901094c87e" dependencies = [ "base64", "serde", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 74f46cbd8..f5250e1d3 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -11,7 +11,7 @@ build = "src/build.rs" [build-dependencies] tauri-build = { version = "1.0.0-beta.3" } -swift-rs = "0.1.0" +swift-rs = "0.2.2" [dependencies] tauri = { version = "1.0.0-beta.8", features = ["api-all"] } @@ -44,7 +44,7 @@ log = "0.4.14" objc = "0.2.7" cocoa = "0.24.0" objc-foundation = "0.1.1" -swift-rs = "0.1.0" +swift-rs = "0.2.2" base64 = "0.13.0" [features] diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index ccded5b12..a5a156b0f 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -68,12 +68,13 @@ pub fn get_mounts() -> Result, String> { Ok(swift::get_mounts().unwrap()) } -#[tauri::command] +#[tauri::command(async)] pub async fn get_thumbs_for_directory(window: tauri::Window, path: &str) -> Result<(), String> { let config = config::get_config(); let dir = filesystem::retrieve::get_dir_with_contents(&path).await?; + // iterate over directory contents for file in dir.contents.into_iter() { - // let now = Instant::now(); + let now = Instant::now(); let icon_name = format!( "{}.png", if file.is_dir { @@ -82,17 +83,21 @@ pub async fn get_thumbs_for_directory(window: tauri::Window, path: &str) -> Resu file.extension } ); - let icon_path = config.file_type_thumb_dir.join(icon_name); - + // extract metadata from file let existing = fs::metadata(&icon_path).is_ok(); - + // write thumbnail only if if !existing { + // call swift to get thumbnail data let thumbnail_b64 = get_file_thumbnail_base64(&file.uri).to_string(); - fs::write(&icon_path, base64::decode(thumbnail_b64).unwrap()).expect("Unable to write file") + fs::write( + &icon_path, + base64::decode(thumbnail_b64).unwrap_or_default(), + ) + .map_err(|_| "thumb_cache_failure")?; } + println!("cached thumb {:?} in {:?}", file.id, now.elapsed()); - // println!("got thumb {:?} in {:?}", file.id, now.elapsed()); if !existing { reply( &window, diff --git a/src-tauri/src/jobs/job.rs b/src-tauri/src/jobs/job.rs new file mode 100644 index 000000000..773a7079c --- /dev/null +++ b/src-tauri/src/jobs/job.rs @@ -0,0 +1,28 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +pub enum Action { + SCAN_DIR, + ENCRYPT_FILE, + UPLOAD_FILE, +} + +// A job is triggered by a user interaction or schedule +#[derive(Serialize, Deserialize)] +pub struct Job { + pub id: String, + pub client_id: String, + pub storage_device_id: Option, + pub uri: Option, + pub action: Action, + pub status: String, + pub complete: bool, +} + +// // A task is a way to track the completion of a portion of a job +// // usually specific +// #[derive(Serialize, Deserialize)] +// pub struct Task { +// pub id: String, +// pub job_id: String, +// } diff --git a/src-tauri/src/jobs/mod.rs b/src-tauri/src/jobs/mod.rs new file mode 100644 index 000000000..5f07af7cc --- /dev/null +++ b/src-tauri/src/jobs/mod.rs @@ -0,0 +1 @@ +pub mod jobs; diff --git a/src-tauri/swift-lib/Package.resolved b/src-tauri/swift-lib/Package.resolved index e36fa4754..7a3a38dc9 100644 --- a/src-tauri/swift-lib/Package.resolved +++ b/src-tauri/swift-lib/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/Brendonovich/swift-rs", "state": { "branch": null, - "revision": "196359dfb25a9520d534655c1321150e36c1b1dd", - "version": "0.1.0" + "revision": "11185f93d4a2d889390538676aba8c1b64981964", + "version": "0.2.2" } } ] diff --git a/src-tauri/swift-lib/Package.swift b/src-tauri/swift-lib/Package.swift index 6d724cb79..02407b9a7 100644 --- a/src-tauri/swift-lib/Package.swift +++ b/src-tauri/swift-lib/Package.swift @@ -18,7 +18,7 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), - .package(name: "SwiftRs", url: "https://github.com/Brendonovich/swift-rs", from: "0.1.0") + .package(name: "SwiftRs", url: "https://github.com/Brendonovich/swift-rs", from: "0.2.2") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/src/App.tsx b/src/App.tsx index 7e5233a39..31d5cc3e5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,13 +8,15 @@ import { ExplorerScreen } from './screens/Explorer'; import { invoke } from '@tauri-apps/api'; import { DebugGlobalStore } from './Debug'; import { useGlobalEvents } from './hooks/useGlobalEvents'; -import { AppState, useAppState } from './store/app'; +import { AppState, useAppState } from './store/global'; import { Modal } from './components/layout/Modal'; import { useKey, useKeyBindings } from 'rooks'; // import { useHotkeys } from 'react-hotkeys-hook'; import { ErrorBoundary, FallbackProps } from 'react-error-boundary'; import { Button } from './components/primative'; import { useLocationStore, Location } from './store/locations'; +import { OverviewScreen } from './screens/Overview'; +import { SpacesScreen } from './screens/Spaces'; function ErrorFallback({ error, resetErrorBoundary }: FallbackProps) { return ( @@ -69,6 +71,12 @@ export default function App() { + + + + + + diff --git a/src/Debug.tsx b/src/Debug.tsx index c2d661ca8..b967f5095 100644 --- a/src/Debug.tsx +++ b/src/Debug.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useAppState } from './store/app'; +import { useAppState } from './store/global'; import { useExplorerStore } from './store/explorer'; export function DebugGlobalStore() { diff --git a/src/assets/svg/drive.svg b/src/assets/svg/drive.svg new file mode 100644 index 000000000..e69de29bb diff --git a/src/components/file/FileList.tsx b/src/components/file/FileList.tsx index 4aae83eba..9dcaf9d81 100644 --- a/src/components/file/FileList.tsx +++ b/src/components/file/FileList.tsx @@ -4,12 +4,12 @@ import { convertFileSrc } from '@tauri-apps/api/tauri'; import clsx from 'clsx'; import byteSize from 'pretty-bytes'; import React, { forwardRef, useEffect, useMemo, useRef } from 'react'; -import AutoSizer from 'react-virtualized-auto-sizer'; -import { FixedSizeList as List } from 'react-window'; +import { Virtuoso, VirtuosoHandle } from 'react-virtuoso'; + import { useKey, useWindowSize } from 'rooks'; import { DirectoryResponse } from '../../screens/Explorer'; // import { List, ListRowRenderer } from 'react-virtualized'; -import { useAppState } from '../../store/app'; +import { useAppState } from '../../store/global'; import { useCurrentDir, useExplorerStore, @@ -43,7 +43,7 @@ type ColumnKey = typeof columns[number]['key']; export const FileList: React.FC<{}> = (props) => { const tableContainer = useRef(null); - const VList = useRef(null); + const VList = useRef(null); const currentDir = useCurrentDir(); // useOnWindowResize((e) => { @@ -56,7 +56,8 @@ export const FileList: React.FC<{}> = (props) => { const seletedRowIndex = useSelectedFileIndex(currentDir?.id as number); useEffect(() => { - if (seletedRowIndex != null) VList.current?.scrollToItem(seletedRowIndex); + // VList.current?.scrollIntoView() + if (seletedRowIndex != null) VList.current?.scrollIntoView({ index: seletedRowIndex }); }, [seletedRowIndex]); useKey('ArrowUp', (e) => { @@ -71,47 +72,32 @@ export const FileList: React.FC<{}> = (props) => { explorer.selectFile(explorer.currentDir as number, explorer.selectedFile.id, 'below'); }); - const listInnerElement = forwardRef(({ style, ...rest }, ref) => ( -
-
-

{currentDir?.name}

-
-
- {columns.map((col) => ( -
- - {col.column} -
- ))} -
-
-
- {rest.children} -
- )); - - const Row = ({ index, key, style }: any) => { + const Row = (index: number) => { const row = currentDir?.children?.[index] as IFile; - return ( -
- -
- ); + return ; }; + const Header = () => ( +
+

{currentDir?.name}

+
+
+ {columns.map((col) => ( +
+ + {col.column} +
+ ))} +
+
+
+ ); + return useMemo( () => (
= (props) => { style={{ marginTop: -44 }} className="table-container w-full h-full bg-white dark:bg-gray-900 p-3 cursor-default" > - - {({ width, height }) => ( - - {Row} - - )} - +
), [size.innerWidth, currentDir?.id, tableContainer.current] diff --git a/src/components/file/Inspector.tsx b/src/components/file/Inspector.tsx index 61b09520a..7205e444a 100644 --- a/src/components/file/Inspector.tsx +++ b/src/components/file/Inspector.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { useExplorerStore, useSelectedFile } from '../../store/explorer'; import { Transition } from '@headlessui/react'; import { IFile } from '../../types'; -import { useAppState } from '../../store/app'; +import { useAppState } from '../../store/global'; import { convertFileSrc } from '@tauri-apps/api/tauri'; import moment from 'moment'; import { Button } from '../primative'; diff --git a/src/components/file/Sidebar.tsx b/src/components/file/Sidebar.tsx index 2171b6774..824e10346 100644 --- a/src/components/file/Sidebar.tsx +++ b/src/components/file/Sidebar.tsx @@ -67,16 +67,13 @@ const Heading: React.FC<{}> = ({ children }) => ( export const Sidebar: React.FC = (props) => { const locations = useLocations(); - - console.log({ locations }); - return ( -
+
} @@ -91,6 +88,10 @@ export const Sidebar: React.FC = (props) => { />
+ + + Overview + Spaces @@ -117,9 +118,9 @@ export const Sidebar: React.FC = (props) => { )} diff --git a/src/components/layout/TopBar.tsx b/src/components/layout/TopBar.tsx index cb47fe2dc..41eeca381 100644 --- a/src/components/layout/TopBar.tsx +++ b/src/components/layout/TopBar.tsx @@ -1,15 +1,4 @@ -import { - ChevronLeftIcon, - ChevronRightIcon, - CogIcon, - HomeIcon, - ViewBoardsIcon, - ViewGridIcon, - ViewListIcon, - CloudIcon, - FolderAddIcon, - TagIcon -} from '@heroicons/react/outline'; +import { ChevronLeftIcon, ChevronRightIcon, CogIcon } from '@heroicons/react/outline'; import clsx from 'clsx'; import { ArrowsLeftRight, @@ -29,6 +18,7 @@ import { Button, ButtonProps, Input } from '../primative'; import { Shortcut } from '../primative/Shortcut'; import { DefaultProps } from '../primative/types'; import { appWindow } from '@tauri-apps/api/window'; +import { HeartIcon } from '@heroicons/react/solid'; export interface TopBarProps extends DefaultProps {} export interface TopBarButtonProps extends ButtonProps { @@ -44,7 +34,7 @@ const TopBarButton: React.FC = ({ icon: Icon, ...props }) => )} diff --git a/src/components/layout/TopBar.tsx b/src/components/layout/TopBar.tsx index cb47fe2dc..41eeca381 100644 --- a/src/components/layout/TopBar.tsx +++ b/src/components/layout/TopBar.tsx @@ -1,15 +1,4 @@ -import { - ChevronLeftIcon, - ChevronRightIcon, - CogIcon, - HomeIcon, - ViewBoardsIcon, - ViewGridIcon, - ViewListIcon, - CloudIcon, - FolderAddIcon, - TagIcon -} from '@heroicons/react/outline'; +import { ChevronLeftIcon, ChevronRightIcon, CogIcon } from '@heroicons/react/outline'; import clsx from 'clsx'; import { ArrowsLeftRight, @@ -29,6 +18,7 @@ import { Button, ButtonProps, Input } from '../primative'; import { Shortcut } from '../primative/Shortcut'; import { DefaultProps } from '../primative/types'; import { appWindow } from '@tauri-apps/api/window'; +import { HeartIcon } from '@heroicons/react/solid'; export interface TopBarProps extends DefaultProps {} export interface TopBarButtonProps extends ButtonProps { @@ -44,7 +34,7 @@ const TopBarButton: React.FC = ({ icon: Icon, ...props }) =>