Comments (9)
That's odd, I would have thought they'd be cached. And using a key
should prevent this. Is the img
the root element? Perhaps wrapping in a div
or something might fix this?
In what browser(s) is this an issue?
from react-reorder.
@maticzav any more info you could provide on this?
from react-reorder.
Hey @JakeSidSmith, I though it might be best if I just give you my implementation and a video of how it works, hope you find it in a snap, as I suppose it must be a simple mistake I made.
Actually I am sorry that I included so much of code, but I wasn't completely sure where the problem might lie, as I have already fixed some lags, but this one wasn't fixed.
/* eslint new-cap: 0 */
import React from 'react'
import { connect } from 'react-redux'
import { graphql, compose } from 'react-apollo'
// Components
import { SortableContainer, SortableElement } from 'react-sortable-hoc'
import Link from 'next/link'
import File from 'components/file'
// GraphQL
import { requestQuery } from 'lib/apollo/queries'
import { createDocumentMutation } from 'lib/apollo/mutations'
// HOCs
import withLoading from 'hocs/withLoading'
// Redux
import * as msg from 'lib/redux/actions'
const mapStateToProps = state => ({
description: state.upload.description,
files: state.upload.files,
loading: state.upload.uploading,
uploaded: state.upload.uploaded,
error: state.upload.error
})
const mapDispatchToProps = dispatch => ({
changeDescription: e => dispatch(msg.changeDescription(e.target.value)),
uploadFiles: e => dispatch(msg.uploadFiles([...e.target.files])),
removeFile: file => dispatch(msg.removeFile(file)),
reorderFiles: ({ oldIndex, newIndex }) => dispatch(msg.reorderFiles(oldIndex, newIndex)),
upload: payload => dispatch(msg.uploadDocument(payload))
})
// Helpers
const getFileKey = file => `${file.name}-${file.lastModified}`
// Helper components
const Request = withLoading(({ description, request, onChange }) => (
<div className="container">
<div className="row justify-content-center">
<div className="col-10 col-md-8">
<blockquote>
<p className="blockquote blockquote-primary">
<p>
Opis naj vsebuje celotno ime profesorja ali profesorice, letnik,
predmet, test v letu in kakršne koli posebnosti.
</p>
<b className="h4">
Sestavi opis tako kot boš ti iskal druge teste!
</b>
</p>
</blockquote>
</div>
</div>
<br/>
<div className="row justify-content-center">
<div className="col-11">
<textarea className="form-control h2" rows={3} value={description || (request && request.description) || description} onChange={onChange} placeholder="Opiši... (1. letnik, 2.test, Prof Šefe, Matematika)"/>
</div>
</div>
</div>
))
const SortableFile = SortableElement(({ file }) => (
<div className="col-12 col-md-6 col-lg-4 align-items-center square cursor-pointer">
<div className="square-content">
<File contentType={file.contentType} src={file.url} loading={!file.url} error={file.error}/>
</div>
</div>
))
const SortableList = SortableContainer(({ files, onRemove }) => (
<div className="row">
{ files.sort((a, b) => a.order - b.order).map(file => (
<SortableFile key={getFileKey(file)} index={file.order} file={file} onRemove={onRemove}/>
))}
</div>
))
// Container
const UploadForm = ({ request, loadingRequest, loadingError, description, changeDescription, files, uploadFiles, removeFile, reorderFiles, submit, uploaded }) => {
const hasFiles = files.length > 0 && files.every(file => file.url !== undefined)
const hasDescription = (request && request.description) || description.trim().length > 10
const isValid = hasFiles && hasDescription
return (
<section>
<header className="container">
<div className="row justify-content-center">
<div className="col-11">
<br/>
<h2 className="title">Naloži</h2>
</div>
</div>
</header>
<br/>
{ !uploaded && <Request description={description} request={request} onChange={changeDescription} loading={loadingRequest} error={loadingError}/> }
{ uploaded && (
<div className="container">
<div className="row justify-content-center">
<h3>Uspešno naloženo!</h3>
</div>
<div className="row justify-content-center">
<Link href="/" prefetch>
<a className="col-8 col-md-3 col-lg-2 btn btn-lg btn-round btn-success h4">Domov</a>
</Link>
</div>
</div>
)}
<br/>
{ !loadingRequest && !uploaded && (
<div className="container">
<div className="row justify-content-center">
<div className="col-10 col-md-8">
<blockquote>
<p className="blockquote blockquote-primary title">
<p>
Uredi slike v pravilen vrstni red!
</p>
<b>
Slike urediš tako da <b>podržiš prst</b> in jih pomakneš na pravo mesto.
</b>
</p>
</blockquote>
</div>
</div>
<br/>
<SortableList files={files} onRemove={removeFile} onSortEnd={reorderFiles} axis="xy" pressDelay={200}/>
<br/>
<div className="row justify-content-center">
<label className="btn btn-icon btn-lg btn-primary btn-round btn-file mx-2">
<input type="file" onChange={uploadFiles} multiple accept="image/*"/>
<i className="fa fa-plus"/>
</label>
{ isValid && (
<label className="btn btn-icon btn-lg btn-success btn-round mx-2" onClick={submit}>
<i className="fa fa-check"/>
</label>
)}
</div>
<br/>
<br/>
</div>
)}
</section>
)
}
export default compose(
connect(mapStateToProps, mapDispatchToProps),
graphql(requestQuery, {
skip: ({ requestId }) => !requestId,
options: ({ requestId }) => ({ variables: { requestId } }),
props: ({ data: { loading, error, Request } }) => ({
loadingRequest: loading,
request: Request,
loadingError: error
})
}),
graphql(createDocumentMutation, {
name: 'createDocumentMutation',
props: ({ createDocumentMutation, ownProps }) => ({
submit: () => {
console.log(ownProps)
const { description, request, requestId, userId: authorId, upload } = ownProps
const files = ownProps.files.map(file => ({
fileId: file.id,
order: file.order
}))
const description_ = description.trim() || request.description
const payload = createDocumentMutation({ variables: { description: description_, requestId, authorId, files } })
return upload(payload)
}
})
})
)(withLoading(UploadForm))
from react-reorder.
@maticzav are you sure you've opened this issue against the correct repo?
https://github.com/clauderic/react-sortable-hoc
from react-reorder.
aaah s**t haha, thank you!
from react-reorder.
No problem. XD
Out of interest, if this package didn't have the flashing images issue, would you consider switching too it?
Any features that I currently don't have that you require?
from react-reorder.
Yes, of course. User experience is always first 😄, but I still love HOC approach better, as it feels more natural to me.
Actually I am not completely sure why I chose react-sortable-hoc
over react-reorder
, I suppose it was because demos are more engaging? 😅 I think I actually used this in one of my other projects, can't remember though.
from react-reorder.
Ah, kay. Well once I release the new version (v3) I'll be updating the demos, and they are already looking a lot nicer. Have a multi list kanban style demo. 🙂
May consider adding animations for reordering also, but worried about performance implications.
from react-reorder.
That sounds so cool. I am definetly going to check v3 out 😄
from react-reorder.
Related Issues (20)
- Unable to make 3.0.0-alpha.7 work with react 16.9 HOT 5
- Less performant deeper in the dom? HOT 1
- Please add events on "drag start" and "drag end" HOT 3
- Can't disable auto scroll HOT 7
- Another complete re-write in TypeScript, with hooks, React 16-17 support, and more HOT 4
- can't reorder
- TypeError: this.state.draggedStyle is null HOT 2
- Update PropTypes HOT 1
- Warning: This synthetic event is reused for performance reasons. HOT 3
- placeholder class is not added when dragging input fields HOT 3
- Overriding sorting behavior HOT 10
- V3 Alpha Issues HOT 47
- Warning with react 15.5.0 HOT 12
- can't control dragged div HOT 17
- Error: Expected reorderId to be a string. Instead got undefined HOT 12
- Tidy up prop documentation in readme (v3) HOT 2
- Support React v16 HOT 11
- Issues with embedded images? HOT 6
- Unable to set reorder to a button HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-reorder.