From e5ab4ffb5b9b7f30f72e30885876ccd4b7dd234f Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 24 Mar 2019 02:41:56 -0700 Subject: [PATCH] Clean up index notification code and handle aborting previous request better. --- src/General/Index.coffee | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 90ade98ae..6f72b0c92 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -573,21 +573,18 @@ Index = "#{hiddenCount} hidden threads" update: (firstTime) -> - Index.req?.aborted = true - Index.req?.abort() - Index.notice?.close() + if (oldReq = Index.req) + delete Index.req + oldReq.abort() - if Conf['Index Refresh Notifications'] and d.readyState isnt 'loading' + if Conf['Index Refresh Notifications'] # Optional notification for manual refreshes - Index.notice = new Notice 'info', 'Refreshing index...' + Index.notice or= new Notice 'info', 'Refreshing index...' else # Also display notice if Index Refresh is taking too long - now = Date.now() - $.ready -> - Index.nTimeout = setTimeout (-> - if Index.req and !Index.notice - Index.notice = new Notice 'info', 'Refreshing index...' - ), 3 * $.SECOND - (Date.now() - now) + Index.nTimeout or= setTimeout -> + Index.notice or= new Notice 'info', 'Refreshing index...' + , 3 * $.SECOND # Hard refresh in case of incomplete page load. if not firstTime and d.readyState isnt 'loading' and not $('.board + *') @@ -602,19 +599,17 @@ Index = $.addClass Index.button, 'fa-spin' load: -> + return if @ isnt Index.req # aborted + $.rmClass Index.button, 'fa-spin' - {req, notice, nTimeout} = Index + {notice, nTimeout} = Index clearTimeout nTimeout if nTimeout delete Index.nTimeout delete Index.req delete Index.notice - if req.aborted - notice?.close() - return - - if req.status not in [200, 304] - err = "Index refresh failed. #{if req.status then "Error #{req.statusText} (#{req.status})" else 'Connection Error'}" + if @status not in [200, 304] + err = "Index refresh failed. #{if @status then "Error #{@statusText} (#{@status})" else 'Connection Error'}" if notice notice.setType 'warning' notice.el.lastElementChild.textContent = err @@ -624,13 +619,12 @@ Index = return try - if req.status is 200 - Index.parse req.response - else if req.status is 304 + if @status is 200 + Index.parse @response + else if @status is 304 Index.pageLoad() catch err c.error "Index failure: #{err.message}", err.stack - # network error or non-JSON content for example. if notice notice.setType 'error' notice.el.lastElementChild.textContent = 'Index refresh failed.' @@ -648,7 +642,7 @@ Index = notice.close() timeEl = $ '#index-last-refresh time', Index.navLinks - timeEl.dataset.utc = Date.parse req.getResponseHeader 'Last-Modified' + timeEl.dataset.utc = Date.parse @getResponseHeader 'Last-Modified' RelativeDates.update timeEl parse: (pages) ->