Page MenuHomePhabricator

Remember Cat-a-lot state over pageloads
Open, Needs TriagePublic

Description

Story: As a user I want that Cat-a-lot remembers its state over page loads when moving through pagination or when i am doing repetitive tasks.

DoneFeatureCurrent version Wanted
X Search keyremembers last search key after page load using cookieremembers state during "same" session
Category list stateresets on page loadremembers state during "same" session
.UI open / minimized stateremembers if new page is in same namespace than lastsupport multiple namespaces
Cat-a-lot window size and positionresets on page loadremembers during "same" session

Category list state
Both search field and category list clicks call updateCats(newcat) for generating the list. Code could store the last newcat to mw.cookie.set( 'catAlot_lastcat', newcat ) and when Cat-a-lot is enabled on page load it could restore it by calling updateCats(mw.cookie.get( 'catAlot_lastcat')) . When user manually closes the Cat-a-lot ui then cookie could be cleared.
https://commons.wikimedia.org/wiki/User:Zache/Gadget-Cat-a-lot-20250602.js#L-1792
https://commons.wikimedia.org/wiki/User:Zache/Gadget-Cat-a-lot-20250602.js#L-2014

Tricky part is to know when UI should not remember last state

UI open / minimized state
Based on the code, cat-a-lot will only remember if it is open if the new page is in the same namespace. For example, if one moves from category to search or from search to category, then it will minimize cat-a-lot.

Tricky part is to know when UI should not remember last state. For this we could try to have separate states for all namespaces so that it would remember remember the state even if user moves between Search and Category namespace.

Remember Cat-a-lot window size and position
Needs investigation

Notes
Currently Cat-a-lot uses cookies, but better place is browsers localstorage.

Event Timeline

I’ve been implementing the category list persistence. Currently, the fallback call to updateCats(this.origin || 'Images') also sets catAlot_lastCategory, even if the user hasn’t interacted. This results in Cat-a-lot overriding the visible category on the next page load.

My thought: should we change this to only store the category when the user explicitly selects one (e.g., via a click)? The user can always dismiss the UI to reset, but this would make the restoration more intentional and avoid surprising results.

Let me know if you’d prefer the current behavior (diff for current behavior) or the more explicit version where we only store the category if user manually selects it. (diff for manual selection version)

Thanks, I think that I prefer it so that it also stores the category when user uses search. With that it is also sync with the search parameter which is also remembered.

Perfect! I’ll go ahead with the second version then, where both manual selections and search inputs update the stored category. That way it stays in sync with the search field too.

I've implemented two features, Category list state and UI open / minimized state using local storage:

  • The manually set category list is remembered during the same session
  • The ui remains open or closed during the same session based on user's preference.

to test:

mw.loader.load('//commons.wikimedia.org/w/index.php?title=User:Adiba_anjum3/consolidated-cat-a-lot.js&action=raw&ctype=text/javascript');

diff for reference

@adiba_anjum : I updated the code to T395770 version (ie. User:Zache/Gadget-Cat-a-lot-20250602.js ) At same time i made some small changes.

  1. Moved the warning that appears when the user tries to leave the page with active selections into a own function to keep updateSelectionCounter() simpler / easier to read.(diff)
  2. I used sessionStorage instead of localStorage to have some expiration for the values.
  3. I moved the` sessionStorage.setItem() call to after updateCats() and used CAL.currentCategory` as the value, which was also stored in a cookie. The difference between the value from user is and CAL.currentCategory is that updateCats() could do some redirect handling in solveSoftRedirect() and update CAL.currentCategory value. However, I don't think that there were any functional differences between our codes and both would have worked fine. ( diff )
  4. UI open / minimized state there were no changes except localStorage -> sessionStorage (diff)
  5. I also changed the storing the search key to session storage from cookie so that the storing the states are identical. ( diff)

Note: I think that this would require input from Cat-a-lot users to know if the persistence should work when a user opens a new tab AND also to know if the values should expire after some time. i.e., sessionStorage vs localStorage, as if we are using localStorage then values are effectively permanent, which is most likely something we do not want and even in sessionStorage values could be stored so long that user is doing something totally different and UI is restoring values which are from different context.

I made a test for a version which remembers the size and position of the window. I also changed UI so that top-border-drag and left-border-drag will be used to resizing instead of dragging from middle of the window. Third change is that i added the toggle directly to the bottom bar instead of using settings so that there is quick access to it.

How to test it
1.) Remove official cat-a-lot from settings
2.) Add following cat-a-lot loading line to your common.js (example)

mw.loader.load('//commons.wikimedia.org/w/index.php?title=User:Zache-test/Gadget-cat-a-lot_persistent_window_size_T399919.js&action=raw&ctype=text/javascript');

3.) Go to https://commons.wikimedia.org/wiki/Category:Test_images for testing

I made an update version to testing

Major changes to this

  1. Now there is setting in ui Remember category and if it is set then it will remember selected category until session is over (60 minutes from last Cat-a-lot startup). It will remember the selected category even if user closes Cat-a-lot with X button. If it is not set then doesn't remember category (ie. original behaviour)
  2. It will startup automatically if User have left the Cat-a-lot open AND
    1. the new page is one of following category page, Special:Search , Special:MediaSearch, Special: Uncategorizedimages , Special:Listfiles
    2. If page is in same namespace where Cat-a-lot was used on last Cat-a-lot startup. Special namespace is excluded
    3. User is in same special page where Cat-a-lot was started last time

note Cat-a-lot doesn't work anymore in Special:Listfiles but it is unrelated to these changes.

Here is source code : User:Zache/Gadget-Cat-a-lot-20250602.js and diff

Now there is setting in preferences on how long it remembers the state in minutes. Default is 60 minutes, but you can increased it to months.