Skip to content

Replaced paste.ee export with Android file sharing#2

Open
mkf wants to merge 26 commits intokapware:masterfrom
mkf:master
Open

Replaced paste.ee export with Android file sharing#2
mkf wants to merge 26 commits intokapware:masterfrom
mkf:master

Conversation

@mkf
Copy link

@mkf mkf commented Aug 1, 2017

No description provided.

(.catch #(js/console.log (str "err " (pr-str %)))))))
(def esteban-share (js/require "react-native-share"))
(defn share-filepath [] (.open esteban-share (clj->js {:url (str "file://" the-file-path)
;;:type "text/plain"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant comments.

(defn a-share-button [text-on on-press-func speakers]
[touchable-highlight {:on-press #(on-press-func speakers)}
[text {:style {:padding 10 :background-color "#999999" :margin-bottom 10}} text-on]])
(defn write-to-file-and-share-button [speakers] (a-share-button "Export" write-to-file-and-share speakers))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming to share-button.

;;:message "This is the file"
})))
(def write-to-file-and-share (write-to-file-fn share-filepath))
(defn a-share-button [text-on on-press-func speakers]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider inlining

(defn write-to-file-fn [what-then-fn]
(fn write-to-file [speakers] (-> speakers
rnfs-write-to-file
(.then #(do (js/console.log (str "suc " (pr-str %) "|" the-file-path))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log(s) or wrap it with goog.debug flag.

(def RNFS (js/require "react-native-fs"))
(def what-platform (keyword (str (.-OS (.-Platform ReactNative)))))
(def the-relative-file-path "auricle-saved.txt")
(def the-file-path (str (case what-platform ;;.-DocumentDirectoryPath
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing comment.

(str "There was an error writing to file: " e
" →the path: " the-file-path)
(clj->js
[{:text "Too bad" :onPress #(do)}])))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you even need :onPress here? Alert button wouldn't be enough?

:android (.-ExternalDirectoryPath RNFS)
:ios (.-LibraryDirectoryPath RNFS)) "/" the-relative-file-path))
(defn rnfs-write-to-file [speakers] (.writeFile RNFS the-file-path (str speakers) "utf8"))
(defn alert-about-write-failed [e] (.alert (.-Alert ReactNative)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alerts are typically used in the app, consider abstracting it out in a convenient function.

(def esteban-share (js/require "react-native-share"))
(defn share-filepath [] (.open esteban-share
(clj->js {:url (str "file://" the-file-path)
;;maybe setting :title or :subject (not :message) would prevent crashes
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing redundant comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants