Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Jun 6, 2020
1 parent 56aafc6 commit 7da7c7d
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 289 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ git clone https://github.com/flexsurfer/conduitrn.git && cd conduitrn

#### Install dependencies
```shell
yarn install || npm install
yarn || npm install
```

#### Install pods for ios
```shell
cd ios; pod install; cd ../
cd ios && pod install && cd ../
```

#### Run dev server
Expand Down
1 change: 0 additions & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ target 'conduitrn' do
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'

target 'conduitrnTests' do
inherit! :complete
Expand Down
5 changes: 4 additions & 1 deletion src/conduit/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
;; When the application first starts, this will be the value put in app-db
;; Look in: `events.cljs` for the registration of :initialise-app handler
;;
(def default-db {:active-page :home}) ;; what gets put into app-db by default.
(def default-db {:active-page :home
:global-articles #{}
:feed-articles #{}
:filtered-articles #{}}) ;; what gets put into app-db by default.
279 changes: 132 additions & 147 deletions src/conduit/events.cljs

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions src/conduit/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,46 @@
;; reg-root-subs is a syntax sugar for registering subscriptions for root keys
;; equal to (re-frame/reg-sub :active-page (fn [db _] (get db :active-page)))

(subs/reg-root-subs #{:active-page :articles-count :tags :profile :loading :filter ;; usage: (subscribe [:active-page])
(subs/reg-root-subs #{:articles :active-page :articles-count :tags :profile :loading :filter ;; usage: (subscribe [:active-page])
:errors :user})
(subs/reg-root-sub :articles-root :articles) ;; usage: (subscribe [:articles-root])
(subs/reg-root-sub :comments-root :comments)
(subs/reg-root-sub :comments-root :comments) ;; usage: (subscribe [:comments-root])
(subs/reg-root-sub :feed-articles-root :feed-articles)
(subs/reg-root-sub :filtered-articles-root :filtered-articles)
(subs/reg-root-sub :global-articles-root :global-articles)

(re-frame/reg-sub
:articles ;; usage: (subscribe [:articles])
:<- [:articles-root]
(fn [articles] ;; db is the (map) value stored in the app-db atom
(->> articles ;; ->> is a thread last macro - pass atricles as last arg of:
(vals) ;; vals, just as we would write (vals articles), then pass the result to:
(sort-by :epoch utils/reverse-cmp)))) ;; sort-by epoch in reverse order
:global-articles ;; usage: (subscribe [:global-articles])
:<- [:articles]
:<- [:global-articles-root]
(fn [[articles global-articles]]
(vals (select-keys articles global-articles)))) ;;we don't sort by epoch because its broken on server

(re-frame/reg-sub
:feed-articles ;; usage: (subscribe [:feed-articles])
:feed-articles ;; usage: (subscribe [:feed-articles])
:<- [:articles]
:<- [:feed-articles-root]
(fn [articles] ;; db is the (map) value stored in the app-db atom
(->> articles ;; ->> is a thread last macro - pass atricles as last arg of:
(vals) ;; vals, just as we would write (vals articles), then pass the result to:
(sort-by :epoch utils/reverse-cmp)))) ;; sort-by epoch in reverse order
(fn [[articles feed-articles]]
(vals (select-keys articles feed-articles))))

(re-frame/reg-sub
:filtered-articles ;; usage: (subscribe [:filtered-articles])
:filtered-articles ;; usage: (subscribe [:filtered-articles])
:<- [:articles]
:<- [:filtered-articles-root]
(fn [articles] ;; db is the (map) value stored in the app-db atom
(->> articles ;; ->> is a thread last macro - pass atricles as last arg of:
(vals) ;; vals, just as we would write (vals articles), then pass the result to:
(sort-by :epoch utils/reverse-cmp)))) ;; sort-by epoch in reverse order
(fn [[articles filtered-articles]]
(vals (select-keys articles filtered-articles))))

(re-frame/reg-sub
:active-article ;; usage (subscribe [:active-article])
:active-article ;; usage (subscribe [:active-article])
(fn [db _]
(or (get-in db [:articles (:active-article db)])
(get-in db [:feed-articles (:active-article db)])
(get-in db [:filtered-articles (:active-article db)]))))
(get-in db [:articles (:active-article db)])))

(re-frame/reg-sub
:comments ;; usage: (subscribe [:comments])
:edit-article ;; usage (subscribe [:edit-article])
(fn [db _]
(get-in db [:articles (:edit-article db)])))

(re-frame/reg-sub
:comments ;; usage: (subscribe [:comments])
:<- [:comments-root]
(fn [comments]
(->> comments
Expand Down
30 changes: 16 additions & 14 deletions src/conduit/ui/article/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
" "
favoritesCount]])

