forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Glitch] Add reminder when about to post without alt text in web UI
Port 1e70da5 to glitch-soc Signed-off-by: Claire <[email protected]>
- Loading branch information
1 parent
800bea7
commit 668355a
Showing
11 changed files
with
120 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...avascript/flavours/glitch/features/ui/components/confirmation_modals/missing_alt_text.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { defineMessages, useIntl } from 'react-intl'; | ||
|
||
import type { Map as ImmutableMap, List as ImmutableList } from 'immutable'; | ||
|
||
import { submitCompose } from 'flavours/glitch/actions/compose'; | ||
import { openModal } from 'flavours/glitch/actions/modal'; | ||
import type { MediaAttachment } from 'flavours/glitch/models/media_attachment'; | ||
import { useAppDispatch, useAppSelector } from 'flavours/glitch/store'; | ||
|
||
import type { BaseConfirmationModalProps } from './confirmation_modal'; | ||
import { ConfirmationModal } from './confirmation_modal'; | ||
|
||
const messages = defineMessages({ | ||
title: { | ||
id: 'confirmations.missing_alt_text.title', | ||
defaultMessage: 'Add alt text?', | ||
}, | ||
confirm: { | ||
id: 'confirmations.missing_alt_text.confirm', | ||
defaultMessage: 'Add alt text', | ||
}, | ||
message: { | ||
id: 'confirmations.missing_alt_text.message', | ||
defaultMessage: | ||
'Your post contains media without alt text. Adding descriptions helps make your content accessible to more people.', | ||
}, | ||
secondary: { | ||
id: 'confirmations.missing_alt_text.secondary', | ||
defaultMessage: 'Post anyway', | ||
}, | ||
}); | ||
|
||
export const ConfirmMissingAltTextModal: React.FC< | ||
{ | ||
overridePrivacy: null | string; | ||
} & BaseConfirmationModalProps | ||
> = ({ onClose, overridePrivacy }) => { | ||
const intl = useIntl(); | ||
const dispatch = useAppDispatch(); | ||
const mediaId = useAppSelector( | ||
(state) => | ||
( | ||
(state.compose as ImmutableMap<string, unknown>).get( | ||
'media_attachments', | ||
) as ImmutableList<MediaAttachment> | ||
) | ||
.find( | ||
(media) => | ||
['image', 'gifv'].includes(media.get('type') as string) && | ||
((media.get('description') ?? '') as string).length === 0, | ||
) | ||
?.get('id') as string, | ||
); | ||
|
||
const handleConfirm = useCallback(() => { | ||
dispatch( | ||
openModal({ | ||
modalType: 'FOCAL_POINT', | ||
modalProps: { | ||
mediaId, | ||
}, | ||
}), | ||
); | ||
}, [dispatch, mediaId]); | ||
|
||
const handleSecondary = useCallback(() => { | ||
dispatch(submitCompose(overridePrivacy)); | ||
}, [dispatch, overridePrivacy]); | ||
|
||
return ( | ||
<ConfirmationModal | ||
title={intl.formatMessage(messages.title)} | ||
message={intl.formatMessage(messages.message)} | ||
confirm={intl.formatMessage(messages.confirm)} | ||
secondary={intl.formatMessage(messages.secondary)} | ||
onConfirm={handleConfirm} | ||
onSecondary={handleSecondary} | ||
onClose={onClose} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters