app/assets/javascripts/components/posts.js.cjsx in octodmin-0.2.0 vs app/assets/javascripts/components/posts.js.cjsx in octodmin-0.2.1

- old
+ new

@@ -8,11 +8,11 @@ { loading: false, posts: null } fetchPosts: -> return if @state.loading @setState(loading: true) - $.get("/api/posts").always(@handleResponse).done(@handleSuccess).fail(@handleError) + $.getq("default", "/api/posts").always(@handleResponse).done(@handleSuccess).fail(@handleError) handleResponse: -> @setState(loading: false) if @isMounted() handleSuccess: (response) -> @@ -21,13 +21,15 @@ handleError: (error) -> $.growl("Could not load posts: #{error.statusText} (#{error.status})", growlError) componentWillMount: -> @fetchPosts() + @timer = setInterval(@fetchPosts, 5000) $(document).on("fetchPosts", @fetchPosts) componentWillUnmount: -> + clearInterval(@timer) $(document).off("fetchPosts", @fetchPosts) render: -> <div> <NewPostPartial site={@props.site} /> @@ -64,11 +66,11 @@ handleSubmit: (event) -> event.preventDefault() return if @state.loading @setState(loading: true) - $.post("/api/posts", @form().serialize()).always(@handleResponse).done(@handleSuccess).fail(@handleError) + $.postq("default", "/api/posts", @form().serialize()).always(@handleResponse).done(@handleSuccess).fail(@handleError) handleResponse: -> @setState(loading: false) handleSuccess: (response) -> @@ -121,11 +123,11 @@ handleRevert: -> return if @state.loading @setState(loading: true) - $.ajax(type: "PATCH", url: "/api/posts/#{@props.post.identifier}/revert"). + $.ajaxq("default", type: "PATCH", url: "/api/posts/#{@props.post.identifier}/revert"). always(@handleResponse). done(@handleSuccess). fail(@handleError) handleDelete: -> @@ -133,20 +135,20 @@ return unless confirm("Are you sure? This can't be undone") return if @state.loading @setState(loading: true) - $.ajax(type: "DELETE", url: "/api/posts/#{@props.post.identifier}"). + $.ajaxq("default", type: "DELETE", url: "/api/posts/#{@props.post.identifier}"). always(@handleResponse). done(@handleSuccess). fail(@handleError) handleRestore: -> return if @state.loading @setState(loading: true) - $.ajax(type: "PATCH", url: "/api/posts/#{@props.post.identifier}/restore"). + $.ajaxq("default", type: "PATCH", url: "/api/posts/#{@props.post.identifier}/restore"). always(@handleResponse). done(@handleSuccess). fail(@handleError) handleResponse: -> @@ -205,11 +207,11 @@ @props.site.octodmin.front_matter fetchPost: -> return if @state.loading @setState(loading: true) - $.get("/api/posts/#{@getParams().post_id}").always(@handleResponse).done(@handleSuccess).fail(@handleError) + $.getq("default", "/api/posts/#{@getParams().post_id}").always(@handleResponse).done(@handleSuccess).fail(@handleError) handleBack: (event) -> event.preventDefault() @transitionTo("app") @@ -217,10 +219,10 @@ event.preventDefault() return if @state.loading @setState(loading: true) data = @form().serializeObject() - $.ajax(type: "PATCH", url: "/api/posts/#{@state.post.identifier}", data: data). + $.ajaxq("default", type: "PATCH", url: "/api/posts/#{@state.post.identifier}", data: data). always(@handleResponse). done(@handleFormSuccess). fail(@handleError) handleResponse: ->