Skip to content

Commit 87d2654

Browse files
committed
Added error display if no username was entered
this will make the first usage of the app a lot more intuitive
1 parent 97c0fe4 commit 87d2654

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

src/main/weebmanager/anime.cljs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
Error
1515
(reason [_] (name error-code)))
1616

17+
(defrecord UserError [reason]
18+
Error
19+
(reason [_] reason))
20+
1721
(defn get-url [url params headers]
1822
(->> {:query-params params
1923
:headers headers
@@ -114,24 +118,26 @@
114118

115119
(defn transduce-merged-data [mal-username xf f map-result]
116120
(go
117-
(let [mal-data (fetch-mal-watching mal-username)
118-
ani-data (apply fetch-anilist-airing (get-year-and-season))
119-
mal-data (<! mal-data)
120-
ani-data (<! ani-data)
121-
combined-xf (comp (filter #(= 2 (count %)))
122-
(map (partial apply merge))
123-
xf)]
124-
(cond
125-
(nil? mal-data) (println "could not fetch mal data for" mal-username)
126-
(nil? ani-data) (println "could not currently running shows for" (get-year-and-season))
127-
(error? mal-data) mal-data
128-
(error? ani-data) ani-data
129-
:else
130-
(->> (concat mal-data ani-data)
131-
(group-by :id)
132-
vals
133-
(transduce combined-xf f)
134-
map-result)))))
121+
(if-not (empty? mal-username)
122+
(let [mal-data (fetch-mal-watching mal-username)
123+
ani-data (apply fetch-anilist-airing (get-year-and-season))
124+
mal-data (<! mal-data)
125+
ani-data (<! ani-data)
126+
combined-xf (comp (filter #(= 2 (count %)))
127+
(map (partial apply merge))
128+
xf)]
129+
(cond
130+
(nil? mal-data) (println "could not fetch mal data for" mal-username)
131+
(nil? ani-data) (println "could not currently running shows for" (get-year-and-season))
132+
(error? mal-data) mal-data
133+
(error? ani-data) ani-data
134+
:else
135+
(->> (concat mal-data ani-data)
136+
(group-by :id)
137+
vals
138+
(transduce combined-xf f)
139+
map-result)))
140+
(UserError. "Please enter your MAL username in the settings"))))
135141

136142
(defn fetch-merged-data [mal-username xf]
137143
(transduce-merged-data mal-username xf conj identity))

src/main/weebmanager/components/common.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@
121121
{:name icon-name
122122
:color "white"
123123
:size 40}]
124-
[:> p/Text text]]))
124+
[:> p/Text
125+
{:style {:text-align :center}}
126+
text]]))
125127

126128
(defn- empty-list-view [text]
127129
(list-empty-component text "sentiment-dissatisfied"))
128130

129131
(defn- error-list-view [reason]
130-
(list-empty-component (str "Could not fetch animes: " reason) "sentiment-very-dissatisfied"))
132+
(list-empty-component (str "Could not fetch animes: \n" reason) "sentiment-very-dissatisfied"))
131133

132134
(defn- anime-flat-list [loading? refresh-data data make-list-item empty-component]
133135
[:> rn/FlatList

0 commit comments

Comments
 (0)