Giter VIP home page Giter VIP logo

Comments (9)

JakeSidSmith avatar JakeSidSmith commented on May 24, 2024

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.

JakeSidSmith avatar JakeSidSmith commented on May 24, 2024

@maticzav any more info you could provide on this?

from react-reorder.

maticzav avatar maticzav commented on May 24, 2024

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))

ab

from react-reorder.

JakeSidSmith avatar JakeSidSmith commented on May 24, 2024

@maticzav are you sure you've opened this issue against the correct repo?

https://github.com/clauderic/react-sortable-hoc

from react-reorder.

maticzav avatar maticzav commented on May 24, 2024

aaah s**t haha, thank you!

from react-reorder.

JakeSidSmith avatar JakeSidSmith commented on May 24, 2024

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?

@maticzav

from react-reorder.

maticzav avatar maticzav commented on May 24, 2024

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.

JakeSidSmith avatar JakeSidSmith commented on May 24, 2024

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.

@maticzav

from react-reorder.

maticzav avatar maticzav commented on May 24, 2024

That sounds so cool. I am definetly going to check v3 out 😄

from react-reorder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.