(defn follow [username]
(let [{:keys [following]} @(re-frame/subscribe [:profile])]
[touchable/touchable-opacity
{:on-press #(re-frame/dispatch [:toggle-follow-user username])}
[rn/view {:style {:align-items :center :justify-content :center
:align-self :flex-start :padding-horizontal 4 :border-radius 2
:border-width 1 :border-color "rgba(100,100,100,0.4)"}}
[rn/text (if following " - Unfollow" " + Follow")]]]))
(defn follow [username profile]
[rn/view {:style {:height 25}}
(when profile
(let [{:keys [following]} profile]
[touchable/touchable-opacity
{:on-press #(re-frame/dispatch [:toggle-follow-user username])}
[rn/view {:style {:align-items :center :justify-content :center
:align-self :flex-start :padding-horizontal 4 :border-radius 2
:border-width 1 :border-color "rgba(100,100,100,0.4)"}}
[rn/text (if following " - Unfollow" " + Follow")]]]))])


(defn edit [slug]
[touchable/touchable-opacity
Expand All @@ -38,7 +41,7 @@
[touchable/touchable-opacity
{:on-press #(re-frame/dispatch [:delete-comment id])}
[rn/view {:style {:align-items :center :justify-content :center
:margin-left 10
:margin-left 10
:align-self :flex-start :padding-horizontal 4 :border-radius 2
:border-width 1 :border-color "rgba(100,100,100,0.4)"}}
[rn/text "Delete"]]])
Expand Down Expand Up @@ -87,15 +90,14 @@
@(re-frame/subscribe [:active-article])
user @(re-frame/subscribe [:user])
comments @(re-frame/subscribe [:comments])
errors @(re-frame/subscribe [:errors])
loading @(re-frame/subscribe [:loading])
profile @(re-frame/subscribe [:profile])
username (:username author)]
[safe-area/safe-area-view {:style {:flex 1
:background-color :white}}
[ui/back-button "" #(do
(re-frame/dispatch [:reset-active-article])
(re-frame/dispatch [:navigate-back]))]
[rn/scroll-view {:style {:flex 1}
[rn/scroll-view {:style {:flex 1}
:keyboardShouldPersistTaps :always}
[rn/view {:style {:margin-horizontal 20 :flex 1}}
[rn/view {:style {:flex-direction :row :flex 1 :align-items :center}}
Expand All @@ -112,6 +114,6 @@
[rn/text {:style {:color :gray}} " · " (utils/format-date createdAt)]]]
(if (= username (:username user))
[edit slug]
[follow username])
[follow username profile])
[rn/text {:style {:font-size 20 :margin-top 30}} body]
[comments-view comments (:username user)]]]]))
[comments-view comments (:username user)]]]]))
33 changes: 19 additions & 14 deletions src/conduit/ui/components.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@
[rn/view {:style {:align-items :center :margin-vertical 5}}
[ui/button (merge {:color "#5cb85c"} props)]])

(defn text-button [title handler]
[rn/view {:style {:align-items :center :margin-vertical 5}}
[touchable/touchable-opacity {:on-press handler}
[rn/view {:style {:padding-horizontal 20 :padding-vertical 10}}
[rn/text {:style {:color "#5cb85c"}} title]]]])

(defn square-button [icon handler]
[touchable/touchable-opacity {:on-press handler}
[rn/view {:style {:width 40 :height 40 :justify-content :center}}
[ion-icons {:name icon :size 30}]]])

(defn back-button
([title] (back-button title #(re-frame/dispatch [:navigate-back])))
([title handler]
[rn/view {:style {:flex-direction :row :align-items :center :margin-horizontal 20
:margin-vertical 10}}
[square-button "ios-arrow-back" handler]
[rn/text {:style {:font-size 20 :margin-left 10}} title]]))

(defn keyboard-avoiding-view [props & children]
(into [other/keyboard-avoiding-view
(merge {:style {:flex 1}}
Expand All @@ -49,20 +68,6 @@
:border-color :gray
:border-width 1}}])))

(defn square-button [icon handler]
[touchable/touchable-opacity {:on-press handler}
[rn/view {:style {:width 40 :height 40 :justify-content :center}}
[ion-icons {:name icon :size 30}]]])

