-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56aafc6
commit 7da7c7d
Showing
13 changed files
with
244 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,68 @@ | ||
(ns conduit.ui.edit.views | ||
(:require [re-frame.core :as re-frame] | ||
[clojure.string :as string] | ||
[reagent.core :as reagent] | ||
[conduit.ui.components :as ui] | ||
[steroid.rn.core :as rn])) | ||
|
||
(defn upsert-article [content slug] | ||
(defn reset-fields [content refs] | ||
(fn [] | ||
(re-frame/dispatch [:reset-edit-article]) | ||
(reset! content {}) | ||
(doseq [ref @refs] | ||
(.clear ^js ref)))) | ||
|
||
(defn upsert-article [content refs slug] | ||
(re-frame/dispatch | ||
[:upsert-article | ||
{:slug slug | ||
:article {:title (string/trim (or (:title content) "")) | ||
:description (string/trim (or (:description content) "")) | ||
:body (string/trim (or (:body content) "")) | ||
:tagList (string/split (:tagList content) #" ")}}])) | ||
:tagList (string/split (:tagList content) #" ")}} | ||
(reset-fields content refs)])) | ||
|
||
(defn editor [] | ||
(let [{:keys [title description body tagList]} | ||
@(re-frame/subscribe [:active-article]) | ||
default {:title title :description description :body body :tagList tagList} | ||
content (reagent/atom default)] | ||
(let [content (atom {}) | ||
refs (atom #{})] | ||
(fn [] | ||
(let [{:keys [title description body tagList slug] :as active-article} | ||
@(re-frame/subscribe [:active-article]) | ||
@(re-frame/subscribe [:edit-article]) | ||
tagList (string/join " " tagList)] | ||
[ui/keyboard-avoiding-view {} | ||
[ui/safe-area-consumer | ||
[rn/scroll-view {:style {:flex 1} | ||
:keyboardShouldPersistTaps :always} | ||
[ui/text-input {:style {:margin-horizontal 20 :margin-vertical 10} | ||
[ui/text-input {:ref #(when % (swap! refs conj %)) | ||
:style {:margin-horizontal 20 :margin-vertical 10} | ||
:on-change-text #(swap! content assoc :title %) | ||
:placeholder "Article Title" | ||
:default-value title}] | ||
[ui/text-input {:style {:margin-horizontal 20 :margin-vertical 10} | ||
[ui/text-input {:ref #(when % (swap! refs conj %)) | ||
:style {:margin-horizontal 20 :margin-vertical 10} | ||
:on-change-text #(swap! content assoc :description %) | ||
:placeholder "What's this article about?" | ||
:default-value description}] | ||
[ui/text-input {:style {:margin-horizontal 20 :margin-vertical 10 | ||
[ui/text-input {:ref #(when % (swap! refs conj %)) | ||
:style {:margin-horizontal 20 :margin-vertical 10 | ||
:height 300} | ||
:on-change-text #(swap! content assoc :body %) | ||
:placeholder "Write your article (in markdown)" | ||
:default-value body}] | ||
[ui/text-input {:style {:margin-horizontal 20 :margin-top 10 | ||
[ui/text-input {:ref #(when % (swap! refs conj %)) | ||
:style {:margin-horizontal 20 :margin-top 10 | ||
:margin-bottom 40} | ||
:on-change-text #(swap! content assoc :tagList %) | ||
:placeholder "Enter tags" | ||
:default-value tagList}] | ||
[ui/button {:on-press #(upsert-article @content slug) | ||
:default-value (str tagList)}] | ||
[ui/button {:on-press #(upsert-article (merge {:title title :description description | ||
:body body :tagList tagList :slug slug} @content) | ||
refs | ||
slug) | ||
:title (if active-article | ||
"Update Article" | ||
"Publish Article")}] | ||
(when active-article | ||
(when (or active-article (seq @content)) | ||
[rn/view {:style {:margin-top 40}} | ||
[ui/button {:on-press #(re-frame/dispatch [:reset-active-article]) | ||
[ui/button {:on-press (reset-fields content refs) | ||
:color "#b85c5c" | ||
:title "Cancel"}]])]]])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.