Skip to content

Commit

Permalink
refactor: Extrait la gestion du re-trigger dans le cookiesService
Browse files Browse the repository at this point in the history
  • Loading branch information
Mintoo200 committed Oct 21, 2024
1 parent 6ad3a5f commit 47e549a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/client/services/cookies/cookies.service.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function aCookiesService(override?: Partial<CookiesService>): CookiesServ
allowService: jest.fn(),
isServiceAllowed: jest.fn(() => true),
openPanel: jest.fn(),
triggerJobs: jest.fn(),
...override,
};
}
2 changes: 2 additions & 0 deletions src/client/services/cookies/cookies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ export interface CookiesService {
allowService(nom: string): void;

openPanel(): void;

triggerJobs(): void;
}
4 changes: 4 additions & 0 deletions src/client/services/cookies/null/null.cookies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export class NullCookiesService implements CookiesService {
openPanel(): void {
return;
}

triggerJobs(): void {
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type TarteAuCitron = {
openPanel: () => void,
}
state: Record<TarteAuCitron.ServiceName, boolean>;
triggerJobsAfterAjaxCall: () => void;
}

export class TarteAuCitronCookiesService implements CookiesService {
Expand Down Expand Up @@ -87,4 +88,8 @@ export class TarteAuCitronCookiesService implements CookiesService {
openPanel(): void {
return this.tarteaucitron.userInterface.openPanel();
}

triggerJobs(): void {
return this.tarteaucitron.triggerJobsAfterAjaxCall();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function aTarteAuCitron(override?: Partial<TarteAuCitron>): TarteAuCitron
job: undefined,
services: {},
state: {},
triggerJobsAfterAjaxCall: jest.fn(),
user: {},
userInterface: {
openPanel: jest.fn(),
Expand Down
12 changes: 3 additions & 9 deletions src/pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,14 @@ export default function App({ Component, pageProps }: AppPropsWithLayout) {


const previousPath = useRef('');
const cookiesService = dependenciesContainerInstance.cookiesService;
useEffect(() => {
// eslint-disable-next-line
console.log(previousPath.current, router.asPath);
if (previousPath.current && previousPath.current !== router.asPath) {
// eslint-disable-next-line
console.log('trigger jobs');
// FIXME (GAFI 08-10-2024): Déplacer dans le service
// eslint-disable-next-line
// @ts-ignore
window.tarteaucitron.triggerJobsAfterAjaxCall();
cookiesService.triggerJobs();
}
previousPath.current = router.asPath;
return () => { document.dispatchEvent(new Event('navigate')); };
}, [router.asPath, sessionId]);
}, [cookiesService, router.asPath, sessionId]);

const getLayout = Component.getLayout ?? defaultLayout;
return (
Expand Down

0 comments on commit 47e549a

Please sign in to comment.