I have a feature of uploading images. There is a gallery of images and I need to update the gallery on adding new photos. The photo upload is success, but, the UI is not getting updated with the newly added photo.
I am using entitydb for storing the list locally.
My controller method is below:
:post-art (pipeline! [value app-db]
(when value
(pipeline! [value app-db]
(post-art-photo app-db value)
(let [res (:createArtPicture value)]
(pp/commit! (edb/append-collection app-db :artPicture :list [(assoc res :art {:id (:artId res)})]))
(pp/commit! (assoc-in app-db [:kv :art-pictures-list] (edb/get-collection app-db :artPicture :list)))
(pp/commit! (assoc-in app-db [:kv :temp-photo] nil))
(navigate-go! {:key "art-single" :id (:artId res)}))
(rescue! [error]
nil))))
entitydb schema is:
(def edb-schema
{:art {:id :id
:relations {:photos [:many :asset]
:authors [:many :author]
:campus [:one :campus]
:thumbnail [:one :asset]
:categories [:many :artCategory]}}
:author {:id :id
:relations {:avatar [:one :asset]
:arts [:many :art]}}
:campus {:id :id
:relations {:arts [:many :art]
:photo [:one :asset]}}
:artCategory {:id :id
:relations {:icon [:one :asset]
:arts [:many :art]}}
:artList {:id :id
:relations {:user [:one :user]
:state [:many :art]}}
:artPicture {:id :id
:relations {:user [:one :user]
:art [:one :art]}
:middleware {:set [(fn [a]
(assoc a :art {:id (:artId a)}))]}}
:comment {:id :id
:relations {:user [:one :user]
:art [:one :art]}
:middleware {:set [(fn [a]
(assoc a :art {:id (:artId a)}))]}}
:favorite {:id :id
:relations {:user [:one :user]}}
:game {:id :id
:relations {:user [:one :user]}}
:user {:id :id
:relations {:artLists [:many :artList]
:artPictures [:many :artPicture]
:comments [:many :comment]
:favorites [:many :favorite]
:games [:many :game]}}
:asset {:id :id}})
The issue is with 'artPicture'. The 'comment' also have the same feature. But, that is working fine. Anyone, please help?
Finally, I found the solution. I have wrapped the code inside a "pipeline! [value app-db]" and that worked!
:post-art-picture (pipeline! [value app-db]
(when value
(pipeline! [value app-db]
(post-art-photo app-db value)
(let [res (:createArtPicture value)]
(pipeline! [value app-db]
(pp/commit! (edb/append-collection app-db :artPicture :list [(assoc res :art {:id (:artId res)})]))
(pp/commit! (assoc-in app-db [:kv :temp-photo] nil))
(navigate-replace! (-> (util/current-route (get-in app-db [:route]))
(dissoc :subpage)
(assoc :subpage "completed")))
(rescue! [error]
(util/log "Photo Upload ERROR:" error)))))))