Fix an issue causing a blank index when navigating

Status 304 a bitch.
This commit is contained in:
Zixaphir 2014-03-13 15:15:58 -07:00
parent 9b9a2980aa
commit 91a63d1bc2
3 changed files with 29 additions and 21 deletions

View File

@ -3058,7 +3058,7 @@
} }
}, },
pageNav: function(pageNum) { pageNav: function(pageNum) {
if (Index.currentPage === pageNum) { if (Index.currentPage === pageNum && !Index.root.parentElement) {
return; return;
} }
history.pushState(null, '', pageNum === 0 ? './' : pageNum); history.pushState(null, '', pageNum === 0 ? './' : pageNum);
@ -3156,7 +3156,7 @@
return $('#hidden-count', Index.hideLabel).textContent = hiddenCount === 1 ? '1 hidden thread' : "" + hiddenCount + " hidden threads"; return $('#hidden-count', Index.hideLabel).textContent = hiddenCount === 1 ? '1 hidden thread' : "" + hiddenCount + " hidden threads";
}, },
update: function(pageNum) { update: function(pageNum) {
var now, onload, _ref, _ref1; var board, now, onload, sortedThreads, _ref, _ref1;
if (!navigator.onLine) { if (!navigator.onLine) {
return; return;
} }
@ -3176,6 +3176,10 @@
if ((_ref1 = Index.notice) != null) { if ((_ref1 = Index.notice) != null) {
_ref1.close(); _ref1.close();
} }
sortedThreads = Index.sortedThreads;
if (sortedThreads) {
board = sortedThreads[0].board.ID;
}
now = Date.now(); now = Date.now();
$.ready(function() { $.ready(function() {
return Index.nTimeout = setTimeout((function() { return Index.nTimeout = setTimeout((function() {
@ -3190,11 +3194,11 @@
onload = function(e) { onload = function(e) {
return Index.load(e, pageNum); return Index.load(e, pageNum);
}; };
Index.req = $.ajax("//a.4cdn.org/" + g.BOARD + "/catalog.json", { Index.req = $.ajax("//a.4cdn.org/" + g.BOARD.ID + "/catalog.json", {
onabort: onload, onabort: onload,
onloadend: onload onloadend: onload
}, { }, {
whenModified: Index.board === ("" + g.BOARD) whenModified: board === g.BOARD.ID
}); });
return $.addClass(Index.button, 'fa-spin'); return $.addClass(Index.button, 'fa-spin');
}, },
@ -3225,12 +3229,11 @@
return; return;
} }
Navigate.title(); Navigate.title();
Index.board = "" + g.BOARD;
try { try {
if (req.status === 200) { if (req.status === 200) {
Index.parse(req.response, pageNum); Index.parse(req.response, pageNum);
} else if (req.status === 304 && (pageNum != null)) { } else if (req.status === 304) {
Index.pageNav(pageNum); Index.pageNav(pageNum || 0);
} }
} catch (_error) { } catch (_error) {
err = _error; err = _error;

View File

@ -3117,7 +3117,7 @@
} }
}, },
pageNav: function(pageNum) { pageNav: function(pageNum) {
if (Index.currentPage === pageNum) { if (Index.currentPage === pageNum && !Index.root.parentElement) {
return; return;
} }
history.pushState(null, '', pageNum === 0 ? './' : pageNum); history.pushState(null, '', pageNum === 0 ? './' : pageNum);
@ -3215,7 +3215,7 @@
return $('#hidden-count', Index.hideLabel).textContent = hiddenCount === 1 ? '1 hidden thread' : "" + hiddenCount + " hidden threads"; return $('#hidden-count', Index.hideLabel).textContent = hiddenCount === 1 ? '1 hidden thread' : "" + hiddenCount + " hidden threads";
}, },
update: function(pageNum) { update: function(pageNum) {
var now, onload, _ref, _ref1; var board, now, onload, sortedThreads, _ref, _ref1;
if (!navigator.onLine) { if (!navigator.onLine) {
return; return;
} }
@ -3235,6 +3235,10 @@
if ((_ref1 = Index.notice) != null) { if ((_ref1 = Index.notice) != null) {
_ref1.close(); _ref1.close();
} }
sortedThreads = Index.sortedThreads;
if (sortedThreads) {
board = sortedThreads[0].board.ID;
}
now = Date.now(); now = Date.now();
$.ready(function() { $.ready(function() {
return Index.nTimeout = setTimeout((function() { return Index.nTimeout = setTimeout((function() {
@ -3249,11 +3253,11 @@
onload = function(e) { onload = function(e) {
return Index.load(e, pageNum); return Index.load(e, pageNum);
}; };
Index.req = $.ajax("//a.4cdn.org/" + g.BOARD + "/catalog.json", { Index.req = $.ajax("//a.4cdn.org/" + g.BOARD.ID + "/catalog.json", {
onabort: onload, onabort: onload,
onloadend: onload onloadend: onload
}, { }, {
whenModified: Index.board === ("" + g.BOARD) whenModified: board === g.BOARD.ID
}); });
return $.addClass(Index.button, 'fa-spin'); return $.addClass(Index.button, 'fa-spin');
}, },
@ -3284,12 +3288,11 @@
return; return;
} }
Navigate.title(); Navigate.title();
Index.board = "" + g.BOARD;
try { try {
if (req.status === 200) { if (req.status === 200) {
Index.parse(req.response, pageNum); Index.parse(req.response, pageNum);
} else if (req.status === 304 && (pageNum != null)) { } else if (req.status === 304) {
Index.pageNav(pageNum); Index.pageNav(pageNum || 0);
} }
} catch (_error) { } catch (_error) {
err = _error; err = _error;

View File

@ -412,7 +412,7 @@ Index =
Index.pageNav pageNum Index.pageNav pageNum
pageNav: (pageNum) -> pageNav: (pageNum) ->
return if Index.currentPage is pageNum return if Index.currentPage is pageNum and not Index.root.parentElement
history.pushState null, '', if pageNum is 0 then './' else pageNum history.pushState null, '', if pageNum is 0 then './' else pageNum
Index.pageLoad pageNum Index.pageLoad pageNum
@ -499,6 +499,10 @@ Index =
Index.req?.abort() Index.req?.abort()
Index.notice?.close() Index.notice?.close()
{sortedThreads} = Index
if sortedThreads
board = sortedThreads[0].board.ID
# This notice only displays if Index Refresh is taking too long # This notice only displays if Index Refresh is taking too long
now = Date.now() now = Date.now()
$.ready -> $.ready ->
@ -509,11 +513,11 @@ Index =
pageNum = null if typeof pageNum isnt 'number' # event pageNum = null if typeof pageNum isnt 'number' # event
onload = (e) -> Index.load e, pageNum onload = (e) -> Index.load e, pageNum
Index.req = $.ajax "//a.4cdn.org/#{g.BOARD}/catalog.json", Index.req = $.ajax "//a.4cdn.org/#{g.BOARD.ID}/catalog.json",
onabort: onload onabort: onload
onloadend: onload onloadend: onload
, ,
whenModified: Index.board is "#{g.BOARD}" whenModified: board is g.BOARD.ID
$.addClass Index.button, 'fa-spin' $.addClass Index.button, 'fa-spin'
load: (e, pageNum) -> load: (e, pageNum) ->
@ -541,13 +545,11 @@ Index =
Navigate.title() Navigate.title()
Index.board = "#{g.BOARD}"
try try
if req.status is 200 if req.status is 200
Index.parse req.response, pageNum Index.parse req.response, pageNum
else if req.status is 304 and pageNum? else if req.status is 304
Index.pageNav pageNum Index.pageNav pageNum or 0
catch err catch err
c.error "Index failure: #{err.message}", err.stack c.error "Index failure: #{err.message}", err.stack
# network error or non-JSON content for example. # network error or non-JSON content for example.