Skip to content

Commit

Permalink
Change dismissed banners to be stored server-side
Browse files Browse the repository at this point in the history
Fixes #25957
  • Loading branch information
ClearlyClaire committed Nov 29, 2023
1 parent c40cfc5 commit ff4bfe7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
25 changes: 22 additions & 3 deletions app/javascript/mastodon/components/dismissable_banner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/* eslint-disable @typescript-eslint/no-unsafe-call,
@typescript-eslint/no-unsafe-return,
@typescript-eslint/no-unsafe-assignment,
@typescript-eslint/no-unsafe-member-access
-- the settings store is not yet typed */
import type { PropsWithChildren } from 'react';
import { useCallback, useState } from 'react';
import { useCallback, useState, useEffect } from 'react';

import { defineMessages, useIntl } from 'react-intl';

import { ReactComponent as CloseIcon } from '@material-symbols/svg-600/outlined/close.svg';

import { changeSetting } from 'mastodon/actions/settings';
import { bannerSettings } from 'mastodon/settings';
import { useAppSelector, useAppDispatch } from 'mastodon/store';

import { IconButton } from './icon_button';

Expand All @@ -21,13 +28,25 @@ export const DismissableBanner: React.FC<PropsWithChildren<Props>> = ({
id,
children,
}) => {
const [visible, setVisible] = useState(!bannerSettings.get(id));
const dismissed = useAppSelector((state) =>
state.settings.getIn(['dismissed_banners', id]),
);
const dispatch = useAppDispatch();

const [visible, setVisible] = useState(!bannerSettings.get(id) && !dismissed);
const intl = useIntl();

const handleDismiss = useCallback(() => {
setVisible(false);
bannerSettings.set(id, true);
}, [id]);
dispatch(changeSetting(['dismissed_banners', id], true));
}, [id, dispatch]);

useEffect(() => {
if (!visible && !dismissed) {
dispatch(changeSetting(['dismissed_banners', id], true));
}
}, [visible, dismissed, dispatch]);

Check warning on line 49 in app/javascript/mastodon/components/dismissable_banner.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'id'. Either include it or remove the dependency array

Check warning on line 49 in app/javascript/mastodon/components/dismissable_banner.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'id'. Either include it or remove the dependency array

if (!visible) {
return null;
Expand Down
9 changes: 9 additions & 0 deletions app/javascript/mastodon/reducers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ const initialState = ImmutableMap({
body: '',
}),
}),

dismissed_banners: ImmutableMap({
'public_timeline': false,
'community_timeline': false,
'home.explore_prompt': false,
'explore/links': false,
'explore/statuses': false,
'explore/tags': false,
}),
});

const defaultColumns = fromJS([
Expand Down

0 comments on commit ff4bfe7

Please sign in to comment.