Convert instance to use zod

This commit is contained in:
Alex Gleason
2023-09-23 20:41:24 -05:00
parent 970ad24de9
commit 3b630ed8fb
46 changed files with 326 additions and 195 deletions

View File

@ -77,7 +77,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
const compose = useCompose(id);
const showSearch = useAppSelector((state) => state.search.submitted && !state.search.hidden);
const maxTootChars = configuration.getIn(['statuses', 'max_characters']) as number;
const maxTootChars = configuration.statuses.max_characters;
const scheduledStatusCount = useAppSelector((state) => state.scheduled_statuses.size);
const features = useFeatures();

View File

@ -8,7 +8,6 @@ import { useAppDispatch, useCompose, useInstance } from 'soapbox/hooks';
import DurationSelector from './duration-selector';
import type { Map as ImmutableMap } from 'immutable';
import type { AutoSuggestion } from 'soapbox/components/autosuggest-input';
const messages = defineMessages({
@ -115,13 +114,14 @@ const PollForm: React.FC<IPollForm> = ({ composeId }) => {
const compose = useCompose(composeId);
const pollLimits = configuration.get('polls') as ImmutableMap<string, number>;
const options = compose.poll?.options;
const expiresIn = compose.poll?.expires_in;
const isMultiple = compose.poll?.multiple;
const maxOptions = pollLimits.get('max_options') as number;
const maxOptionChars = pollLimits.get('max_characters_per_option') as number;
const {
max_options: maxOptions,
max_characters_per_option: maxOptionChars,
} = configuration.polls;
const onRemoveOption = (index: number) => dispatch(removePollOption(composeId, index));
const onChangeOption = (index: number, title: string) => dispatch(changePollOption(composeId, index, title));

View File

@ -4,14 +4,12 @@ import { defineMessages, IntlShape, useIntl } from 'react-intl';
import { IconButton } from 'soapbox/components/ui';
import { useInstance } from 'soapbox/hooks';
import type { List as ImmutableList } from 'immutable';
const messages = defineMessages({
upload: { id: 'upload_button.label', defaultMessage: 'Add media attachment' },
});
export const onlyImages = (types: ImmutableList<string>) => {
return Boolean(types && types.every(type => type.startsWith('image/')));
export const onlyImages = (types: string[] | undefined): boolean => {
return types?.every((type) => type.startsWith('image/')) ?? false;
};
export interface IUploadButton {
@ -38,7 +36,7 @@ const UploadButton: React.FC<IUploadButton> = ({
const { configuration } = useInstance();
const fileElement = useRef<HTMLInputElement>(null);
const attachmentTypes = configuration.getIn(['media_attachments', 'supported_mime_types']) as ImmutableList<string>;
const attachmentTypes = configuration.media_attachments.supported_mime_types;
const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
if (e.target.files?.length) {
@ -78,7 +76,7 @@ const UploadButton: React.FC<IUploadButton> = ({
ref={fileElement}
type='file'
multiple
accept={attachmentTypes && attachmentTypes.toArray().join(',')}
accept={attachmentTypes?.join(',')}
onChange={handleChange}
disabled={disabled}
className='hidden'