-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Walk): Display image filename in OrganizePreviews
- Loading branch information
Showing
12 changed files
with
206 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { useState } from 'react'; | ||
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd'; | ||
|
||
// a little function to help us with reordering the result | ||
const reorder = (list, startIndex, endIndex) => { | ||
const result = Array.from(list); | ||
const [removed] = result.splice(startIndex, 1); | ||
result.splice(endIndex, 0, removed); | ||
|
||
return result; | ||
}; | ||
|
||
const grid = 8; | ||
|
||
const getItemStyle = (isDragging, draggableStyle) => ({ | ||
// some basic styles to make the items look a bit nicer | ||
userSelect: 'none', | ||
padding: grid * 2, | ||
margin: `0 0 ${grid}px 0`, | ||
|
||
// change background colour if dragging | ||
background: isDragging ? 'lightgreen' : 'grey', | ||
|
||
// styles we need to apply on draggables | ||
...draggableStyle, | ||
}); | ||
|
||
const getListStyle = (isDraggingOver) => ({ | ||
background: isDraggingOver ? 'lightblue' : 'lightgrey', | ||
padding: grid, | ||
width: 250, | ||
}); | ||
|
||
function OrganizePreviews({ items: initialItems }) { | ||
const [items, setItems] = useState(initialItems); | ||
|
||
function onDragEnd(result) { | ||
// dropped outside the list | ||
if (!result.destination) { | ||
return; | ||
} | ||
|
||
setItems(reorder( | ||
items, | ||
result.source.index, | ||
result.destination.index, | ||
)); | ||
} | ||
|
||
return ( | ||
<DragDropContext onDragEnd={onDragEnd}> | ||
<Droppable droppableId="droppable"> | ||
{(providedDrop, snapshotDrop) => ( | ||
<div | ||
{...providedDrop.droppableProps} | ||
ref={providedDrop.innerRef} | ||
style={getListStyle(snapshotDrop.isDraggingOver)} | ||
> | ||
{items.map((item, index) => ( | ||
<Draggable key={item.id} draggableId={item.id} index={index}> | ||
{(providedDrag, snapshotDrag) => ( | ||
<div | ||
ref={providedDrag.innerRef} | ||
{...providedDrag.draggableProps} | ||
{...providedDrag.dragHandleProps} | ||
style={getItemStyle( | ||
snapshotDrag.isDragging, | ||
providedDrag.draggableProps.style, | ||
)} | ||
> | ||
{item.content} | ||
</div> | ||
)} | ||
</Draggable> | ||
))} | ||
{providedDrop.placeholder} | ||
</div> | ||
)} | ||
</Droppable> | ||
</DragDropContext> | ||
); | ||
} | ||
|
||
export default OrganizePreviews; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: '../../../../test.eslintrc.js', | ||
}; |
24 changes: 24 additions & 0 deletions
24
ui/app/components/OrganizePreviews/tests/index.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
|
||
import OrganizePreviews from '../index'; | ||
|
||
export default { | ||
title: 'OrganizePreviews', | ||
component: OrganizePreviews, | ||
}; | ||
|
||
export const OrganizePreviewStories = () => { | ||
// fake data generator | ||
const getItems = (count) => Array.from({ length: count }, (v, k) => k).map((k) => ({ | ||
id: `item-${k}`, | ||
content: `item ${k + 1}`, | ||
})); | ||
|
||
return ( | ||
<OrganizePreviews items={getItems(7)} /> | ||
); | ||
}; | ||
|
||
OrganizePreviewStories.story = { | ||
name: 'with text', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
const config = require('../../../../config.json'); | ||
|
||
function areImages(file) { | ||
function isImage(file) { | ||
return (file.mediumType === 'image' && config.supportedFileTypes.photo.includes(file.ext.toLowerCase())); | ||
} | ||
|
||
export default { | ||
areImages, | ||
isImage, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.