GithubHelp home page GithubHelp logo

mpizenberg / elm-file Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 0.0 10 KB

Alternative to elm/file that can be encoded and passed through ports

License: BSD 3-Clause "New" or "Revised" License

Elm 100.00%

elm-file's People

Contributors

mpizenberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

elm-file's Issues

Files during `onOver` dragging do not contain readable data

While using FileValue.onDrop function, a set of properties must be given as a parameter :

dropConfig = { onOver, onDrop, onLeave }

Each of those is a function taking as parameters a file and a list of file.
I have no trouble reading the content of the files for the onDropfunction, but while using the onOver function and writing in my logs the content of the file being dragged over, I get the following result :

{ lastModified = Posix 0
, mime = "text/plain"
, name = "If you see this file, please report an error at https://github.com/mpizenberg/elm-files/issues"
, size = 0
, value = <internals> }

Here is the exact piece of code giving me this result :

ฬ€```elm

 let
    extensionRegex : Regex.Regex
    extensionRegex = Maybe.withDefault Regex.never <| Regex.fromString "*\\.csv"

    extension : String -> Bool
    extension fileName =
        Regex.contains extensionRegex fileName
in
List.map Element.htmlAttribute
    (File.onDrop
        -- /!\ Cannot work with file.mime string for onOver,
        --     as it seems to always be "text/plain"
        { onOver = \file otherFiles -> 
            if extension (Debug.log "name:" file).name then
                DragDropLightsMsg DragOverLights
            else
                DragDropImagesMsg DragOverImages
            -- (case Debug.log "mime:" file.mime of
            -- "text/csv" ->
            --     DragDropLightsMsg DragOverLights
            -- "text/plain" ->
            --     DragDropLightsMsg DragOverLights
            -- "image/*" ->
            --     DragDropImagesMsg DragOverImages
            -- _ ->
            --     ClearLogs
            -- )
        , onDrop = \file otherFiles ->
            (case file.mime of
            "text/csv" ->
                DragDropLightsMsg (DropLights file)
            _ ->
                DragDropImagesMsg (DropImages file otherFiles)
            )
        , onLeave = Just { id = "FileDropArea", msg = DragDropImagesMsg DragLeaveImages }
        }
    )


## Reproductibility :

I have tried the following browsing tools :
[x] Firefox
[x] Chrome
[ ] Explorer
[ ] Opera

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.