Repository: penpot/penpot
File: frontend/src/app/main/ui/workspace/tokens/modals/import.cljs (ClojureScript)

Code before:
        (mf/use-fn
         (fn [event]
           (let [files (->> (dom/get-target event)
                            (dom/get-files)
                            (filter (fn [file]
                                      (let [name (.-name file)
                                            type (.-type file)]
                                        (or
                                         (= type "application/json")
                                         (str/ends-with? name ".json"))))))]
             (->> (rx/from files)
                  (rx/mapcat (fn [file]
                               (->> (wapi/read-file-as-text file)
                                    (rx/map (fn [file-text]
                                              [(.-webkitRelativePath file)
                                               file-text])))))
                  (dwti/import-directory-stream)
                  (on-stream-imported "multiple"))

             (-> (mf/ref-val dir-input-ref)
                 (dom/set-value! "")))))

        on-zip-file-import
        (mf/use-fn
         (fn [event]
           (let [zipfile (-> (dom/get-target event)
                             (dom/get-files)
                             (first))
                 zipfile-name (str/strip-suffix (.-name zipfile) ".zip")]
             (->> (wapi/read-file-as-array-buffer zipfile)
                  (rx/mapcat (fn [file-content]
                               (let [zip-reader (uz/reader file-content)]
                                 (->> (rx/from (uz/get-entries zip-reader))
                                      (rx/mapcat
                                       (fn [entries]
                                         (->> (rx/from entries)
                                              (rx/filter (fn [entry]
                                                           (let [filename (.-filename entry)]
                                                             (str/ends-with? filename ".json"))))
                                              (rx/merge-map (fn [entry]
                                                              (let [filename (str/concat zipfile-name "/" (.-filename entry))
                                                                    content-promise (uz/read-as-text entry)]
                                                                (-> content-promise
                                                                    (.then (fn [text]
                                                                             [filename text]))
                                                                    (rx/from)))))
                                              (rx/map (fn [entry]
                                                        entry)))))
                                      (rx/finalize (partial uz/close zip-reader))))))
                  (dwti/import-directory-stream)
                  (on-stream-imported "zip"))

Review comment (suggestion):
For consitency I'd suggest name `on-import-zip-file` here and rename the following one to `on-import-json-file`.

Code after:
             nil)))

        on-import-directory
        (mf/use-fn
         (fn [event]
           (let [files (->> (dom/get-target event)
                            (dom/get-files)
                            (filter (fn [file]
                                      (let [name (.-name file)
                                            type (.-type file)]
                                        (or
                                         (= type "application/json")
                                         (str/ends-with? name ".json"))))))]
             (->> (rx/from files)
                  (rx/mapcat (fn [file]
                               (->> (wapi/read-file-as-text file)
                                    (rx/map (fn [file-text]
                                              [(.-webkitRelativePath file)
                                               file-text])))))
                  (dwti/import-directory-stream)
                  (on-stream-imported "multiple"))

             (-> (mf/ref-val dir-input-ref)
                 (dom/set-value! "")))))

        on-import-zip-file
        (mf/use-fn
         (fn [event]
           (let [zipfile (-> (dom/get-target event)
                             (dom/get-files)
                             (first))
                 zipfile-name (str/strip-suffix (.-name zipfile) ".zip")]
             (->> (wapi/read-file-as-array-buffer zipfile)
                  (rx/mapcat (fn [file-content]
                               (let [zip-reader (uz/reader file-content)]
                                 (->> (rx/from (uz/get-entries zip-reader))
                                      (rx/mapcat
                                       (fn [entries]
                                         (->> (rx/from entries)
                                              (rx/filter (fn [entry]
                                                           (let [filename (.-filename entry)]
                                                             (str/ends-with? filename ".json"))))
                                              (rx/merge-map (fn [entry]
                                                              (let [filename (str/concat zipfile-name "/" (.-filename entry))
                                                                    content-promise (uz/read-as-text entry)]
                                                                (-> content-promise
                                                                    (.then (fn [text]
                                                                             [filename text]))
                                                                    (rx/from))))))))
                                      (rx/finalize (partial uz/close zip-reader))))))
                  (dwti/import-directory-stream)