[FIX] website: remove global event listener from the configurator

[1] refactored the Configurator from its own frontend app to a component
of the web client.

[2] forward-ported a fix, targeting the Configurator standalone app,
which did not need to remove the window "popstate" event listener. But
after [1], that global listener was never removed.

This commit changes adding this event listener by using the
useExternalListener hook, which will remove it when the Configurator is
unmounted.

[1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b
[2]: https://github.com/odoo/odoo/commit/3d3f9ffaa7caf5280602553459062fc6c9e35856

task-2687506

Part-of: odoo/odoo#97408
This commit is contained in:
Younn Olivier
2022-08-31 22:13:21 +02:00
committed by qsm-odoo
parent c65d1dda4a
commit 444b07f031
@@ -9,7 +9,7 @@ import {svgToPNG} from 'website.utils';
import { useService } from "@web/core/utils/hooks";
import { registry } from "@web/core/registry";
const { Component, onMounted, reactive, useEnv, useRef, useState, useSubEnv, onWillStart } = owl;
const { Component, onMounted, reactive, useEnv, useRef, useState, useSubEnv, onWillStart, useExternalListener } = owl;
const ROUTES = {
descriptionScreen: 2,
@@ -608,13 +608,13 @@ class Configurator extends Component {
this.router = useService('router');
// Using the back button must update the router state.
window.addEventListener("popstate", () => {
useExternalListener(window, "popstate", () => {
const match = window.location.pathname.match(/\/website\/configurator\/(.*)$/);
const step = parseInt(match && match[1], 10) || 1;
// Do not use navigate because URL is already updated.
this.state.currentStep = step;
});
const initialStep = this.props.action.context.params && this.props.action.context.params.step;
const store = reactive(new Store(), () => this.updateStorage(store));