Skip to content

Commit

Permalink
Consolidate all TCCP pathname storage logic in htmx module
Browse files Browse the repository at this point in the history
  • Loading branch information
contolini committed Mar 22, 2024
1 parent 8bdd7cc commit ebc62fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 7 additions & 1 deletion cfgov/unprocessed/apps/tccp/js/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ htmx.defineExtension('htmx-url-param', {
});

/**
* htmx extension that stores the page's pathname in web
* htmx extension that stores the page's path in web
* storage whenever it's updated
* See https://htmx.org/extensions/
* See https://htmx.org/events/#htmx:replacedInHistory
Expand All @@ -48,6 +48,12 @@ htmx.defineExtension('store-tccp-filter-path', {
},
});

// Store the path on page load before htmx has started up
webStorageProxy.setItem(
'tccp-filter-path',
window.location.pathname + window.location.search,
);

// Add htmx extensions to the dom and initialize them
document.body.setAttribute('hx-ext', 'htmx-url-param, store-tccp-filter-path');
htmx.process(document.body);
4 changes: 0 additions & 4 deletions cfgov/unprocessed/apps/tccp/js/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { attach } from '@cfpb/cfpb-atomic-component';

import webStorageProxy from '../../../js/modules/util/web-storage-proxy';

/**
* Initialize some things.
*/
function init() {
// Store the card filter query params to web storage for our breadcrumbs
webStorageProxy.setItem('tccp-filter-path', window.location.pathname);
// Attach "show more" click handler
attach('show-more', 'click', handleShowMore);
}
Expand Down

0 comments on commit ebc62fa

Please sign in to comment.