(defn back-button
([title] (back-button title #(re-frame/dispatch [:navigate-back])))
([title handler]
[rn/view {:style {:flex-direction :row :align-items :center :margin-horizontal 20
:margin-vertical 10}}
[square-button "ios-arrow-back" handler]
[rn/text {:style {:font-size 20 :margin-left 10}} title]]))


(defn safe-area-consumer [& children]
[safe-area/safe-area-consumer
(fn [insets]
Expand Down
44 changes: 28 additions & 16 deletions src/conduit/ui/edit/views.cljs
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"}]])]]]))))
6 changes: 3 additions & 3 deletions src/conduit/ui/home/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
:on-refresh #(re-frame/dispatch [:get-feed-articles])
:on-end #(re-frame/dispatch [:get-more-feed-articles])}]]))

(defn my []
(defn user-articles []
(let [loading @(re-frame/subscribe [:loading])
articles @(re-frame/subscribe [:filtered-articles])]
[safe-area/safe-area-view {:style {:flex 1
Expand Down Expand Up @@ -114,12 +114,12 @@

(defn home []
(let [loading @(re-frame/subscribe [:loading])
articles @(re-frame/subscribe [:articles])]
articles @(re-frame/subscribe [:global-articles])]
[ui/safe-area-consumer
[screen
{:title "Global feed"
:data articles
:loading? (:articles loading)
:accesories #(re-frame/dispatch [:navigate-to :tags])
:accesories #(re-frame/dispatch [:set-active-page {:page :tags}])
:on-refresh #(re-frame/dispatch [:get-articles])
:on-end #(re-frame/dispatch [:get-more-articles])}]]))
42 changes: 2 additions & 40 deletions src/conduit/ui/profile/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,11 @@
[rn/text {:style {:color :gray}
:number-of-lines 4} bio]]
[rn/view
[profile-item "My articles" #(re-frame/dispatch [:set-active-page {:page :my
[profile-item "My articles" #(re-frame/dispatch [:set-active-page {:page :user-articles
:profile username}])
true false]
[profile-item "Favorited Articles" #(re-frame/dispatch [:set-active-page {:page :favorited
[profile-item "Favorited Articles" #(re-frame/dispatch [:set-active-page {:page :user-favorite
:favorited username}])
false false]
[rn/view {:style {:height 50}}]
[profile-item "Logout" #(re-frame/dispatch [:logout]) false true]]]]))

(defn profile-old
[]
(let [{:keys [image username bio following] :or {username ""}} @(re-frame/subscribe [:profile])
{:keys [author favorites]} @(re-frame/subscribe [:filter])
loading @(re-frame/subscribe [:loading])
articles @(re-frame/subscribe [:articles])
user @(re-frame/subscribe [:user])]
[:div.profile-page
[:div.user-info
[:div.container
[:div.row
[:div.col-xs-12.col-md-10.offset-md-1
[:img.user-img {:src image :alt "user image"}]
[:h4 username]
[:p bio]
(if (= (:username user) username)
[:a.btn.btn-sm.btn-outline-secondary.action-btn ;{:href (url-for :settings)}
[:i.ion-gear-a] " Edit Profile Settings"]
[:button.btn.btn-sm.action-btn.btn-outline-secondary
{:on-click #(re-frame/dispatch [:toggle-follow-user username])
:class (when (:toggle-follow-user loading) "disabled")}
[:i {:class (if following "ion-minus-round" "ion-plus-round")}]
[:span (if following (str " Unfollow " username) (str " Follow " username))]])]]]]
[:div.container
[:div.row
[:div.col-xs-12.col-md-10.offset-md-1
[:div.articles-toggle
[:ul.nav.nav-pills.outline-active
[:li.nav-item
[:a.nav-link ;{:href (url-for :profile :user-id username)
;:class (when author " active")
"My Articles"]]
[:li.nav-item
[:a.nav-link {;:href (url-for :favorited :user-id username)
:class (when favorites "active")}
"Favorited Articles"]]]]]]]]))
;[articles-list articles (:articles loading)]]]]]))
6 changes: 2 additions & 4 deletions src/conduit/ui/signin/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
errors @(re-frame/subscribe [:errors])]
[rn/view {:style {:flex 1}}
[rn/text {:style {:font-size 30 :align-self :center}} "Sign in"]
[ui/button {:title "Need an account?"
:on-press #(swap! sign-in? not)}]
[ui/text-button "Need an account?" #(swap! sign-in? not)]
(when (:login errors)
[ui/errors-list (:login errors)])
[ui/text-input {:style {:margin-horizontal 20 :margin-vertical 10}
Expand Down Expand Up @@ -45,8 +44,7 @@
errors @(re-frame/subscribe [:errors])]
[rn/view {:style {:flex 1}}
[rn/text {:style {:font-size 30 :align-self :center}} "Sign up"]
[ui/button {:title "Have an account?"
:on-press #(swap! sign-in? not)}]
[ui/text-button "Have an account?" #(swap! sign-in? not)]
(when (:register-user errors)
[ui/errors-list (:register-user errors)])
[ui/text-input {:style {:margin-horizontal 20 :margin-vertical 10}
Expand Down
Loading

0 comments on commit 7da7c7d

Please sign in to comment.