Repository navigation
Conversation
- Add static/sort.js to automatically submit sort and timeframe forms on selection change - Register /sort.js route in main.rs and include in base.html - Set explicit method and action for sort forms across subreddit, user, search, and post templates - Add onchange fallback on timeframe and sort dropdowns - Add unit test for subreddit sort form rendering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When visiting a subreddit and sorting by Top or Controversial (such as
/r/reddit/top), picking an option from the timeframe dropdown (Hour, Day, Week, Month, Year, All) does not reload the page or update the URL to?t=<timeframe>. Users currently have to manually click the tiny arrow submit button next to the dropdown for the timeframe filter to apply.Root cause
<select id="timeframe">dropdown had nochangeevent listener oronchangehandler, so choosing an option only mutated the<select>value in the DOM without submitting the parent form.<form id="sort">did not specify an explicitmethod="get"andactionattribute pointing to the active sort listing (/r/{sub}/topor/top).script-src 'self' blob:;) disallows inline script execution, so inlineonchange="..."handlers alone are blocked by the browser unless accompanied by a script served from'self'.Changes
static/sort.js): Added a small script registered insrc/main.rsas/sort.jsand loaded withdeferintemplates/base.html. It listens forchangeevents on#timeframe,#sort_select,#commentSortSelect, and#search_sort select[name="sort"]and submits the form upon selection.method="get"andactionto sort forms intemplates/subreddit.html,templates/user.html,templates/search.html, andtemplates/post.html, along with anonchange="this.form.submit()"inline fallback.<button id="sort_submit">button is kept in place so users browsing with JavaScript disabled can still submit the form manually.test_subreddit_sort_form_renderinsrc/subreddit.rsto verify thatSubredditTemplaterenders the form with the expected action, onchange handler, and script tag.Verification
cargo checkandcargo test./r/reddit/topand selecting a timeframe submits the form and reloads at/r/reddit/top?t=<timeframe>./top, multireddits (/r/rust+golang/top),/r/reddit/controversial,/user/:name, and/search./sort.jsserves HTTP 200 withcontent-type: text/javascript.