Revise reverse sort implementation details

On setup, immediately check box if '-rev'
appended to current sort.

For custom board navigation, prefer to account for
'-rev' option in processHash().

Bring sorting work outside nested function.
This commit is contained in:
Koushien 2016-10-29 12:00:25 -07:00
parent 1c7e85ea7b
commit 1d0d7f3f2c

View File

@ -351,17 +351,11 @@ Index =
'catalog': 'catalog' 'catalog': 'catalog'
sort: sort:
'bump-order': 'bump' 'bump-order': 'bump'
'bump-order-rev': 'bump-rev'
'last-reply': 'lastreply' 'last-reply': 'lastreply'
'last-reply-rev': 'lastreply-rev'
'last-long-reply': 'lastlong' 'last-long-reply': 'lastlong'
'last-long-reply-rev': 'lastlong-rev'
'creation-date': 'birth' 'creation-date': 'birth'
'creation-date-rev': 'birth-rev'
'reply-count': 'replycount' 'reply-count': 'replycount'
'reply-count-rev': 'replycount-rev'
'file-count': 'filecount' 'file-count': 'filecount'
'file-count-rev': 'filecount-rev'
processHash: -> processHash: ->
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304 # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304
@ -378,6 +372,8 @@ Index =
state.page = 1 state.page = 1
else if (sort = Index.hashCommands.sort[command]) else if (sort = Index.hashCommands.sort[command])
state.sort = sort state.sort = sort
else if (sort = Index.hashCommands.sort[command.slice(0,-4)])
state.sort = sort + '-rev'
else if /^s=/.test command else if /^s=/.test command
state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim() state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim()
else else
@ -460,7 +456,7 @@ Index =
$('#hidden-toggle a', Index.navLinks).textContent = 'Show' $('#hidden-toggle a', Index.navLinks).textContent = 'Show'
setupSort: -> setupSort: ->
Index.selectRev.checked = false Index.selectRev.checked = Index.currentSort.slice(-4) is '-rev'
Index.selectSort.value = do -> Index.selectSort.value = do ->
if Index.currentSort.slice(-4) is '-rev' if Index.currentSort.slice(-4) is '-rev'
Index.selectRev.checked = true Index.selectRev.checked = true
@ -764,32 +760,31 @@ Index =
sort: -> sort: ->
{liveThreadIDs, liveThreadData} = Index {liveThreadIDs, liveThreadData} = Index
return unless liveThreadData return unless liveThreadData
Index.sortedThreadIDs = do -> if Index.currentSort.slice(-4) is '-rev'
if Index.currentSort.slice(-4) == "-rev" currentSort = Index.currentSort.slice(0,-4)
currentSort = Index.currentSort.slice(0,-4) reverse = true
reverse = true else
else currentSort = Index.currentSort
currentSort = Index.currentSort sorted = switch currentSort
sorted = switch currentSort when 'lastreply'
when 'lastreply' [liveThreadData...].sort((a, b) ->
[liveThreadData...].sort((a, b) -> a = num[num.length - 1] if (num = a.last_replies)
a = num[num.length - 1] if (num = a.last_replies) b = num[num.length - 1] if (num = b.last_replies)
b = num[num.length - 1] if (num = b.last_replies) b.no - a.no
b.no - a.no ).map (post) -> post.no
).map (post) -> post.no when 'lastlong'
when 'lastlong' lastlong = (thread) ->
lastlong = (thread) -> for r, i in (thread.last_replies or []) by -1
for r, i in (thread.last_replies or []) by -1 return r if r.com and Build.parseComment(r.com).replace(/[^a-z]/ig, '').length >= 100
return r if r.com and Build.parseComment(r.com).replace(/[^a-z]/ig, '').length >= 100 thread
thread [liveThreadData...].sort((a, b) ->
[liveThreadData...].sort((a, b) -> lastlong(b).no - lastlong(a).no
lastlong(b).no - lastlong(a).no ).map (post) -> post.no
).map (post) -> post.no when 'bump' then liveThreadIDs
when 'bump' then liveThreadIDs when 'birth' then [liveThreadIDs... ].sort (a, b) -> b - a
when 'birth' then [liveThreadIDs... ].sort (a, b) -> b - a when 'replycount' then [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no
when 'replycount' then [liveThreadData...].sort((a, b) -> b.replies - a.replies).map (post) -> post.no when 'filecount' then [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no
when 'filecount' then [liveThreadData...].sort((a, b) -> b.images - a.images ).map (post) -> post.no Index.sortedThreadIDs = if reverse then [sorted...].reverse() else sorted
return if reverse then [sorted...].reverse() else sorted
if Index.search and (threadIDs = Index.querySearch Index.search) if Index.search and (threadIDs = Index.querySearch Index.search)
Index.sortedThreadIDs = threadIDs Index.sortedThreadIDs = threadIDs
# Sticky threads # Sticky threads