Compare commits
2 Commits
06f94fe27e
...
f618d1442c
Author | SHA1 | Date | |
---|---|---|---|
|
f618d1442c | ||
|
39e4751a9d |
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
|
@ -339,6 +339,7 @@ dependencies = [
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"uuid 1.3.0",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ walkdir = "2.3.2"
|
||||||
serde_repr = "0.1.10"
|
serde_repr = "0.1.10"
|
||||||
tokio = { version = "1.23.1", features = ["full"] }
|
tokio = { version = "1.23.1", features = ["full"] }
|
||||||
image = "0.24.5"
|
image = "0.24.5"
|
||||||
|
uuid = "1.3.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||||
|
|
|
@ -4,6 +4,7 @@ use walkdir::WalkDir;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct FileItem {
|
pub struct FileItem {
|
||||||
|
pub id: String,
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
|
@ -19,6 +20,7 @@ pub fn scan_directory(target: String) -> Result<Vec<FileItem>, String> {
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
let (width, height) = image::image_dimensions(f.path())?;
|
let (width, height) = image::image_dimensions(f.path())?;
|
||||||
Ok(FileItem {
|
Ok(FileItem {
|
||||||
|
id: uuid::Uuid::new_v4().to_string(),
|
||||||
filename: f
|
filename: f
|
||||||
.path()
|
.path()
|
||||||
.file_name()
|
.file_name()
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
//@ts-nocheck
|
//@ts-nocheck
|
||||||
import { Box } from '@mantine/core';
|
import { Box } from '@mantine/core';
|
||||||
import { equals } from 'ramda';
|
import { equals, head } from 'ramda';
|
||||||
import { FC, useLayoutEffect } from 'react';
|
import { FC, useLayoutEffect, useMemo } from 'react';
|
||||||
import { useMeasure } from 'react-use';
|
import { useMeasure, useUpdate } from 'react-use';
|
||||||
|
import { sortedFilesSelector, useFileListStore } from '../states/files';
|
||||||
import { useZoomState } from '../states/zoom';
|
import { useZoomState } from '../states/zoom';
|
||||||
import { ContinuationView } from './ContinuationView';
|
import { ContinuationView } from './ContinuationView';
|
||||||
import { SingleView } from './SingleView';
|
import { SingleView } from './SingleView';
|
||||||
|
|
||||||
export const ComicView: FC = () => {
|
export const ComicView: FC = () => {
|
||||||
|
const forceUpdate = useUpdate();
|
||||||
|
const files = useFileListStore(sortedFilesSelector());
|
||||||
const viewMode = useZoomState.use.viewMode();
|
const viewMode = useZoomState.use.viewMode();
|
||||||
const updateViewHeight = useZoomState.use.updateViewHeight();
|
const updateViewHeight = useZoomState.use.updateViewHeight();
|
||||||
const [containerRef, { height }] = useMeasure();
|
const [containerRef, { height }] = useMeasure();
|
||||||
|
const firstFileId = useMemo(() => head(files)?.id ?? '', [files, files.length]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
updateViewHeight(height);
|
updateViewHeight(height);
|
||||||
|
@ -19,7 +23,7 @@ export const ComicView: FC = () => {
|
||||||
return (
|
return (
|
||||||
<Box w="100%" h="100%" sx={{ overflow: 'hidden' }} ref={containerRef}>
|
<Box w="100%" h="100%" sx={{ overflow: 'hidden' }} ref={containerRef}>
|
||||||
{equals(viewMode, 'single') && <SingleView />}
|
{equals(viewMode, 'single') && <SingleView />}
|
||||||
{equals(viewMode, 'continuation') && <ContinuationView />}
|
{equals(viewMode, 'continuation') && <ContinuationView key={firstFileId} />}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@ export const ContinuationView: FC = () => {
|
||||||
},
|
},
|
||||||
[files]
|
[files]
|
||||||
);
|
);
|
||||||
|
const fileHeights = useMemo(() => map(item => item.height * (zoom / 100), files), [files, zoom]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ebus?.addListener('navigate_offset', ({ filename }) => {
|
ebus?.addListener('navigate_offset', ({ filename }) => {
|
||||||
|
@ -48,7 +49,8 @@ export const ContinuationView: FC = () => {
|
||||||
<VariableSizeList
|
<VariableSizeList
|
||||||
itemData={files}
|
itemData={files}
|
||||||
itemCount={fileCount}
|
itemCount={fileCount}
|
||||||
itemSize={index => files[index].height * (zoom / 100)}
|
itemSize={index => fileHeights[index]}
|
||||||
|
itemKey={index => files[index].id}
|
||||||
height={viewHeight}
|
height={viewHeight}
|
||||||
width="100%"
|
width="100%"
|
||||||
ref={virtualListRef}
|
ref={virtualListRef}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export type FileItem = {
|
export type FileItem = {
|
||||||
sort: number;
|
sort: number;
|
||||||
|
id: string;
|
||||||
filename: string;
|
filename: string;
|
||||||
path: string;
|
path: string;
|
||||||
width: number;
|
width: number;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user