Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: File select and opening #23

Merged
merged 38 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2f0d7fc
Implemented state and actions for opening a file
Feb 19, 2019
aa6240c
Shift-click files for multi select, arrow keys for changing opened file
Feb 25, 2019
5ff04d5
Removed the "active file", added a basic inspector component
Mar 9, 2019
cbf5f04
Click image to inspect, ctrl click for multi select
Mar 9, 2019
c4d1386
Improved info shown in inspector, made it collapsable
Mar 9, 2019
58f651f
Merged with master
Mar 9, 2019
e281511
Fix merge conflicts
hummingly Mar 30, 2019
e61932c
Center inspector image
hummingly Mar 30, 2019
28d1eba
fix error
hummingly Mar 31, 2019
b92a10e
Remove tag and file from selection when removing them
Mar 31, 2019
bfefc11
Simplify HTML structure
hummingly Mar 31, 2019
9a9861b
Merge branch 'file-select-and-opening' of https://github.com/RvanderL…
hummingly Mar 31, 2019
bfa2617
Scrolling fix
hummingly Mar 31, 2019
ad8e1d7
Remove circle selector
hummingly Apr 1, 2019
d9a30ee
Input field for adding/removing tags from selected image(s) in Inspector
Apr 2, 2019
8ce3344
Adds tag removal and extracts FileTag from FileInfo
hummingly Apr 3, 2019
61cf889
Merge and performance optimizations
Apr 3, 2019
47ed0f0
Added option to create tags in the inspector
Apr 3, 2019
4a90092
Added blueprint-select CSS, finishing up inspector tag selector
Apr 3, 2019
0ce87ff
Formatting
hummingly Apr 4, 2019
b053475
Added Toolbar component with mostly placeholder elements
Apr 4, 2019
bc31b49
Switch between outliner pages
Apr 5, 2019
2234bc4
Added (de)select all and layout popover menu
Apr 5, 2019
8406f68
Added basic Locations component, added non-functional Search componen…
Apr 6, 2019
3b695a7
Added ErrorBoundary that shows an error screen instead of a blank scr…
Apr 6, 2019
df653f7
Improved toolbar css
Apr 6, 2019
3ef9a5f
Use IDs and grid areas for the toolbar
hummingly Apr 6, 2019
dc008b4
Fixes scrollbar height
hummingly Apr 7, 2019
62ec0fd
Cleanup height
hummingly Apr 9, 2019
04753c2
Replaced Locations with Import tab, small fixes
Apr 10, 2019
f419bd2
Crash fix: Deselect files that are not tagged with any tag in the cur…
Apr 11, 2019
dec16db
Added query overview at the top of the gallery
Apr 11, 2019
c81170d
Removed selection header, replaced with toolbar actions
Apr 11, 2019
d32f54c
Always re-fetch files when tag selection is updated
Apr 11, 2019
db29500
Formatting
hummingly Apr 11, 2019
f737aa3
Merge pull request #36 from RvanderLaan/toolbar
hummingly Apr 11, 2019
61b0982
Merge master
hummingly Apr 11, 2019
68ce352
Fix tslint
hummingly Apr 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"webpack-cli": "^3.2.0"
},
"dependencies": {
"@blueprintjs/core": "^3.12.0",
"@blueprintjs/select": "^3.6.0",
"@blueprintjs/core": "^3.15.0",
"@blueprintjs/select": "^3.8.0",
"fs-extra": "^7.0.1",
"idb": "^3.0.2",
"mobx": "^5.9.0",
Expand Down
39 changes: 14 additions & 25 deletions src/renderer/frontend/App.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
import { Breadcrumbs, IBreadcrumbProps, InputGroup } from '@blueprintjs/core';
import { observer } from 'mobx-react-lite';
import React from 'react';

import FileList from './components/FileList';
import Sidebar from './components/Sidebar';
import { withRootstore, IRootStoreProp } from './contexts/StoreContext';
import Outliner from './components/Outliner';
import { IRootStoreProp, withRootstore } from './contexts/StoreContext';
import Inspector from './components/Inspector';
import Toolbar from './components/Toolbar';
import ErrorBoundary from './components/ErrorBoundary';

interface IAppProps extends IRootStoreProp {}

const App = ({ rootStore: { uiStore } }: IAppProps) => {
// Breadcrumbs placeholder
const breadcrumbs: IBreadcrumbProps[] = [
{ icon: 'symbol-square' },
{ icon: 'folder-close', text: 'Cars' },
{ icon: 'folder-close', text: 'Yellow' },
{ icon: 'document', text: 'New' },
];

const themeClass = uiStore.theme === 'DARK' ? 'bp3-dark' : 'bp3-light';

return (
<div className={`${themeClass} column`}>
<Sidebar />

<div className="main">
<div className="header">
<Breadcrumbs items={breadcrumbs} />
<div id="layoutContainer" className={`${themeClass}`}>
<ErrorBoundary>
<Toolbar />

{/* This can be replaced with the custom SearchBar component later */}
<InputGroup type="search" leftIcon="search" placeholder="Search" />
</div>
<Outliner />

<br />

<div className="gallery">
<main>
<FileList />
</div>
</div>
</main>

<Inspector />
</ErrorBoundary>
</div>
);
};
Expand Down
72 changes: 72 additions & 0 deletions src/renderer/frontend/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';
import { remote } from 'electron';
import { Button, NonIdealState, ButtonGroup, EditableText } from '@blueprintjs/core';

interface IErrorBoundaryState {
hasError: boolean;
error: string;
}

class ErrorBoundary extends React.Component<{}, IErrorBoundaryState> {
static getDerivedStateFromError(error: any) {
// Update state so the next render will show the fallback UI.
return { hasError: true, error };
}
state = {
hasError: false,
error: '',
};

componentDidCatch(error: any, info: any) {
// TODO: Send error to logging service
const stringifiedError = JSON.stringify(error, Object.getOwnPropertyNames(error), 2);
this.setState({ error: stringifiedError });
}

viewInspector() {
remote.getCurrentWebContents()
.openDevTools();
}

reloadApplication() {
remote.getCurrentWindow()
.reload();
}

render() {
const { hasError, error } = this.state;
if (hasError) {
// You can render any custom fallback UI
return (
<div className="error-boundary">
<NonIdealState
icon={<span>😞</span>}
title="Something went wrong."
description="You can try one of the following options or contact the maintainers"
action={<ButtonGroup>
<Button onClick={this.reloadApplication} icon="refresh" intent="primary">
Reload
</Button>
<Button onClick={this.viewInspector} intent="warning" icon="error">
View in DevTools
</Button>
<Button disabled intent="danger" icon="database">
Clear database
</Button>
</ButtonGroup>}
>
<EditableText
className="bp3-intent-danger bp3-monospace-text message"
value={error.toString()}
isEditing={false}
multiline
/>
</NonIdealState>
</div>
);
}
return this.props.children;
}
}

export default ErrorBoundary;
86 changes: 86 additions & 0 deletions src/renderer/frontend/components/FileInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { useEffect, useState, useMemo } from 'react';
import fs from 'fs';
import { observer } from 'mobx-react-lite';

import { ClientFile } from '../../entities/File';

const formatDate = (d: Date) =>
`${d.getUTCFullYear()}-${d.getUTCMonth() +
1}-${d.getUTCDate()} ${d.getUTCHours()}:${d.getUTCMinutes()}`;

interface IFileInfoProps {
files: ClientFile[];
}

const SingleFileInfo = observer(({ file }: { file: ClientFile }) => {
const [fileStats, setFileStats] = useState<fs.Stats | undefined>(undefined);
const [error, setError] = useState<Error | undefined>(undefined);

// Look up file info when file changes
useEffect(
() => {
fs.stat(file.path, (err, stats) =>
err ? setError(err) : setFileStats(stats),
);
},
[file],
);

// Todo: Would be nice to also add tooltips explaining what these mean (e.g. diff between dimensions & resolution)
// Or add the units: pixels vs DPI
const fileInfoList = useMemo(
() => [
{ key: 'Filename', value: file.path },
{
key: 'Created',
value: fileStats ? formatDate(fileStats.birthtime) : '...',
},
{ key: 'Modified', value: fileStats ? formatDate(fileStats.ctime) : '...' },
{
key: 'Last Opened',
value: fileStats ? formatDate(fileStats.atime) : '...',
},
{ key: 'Dimensions', value: '?' },
{ key: 'Resolution', value: '?' },
{ key: 'Color Space', value: '?' },
],
[file, fileStats],
);

return (
<section id="fileInfo">
{fileInfoList.map(({ key, value }) => [
<div key={`fileInfoKey-${key}`} className="inpectorHeading">
{key}
</div>,
<div key={`fileInfoValue-${key}`} className="fileInfoValue">
{value}
</div>,
])}

{error && (
<p>
Error: {error.name} <br /> {error.message}
</p>
)}
</section>
);
});

const MultiFileInfo = observer(({ files }: IFileInfoProps) => {
return (
<section>
<p>Selected {files.length} files</p>
</section>
);
});

const FileInfo = ({ files }: IFileInfoProps) => {
if (files.length === 1) {
return <SingleFileInfo file={files[0]} />;
} else {
return <MultiFileInfo files={files} />;
}
};

export default FileInfo;
83 changes: 26 additions & 57 deletions src/renderer/frontend/components/FileList.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,39 @@
import { remote } from 'electron';
import fse from 'fs-extra';
import path from 'path';
import React from 'react';

import React, { useCallback } from 'react';
import { observer } from 'mobx-react-lite';
import { Button } from '@blueprintjs/core';

import { withRootstore, IRootStoreProp } from '../contexts/StoreContext';
import FileStore from '../stores/FileStore';

import Gallery from './Gallery';
import FileSelectionHeader from './FileSelectionHeader';
import { Tag, ITagProps } from '@blueprintjs/core';

export interface IFileListProps extends IRootStoreProp {}

const chooseDirectory = async (fileStore: FileStore) => {
const dirs = remote.dialog.showOpenDialog({
properties: ['openDirectory', 'multiSelections'],
});

if (!dirs) {
return;
}

dirs.forEach(async (dir) => {
// Check if directory
// const stats = await fse.lstat(dirs[0]);
const imgExtensions = ['gif', 'png', 'jpg', 'jpeg'];

const filenames = await fse.readdir(dir);
const imgFileNames = filenames.filter((f) =>
imgExtensions.some((ext) =>
f.toLowerCase()
.endsWith(ext)),
);
const FileList = ({ rootStore: { uiStore, fileStore, tagStore } }: IFileListProps) => {

imgFileNames.forEach(async (filename) => {
const joinedPath = path.join(dir, filename);
console.log(joinedPath);
fileStore.addFile(joinedPath);
});
});
};

const FileList = ({ rootStore: { uiStore, fileStore } }: IFileListProps) => {
const removeSelectedFiles = async () => {
await fileStore.removeFilesById(uiStore.fileSelection);
uiStore.fileSelection.clear();
};
const handleDeselectTag = useCallback(
(_, props: ITagProps) => {
const clickedTag = tagStore.tagList.find((t) => t.id === props.id);
if (clickedTag) {
uiStore.deselectTag(clickedTag);
}
},
[],
);

return (
<div>
{uiStore.fileSelection.length > 0 && (
<FileSelectionHeader
numSelectedFiles={uiStore.fileSelection.length}
onCancel={() => uiStore.fileSelection.clear()}
onRemove={removeSelectedFiles}
/>
)}

<Button onClick={() => chooseDirectory(fileStore)} icon="folder-open">
Add images to your Visual Library
</Button>

<br />
<br />
<div className="gallery">

<div id="query-overview">
{uiStore.clientTagSelection.map((tag) => (
<Tag
key={tag.id}
id={tag.id}
intent="primary"
onRemove={handleDeselectTag}
>
{tag.name}
</Tag>),
)}
</div>

<Gallery />
</div>
Expand Down
57 changes: 0 additions & 57 deletions src/renderer/frontend/components/FileSelectionHeader.tsx

This file was deleted.

Loading