Skip to content

Commit

Permalink
fix(Walk): Display error message; Prevent 404 images
Browse files Browse the repository at this point in the history
  • Loading branch information
danactive committed Jun 21, 2020
1 parent 222b3a9 commit 6e1c74e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
4 changes: 4 additions & 0 deletions ui/app/components/OrganizePreviews/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const getListStyle = isDraggingOver => ({
});

function OrganizePreviews({ items, setItems }) {
if (items.length === 0) {
return null;
}

function onDragEnd(result) {
// dropped outside the list
if (!result.destination) {
Expand Down
4 changes: 2 additions & 2 deletions ui/app/containers/Walk/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function listingSuccess(listing) {
function listingFailure(error) {
return {
type: LIST_DIRECTORY_FAILURE,
error,
errorMsg: error.message,
};
}

Expand All @@ -44,7 +44,7 @@ function resizeSuccess() {
function resizeFailure(error) {
return {
type: RESIZE_IMAGES_FAILURE,
error,
errorMsg: error.message,
};
}

Expand Down
70 changes: 30 additions & 40 deletions ui/app/containers/Walk/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ function Walk({ location: { hash } }) {
useInjectSaga({ key: 'walk', saga });
const files = useSelector(makeSelectFiles());
const statePath = useSelector(makeSelectPath());
const [stateItems, setItems] = useState([]);
const [stateImages, setItems] = useState([]);
const qsPath = parseHash('path', hash);

useEffect(() => {
dispatch(actions.listDirectory(qsPath));
}, [qsPath]);

const loading = statePath !== qsPath;

if (loading) {
return <LoadingIndicator />;
}
const loading = statePath !== qsPath || files.length === 0;

const itemFiles = files.map(file => ({
id: file.path,
Expand All @@ -50,17 +46,25 @@ function Walk({ location: { hash } }) {
addParentDirectoryNav(itemFiles, statePath);

const itemImages = itemFiles.filter(file => isImage(file));
const hasImages = !loading && itemImages.length > 0;
const hasImages = !loading && stateImages.length > 0;

const Components = [
useEffect(() => {
setItems(itemImages);
}, [files]);

if (loading) {
return <LoadingIndicator />;
}

return [
<Helmet key="walk-Helmet">
<title>Walk</title>
<meta name="description" content="Description of Walk" />
</Helmet>,
<Menu
key="walk-Menu"
showMenu={hasImages}
imageFilenames={stateItems.map(i => i.filename)}
imageFilenames={stateImages.map(i => i.filename)}
path={statePath}
/>,
<GenericList
Expand All @@ -70,38 +74,24 @@ function Walk({ location: { hash } }) {
loading={loading}
error={false}
/>,
<OrganizePreviews
key="walk-OrganizePreviews"
setItems={setItems}
items={stateImages.map(item => ({
...item,
content: [
<span key={`label-${item.filename}`}>{item.filename}</span>,
<img
key={`thumbnail-${item.filename}`}
alt="No preview yet"
src={`http://localhost:${config.apiPort}/public/${statePath}/${item.filename}`}
width={config.resizeDimensions.preview.width}
height={config.resizeDimensions.preview.height}
/>,
],
}))}
/>,
];

if (hasImages) {
let items = itemImages;
if (stateItems.length > 0) {
items = stateItems;
} else {
setItems(itemImages);
}

Components.push(
<OrganizePreviews
key="walk-OrganizePreviews"
items={items.map(item => ({
...item,
content: [
<span key={`label-${item.filename}`}>{item.filename}</span>,
<img
key={`thumbnail-${item.filename}`}
alt="No preview yet"
src={`http://localhost:${config.apiPort}/public/${statePath}/${item.filename}`}
width={config.resizeDimensions.preview.width}
height={config.resizeDimensions.preview.height}
/>,
],
}))}
setItems={setItems}
/>,
);
}

return Components;
}

export default Walk;

0 comments on commit 6e1c74e

Please sign in to comment.