fossar / selfoss

multipurpose rss reader, live stream, mashup, aggregation web application
https://selfoss.aditu.de
GNU General Public License v3.0
2.35k stars 343 forks source link

The auto_collapse option is ineffective #1454

Closed cr04ch closed 11 months ago

cr04ch commented 11 months ago

My config.ini has the option auto_collapse=1, but the previously expanded elements do not collapse when I click on a new element.

selfoss 2.20-8307769
Firefox 115.0.2
Chromium 115.0.5790.102
jtojnar commented 11 months ago

Thanks for reporting, that is weird.

I verified that setExpandedEntries is being called with {} as an argument but for some reason the state is not updated, even though it is passed to setState:

https://github.com/fossar/selfoss/blob/83077695ee7d3a645cab3eebe817966af5998b7d/client/js/templates/EntriesPage.jsx#L518

cr04ch commented 11 months ago

I'm not a programmer, so I can't find the root of the issue, but if I make the following changes to work around the problem, the function works for me.

diff -Nadur a/client/js/templates/EntriesPage.jsx b/client/js/templates/EntriesPage.jsx
--- a/client/js/templates/EntriesPage.jsx   2023-07-17 17:09:47.258946668 +0200
+++ b/client/js/templates/EntriesPage.jsx   2023-07-27 08:42:11.668197075 +0200
@@ -571,14 +571,14 @@
      * @param {number} id of entry
      */
     activateEntry(id) {
-        if (this.props.configuration.autoCollapse) {
-            this.collapseAllEntries();
-        }
-
         this.setSelectedEntry(id);

         // show/hide (with toolbar)
-        this.setEntryExpanded(id, true);
+        if (this.props.configuration.autoCollapse) {
+            this.setExpandedEntries({[id]: true});
+        } else {
+            this.setEntryExpanded(id, true);
+        }

         // automark as read
         const entry = this.state.entries.find((entry) => id === entry.id);
jtojnar commented 11 months ago

Thanks. Your patch is correct, though the original code should work as well – turns out you discovered a pretty nasty logic bug that got revealed when we upgraded to React 18 recently. https://github.com/fossar/selfoss/pull/1458 should fix it.