Refactor hidden threads count.
It concerns filtered threads too, not just manually hidden threads. Conflicts: src/Filtering/ThreadHiding.coffee src/General/Index.coffee
This commit is contained in:
parent
3af338f23d
commit
d9e4dcda41
@ -19,29 +19,7 @@ ThreadHiding =
|
|||||||
thread = Get.threadFromRoot root
|
thread = Get.threadFromRoot root
|
||||||
if thread.isHidden and thread.stub and !root.contains thread.stub
|
if thread.isHidden and thread.stub and !root.contains thread.stub
|
||||||
ThreadHiding.makeStub thread, root
|
ThreadHiding.makeStub thread, root
|
||||||
ThreadHiding.updateToggle()
|
return
|
||||||
updateToggle: ->
|
|
||||||
hiddenCount = 0
|
|
||||||
for threadID, thread of g.BOARD.threads when thread.isHidden
|
|
||||||
hiddenCount++ if thread.ID in Index.liveThreadIDs
|
|
||||||
unless hiddenCount
|
|
||||||
ThreadHiding.removeToggle()
|
|
||||||
return
|
|
||||||
unless ThreadHiding.toggler
|
|
||||||
ThreadHiding.addToggle()
|
|
||||||
$('#hidden-count', Index.navLinks).textContent = if hiddenCount is 1
|
|
||||||
'1 hidden thread'
|
|
||||||
else
|
|
||||||
"#{hiddenCount} hidden threads"
|
|
||||||
addToggle: ->
|
|
||||||
ThreadHiding.toggler = $.el 'span',
|
|
||||||
id: 'hidden-label'
|
|
||||||
innerHTML: ' — <span id="hidden-count"></span>'
|
|
||||||
$.add Index.navLinks, ThreadHiding.toggler
|
|
||||||
removeToggle: ->
|
|
||||||
return unless ThreadHiding.toggler
|
|
||||||
$.rm ThreadHiding.toggler
|
|
||||||
delete ThreadHiding.toggler
|
|
||||||
|
|
||||||
syncCatalog: ->
|
syncCatalog: ->
|
||||||
# Sync hidden threads from the catalog into the index.
|
# Sync hidden threads from the catalog into the index.
|
||||||
@ -210,7 +188,7 @@ ThreadHiding =
|
|||||||
return if thread.isHidden
|
return if thread.isHidden
|
||||||
threadRoot = thread.OP.nodes.root.parentNode
|
threadRoot = thread.OP.nodes.root.parentNode
|
||||||
thread.isHidden = true
|
thread.isHidden = true
|
||||||
ThreadHiding.updateToggle()
|
Index.updateHideToggle()
|
||||||
|
|
||||||
return threadRoot.hidden = true unless makeStub
|
return threadRoot.hidden = true unless makeStub
|
||||||
|
|
||||||
@ -222,4 +200,4 @@ ThreadHiding =
|
|||||||
delete thread.stub
|
delete thread.stub
|
||||||
threadRoot = thread.OP.nodes.root.parentNode
|
threadRoot = thread.OP.nodes.root.parentNode
|
||||||
threadRoot.hidden = thread.isHidden = false
|
threadRoot.hidden = thread.isHidden = false
|
||||||
ThreadHiding.updateToggle()
|
Index.updateHideToggle()
|
||||||
|
|||||||
@ -267,6 +267,29 @@ Index =
|
|||||||
$.before a, strong
|
$.before a, strong
|
||||||
$.add strong, a
|
$.add strong, a
|
||||||
|
|
||||||
|
updateHideToggle: ->
|
||||||
|
hiddenCount = 0
|
||||||
|
for threadID, thread of g.BOARD.threads when thread.isHidden
|
||||||
|
hiddenCount++ if thread.ID in Index.liveThreadIDs
|
||||||
|
unless hiddenCount
|
||||||
|
Index.removeHideToggle()
|
||||||
|
return
|
||||||
|
unless Index.toggler
|
||||||
|
Index.addHideToggle()
|
||||||
|
$('#hidden-count', Index.navLinks).textContent = if hiddenCount is 1
|
||||||
|
'1 hidden thread'
|
||||||
|
else
|
||||||
|
"#{hiddenCount} hidden threads"
|
||||||
|
addHideToggle: ->
|
||||||
|
Index.toggler = $.el 'span',
|
||||||
|
id: 'hidden-label'
|
||||||
|
innerHTML: ' — <span id="hidden-count"></span>'
|
||||||
|
$.add Index.navLinks, Index.toggler
|
||||||
|
removeHideToggle: ->
|
||||||
|
return unless Index.toggler
|
||||||
|
$.rm Index.toggler
|
||||||
|
delete Index.toggler
|
||||||
|
|
||||||
update: (pageNum, forceReparse) ->
|
update: (pageNum, forceReparse) ->
|
||||||
return unless navigator.onLine
|
return unless navigator.onLine
|
||||||
delete Index.pageNum
|
delete Index.pageNum
|
||||||
@ -386,6 +409,7 @@ Index =
|
|||||||
$.nodes Index.nodes
|
$.nodes Index.nodes
|
||||||
Main.callbackNodes Thread, threads
|
Main.callbackNodes Thread, threads
|
||||||
Main.callbackNodes Post, posts
|
Main.callbackNodes Post, posts
|
||||||
|
Index.updateHideToggle()
|
||||||
$.event 'IndexRefresh'
|
$.event 'IndexRefresh'
|
||||||
|
|
||||||
buildReplies: (threadRoots) ->
|
buildReplies: (threadRoots) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user