Change dismissed banners to be stored server-side (#27055)
This commit is contained in:
		
							parent
							
								
									ce78a9c9ac
								
							
						
					
					
						commit
						7faa27e17d
					
				@ -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 type { PropsWithChildren } from 'react';
 | 
				
			||||||
import { useCallback, useState } from 'react';
 | 
					import { useCallback, useState, useEffect } from 'react';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { defineMessages, useIntl } from 'react-intl';
 | 
					import { defineMessages, useIntl } from 'react-intl';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { ReactComponent as CloseIcon } from '@material-symbols/svg-600/outlined/close.svg';
 | 
					import { ReactComponent as CloseIcon } from '@material-symbols/svg-600/outlined/close.svg';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { changeSetting } from 'mastodon/actions/settings';
 | 
				
			||||||
import { bannerSettings } from 'mastodon/settings';
 | 
					import { bannerSettings } from 'mastodon/settings';
 | 
				
			||||||
 | 
					import { useAppSelector, useAppDispatch } from 'mastodon/store';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { IconButton } from './icon_button';
 | 
					import { IconButton } from './icon_button';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -21,13 +28,25 @@ export const DismissableBanner: React.FC<PropsWithChildren<Props>> = ({
 | 
				
			|||||||
  id,
 | 
					  id,
 | 
				
			||||||
  children,
 | 
					  children,
 | 
				
			||||||
}) => {
 | 
					}) => {
 | 
				
			||||||
  const [visible, setVisible] = useState(!bannerSettings.get(id));
 | 
					  const dismissed = useAppSelector((state) =>
 | 
				
			||||||
 | 
					    state.settings.getIn(['dismissed_banners', id], false),
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					  const dispatch = useAppDispatch();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const [visible, setVisible] = useState(!bannerSettings.get(id) && !dismissed);
 | 
				
			||||||
  const intl = useIntl();
 | 
					  const intl = useIntl();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const handleDismiss = useCallback(() => {
 | 
					  const handleDismiss = useCallback(() => {
 | 
				
			||||||
    setVisible(false);
 | 
					    setVisible(false);
 | 
				
			||||||
    bannerSettings.set(id, true);
 | 
					    bannerSettings.set(id, true);
 | 
				
			||||||
  }, [id]);
 | 
					    dispatch(changeSetting(['dismissed_banners', id], true));
 | 
				
			||||||
 | 
					  }, [id, dispatch]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  useEffect(() => {
 | 
				
			||||||
 | 
					    if (!visible && !dismissed) {
 | 
				
			||||||
 | 
					      dispatch(changeSetting(['dismissed_banners', id], true));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }, [id, dispatch, visible, dismissed]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!visible) {
 | 
					  if (!visible) {
 | 
				
			||||||
    return null;
 | 
					    return null;
 | 
				
			||||||
 | 
				
			|||||||
@ -100,6 +100,15 @@ const initialState = ImmutableMap({
 | 
				
			|||||||
      body: '',
 | 
					      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([
 | 
					const defaultColumns = fromJS([
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user