Skip to content

Instantly share code, notes, and snippets.

@kenbier
Last active December 21, 2016 07:18
Show Gist options
  • Save kenbier/a4b045f0ef62235b9239ed279e8ee10e to your computer and use it in GitHub Desktop.
Save kenbier/a4b045f0ef62235b9239ed279e8ee10e to your computer and use it in GitHub Desktop.
(defn with-auth-token
"Token wrapper for calls to report-center production server. Gets the
token from the url params"
[request]
(assoc-in request
[:headers "Authorization"]
(str "Bearer " (core/get-url-param "token"))))
(defn start-untangled-support-viewer
"Create and display a new untangled support viewer on the given app root, with VCR controls to browse through the given history. The support HTML file must include
a div with app-dom-id (to mount the app) and a div with support-dom-id to mount the viewer controls."
[support-dom-id AppRoot app-dom-id]
(let [app (atom (core/new-untangled-client
:request-transform auth/with-auth-token
:initial-state (atom
(assoc
@st/init-data
:ui/support-viewer? true
:ui/no-router true))
:networking (net/mock-network)))
viewer (viewer/map->SupportViewer
{:app-root AppRoot
:dom-id app-dom-id
:application app
:support (atom (core/new-untangled-client
:initial-state {:history {}
:application app
:position :controls-left
:client-time (js/Date.)
:frames 0
:current-position 0}
:networking
(net/make-untangled-network
"https://report.adstage.io/api"
:request-transform with-auth-token
:global-error-callback network-error-callback)
:started-callback (fn [{:keys [reconciler]}]
(load-data reconciler
`[(:support-request {:id ~(core/get-url-param "id")})]
:post-mutation 'support-viewer/initialize-history))))})]
(core/mount viewer viewer/SupportViewerRoot support-dom-id)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment