Skip to content

Commit

Permalink
Make banner work when re-loaded (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibobo authored May 29, 2024
1 parent 0dd17d9 commit 4e0d079
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/components/IubendaCookieSolutionBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,32 @@ const IubendaCookieSolutionBanner = ({ config, version }: Props) => {
useEffect(() => {
validateConfig(config);

(window as any)._iub = (window as any)._iub || [];
(window as any)._iub.csConfiguration = config;
(window as any)._iub.csConfiguration.callback = {
onPreferenceExpressedOrNotNeeded: function (preferences: any) {
// TODO: Figure out what the "preferences.consent" property really means since it's behavior is not documented.

if (!preferences) {
dispatchUserPreferences({ type: 'consent_not_needed' });

return;
} else {
dispatchUserPreferences({
type: 'update',
rawData: preferences,
});
}
},
};
const _iub = ((window as any)._iub = (window as any)._iub || []);

if (_iub.csReady && _iub.cs?.api.isPreferenceExpressed()) {
dispatchUserPreferences({
type: 'update',
rawData: _iub.cs.consent,
});
} else {
_iub.csConfiguration = config;
_iub.csConfiguration.callback = {
onPreferenceExpressedOrNotNeeded: function (preferences: any) {
// TODO: Figure out what the "preferences.consent" property really means since it's behavior is not documented.

if (!preferences) {
dispatchUserPreferences({ type: 'consent_not_needed' });

return;
} else {
dispatchUserPreferences({
type: 'update',
rawData: preferences,
});
}
},
};
}
}, [config, dispatchUserPreferences]);

return (
Expand Down

0 comments on commit 4e0d079

Please sign in to comment.