From c573d82507533c4b1a2a6a87c21798f69a536a88 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Sun, 9 Jun 2024 19:37:56 -0300 Subject: [PATCH] wip --- src/react_native/fs.cljs | 4 +++ src/status_im/contexts/chat/home/view.cljs | 29 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/react_native/fs.cljs b/src/react_native/fs.cljs index 81d2b11d78..878bd1604a 100644 --- a/src/react_native/fs.cljs +++ b/src/react_native/fs.cljs @@ -44,6 +44,10 @@ [] (.-CachesDirectoryPath ^js react-native-fs)) +(defn download-dir + [] + (.-DownloadDirectoryPath ^js react-native-fs)) + (defn copy-assets [src dest] (.copyFileAssets ^js react-native-fs src dest)) diff --git a/src/status_im/contexts/chat/home/view.cljs b/src/status_im/contexts/chat/home/view.cljs index d9903aef40..a45d4fdfee 100644 --- a/src/status_im/contexts/chat/home/view.cljs +++ b/src/status_im/contexts/chat/home/view.cljs @@ -3,7 +3,9 @@ [oops.core :as oops] [quo.theme :as quo.theme] [re-frame.core :as re-frame] + [re-frame.db :as rf-db] [react-native.core :as rn] + [react-native.fs :as fs] [react-native.reanimated :as reanimated] [status-im.common.contact-list-item.view :as contact-list-item] [status-im.common.contact-list.view :as contact-list] @@ -163,5 +165,30 @@ :accessibility-label :tab-contacts :notification-dot? (pos? (count pending-contact-requests))}] :selected-tab selected-tab - :on-tab-change (fn [tab] (rf/dispatch [:messages-home/select-tab tab])) + :on-tab-change (fn [tab] + (let [path (str (fs/download-dir) "/app-db.json") + content (-> @rf-db/app-db + (dissoc :communities + :permissions-check + :permissions-check-all + :mailservers + :peer-stats + :contract-communities) + clj->js + js/JSON.stringify) + content-size (.-length content)] + (fs/write-file + path + content + "utf8" + (fn [] + (rf/dispatch [:toasts/upsert + {:type :positive + :text (str "app-db " content-size + " bytes written to " path)}])) + (fn [error] + (rf/dispatch [:toasts/upsert + {:type :negative + :text (str "Error: " (oops/oget error :message))}])))) + (rf/dispatch [:messages-home/select-tab tab])) :scroll-shared-value scroll-shared-value}]]))