From 27e79da6b9d296ff20d8f1b800414ad039031fa5 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Fri, 22 Nov 2024 17:23:02 -0500 Subject: [PATCH] Update immutable imports for v5 (#33037) --- .../features/status/components/card.jsx | 4 ++-- .../mastodon/features/status/index.jsx | 10 ++++---- .../subscribed_languages_modal/index.jsx | 2 +- app/javascript/mastodon/models/account.ts | 24 +++++++++++-------- .../mastodon/reducers/push_notifications.js | 12 +++++----- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/app/javascript/mastodon/features/status/components/card.jsx b/app/javascript/mastodon/features/status/components/card.jsx index ee1fbe0f8fe826..136a5568a40fb2 100644 --- a/app/javascript/mastodon/features/status/components/card.jsx +++ b/app/javascript/mastodon/features/status/components/card.jsx @@ -8,7 +8,7 @@ import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; -import Immutable from 'immutable'; +import { is } from 'immutable'; import ImmutablePropTypes from 'react-immutable-proptypes'; import DescriptionIcon from '@/material-icons/400-24px/description-fill.svg?react'; @@ -73,7 +73,7 @@ export default class Card extends PureComponent { }; UNSAFE_componentWillReceiveProps (nextProps) { - if (!Immutable.is(this.props.card, nextProps.card)) { + if (!is(this.props.card, nextProps.card)) { this.setState({ embedded: false, previewLoaded: false }); } diff --git a/app/javascript/mastodon/features/status/index.jsx b/app/javascript/mastodon/features/status/index.jsx index c115f777559b30..8da3d7e11ae47d 100644 --- a/app/javascript/mastodon/features/status/index.jsx +++ b/app/javascript/mastodon/features/status/index.jsx @@ -7,7 +7,7 @@ import { Helmet } from 'react-helmet'; import { withRouter } from 'react-router-dom'; import { createSelector } from '@reduxjs/toolkit'; -import Immutable from 'immutable'; +import { List as ImmutableList } from 'immutable'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { connect } from 'react-redux'; @@ -87,7 +87,7 @@ const makeMapStateToProps = () => { (_, { id }) => id, state => state.getIn(['contexts', 'inReplyTos']), ], (statusId, inReplyTos) => { - let ancestorsIds = Immutable.List(); + let ancestorsIds = ImmutableList(); ancestorsIds = ancestorsIds.withMutations(mutable => { let id = statusId; @@ -134,14 +134,14 @@ const makeMapStateToProps = () => { }); } - return Immutable.List(descendantsIds); + return ImmutableList(descendantsIds); }); const mapStateToProps = (state, props) => { const status = getStatus(state, { id: props.params.statusId }); - let ancestorsIds = Immutable.List(); - let descendantsIds = Immutable.List(); + let ancestorsIds = ImmutableList(); + let descendantsIds = ImmutableList(); if (status) { ancestorsIds = getAncestorsIds(state, { id: status.get('in_reply_to_id') }); diff --git a/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx b/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx index 0531346f91dad0..895a2686e842e6 100644 --- a/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx +++ b/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx @@ -23,7 +23,7 @@ const getAccountLanguages = createSelector([ (state, accountId) => state.getIn(['timelines', `account:${accountId}`, 'items'], ImmutableList()), state => state.get('statuses'), ], (statusIds, statuses) => - new ImmutableSet(statusIds.map(statusId => statuses.get(statusId)).filter(status => !status.get('reblog')).map(status => status.get('language')))); + ImmutableSet(statusIds.map(statusId => statuses.get(statusId)).filter(status => !status.get('reblog')).map(status => status.get('language')))); const mapStateToProps = (state, { accountId }) => ({ acct: state.getIn(['accounts', accountId, 'acct']), diff --git a/app/javascript/mastodon/models/account.ts b/app/javascript/mastodon/models/account.ts index 8e8e3b0e8dffe8..34fd1b57e99484 100644 --- a/app/javascript/mastodon/models/account.ts +++ b/app/javascript/mastodon/models/account.ts @@ -1,5 +1,5 @@ import type { RecordOf } from 'immutable'; -import { List, Record as ImmutableRecord } from 'immutable'; +import { List as ImmutableList, Record as ImmutableRecord } from 'immutable'; import escapeTextContentForBrowser from 'escape-html'; @@ -48,9 +48,9 @@ export interface AccountShape extends Required< Omit > { - emojis: List; - fields: List; - roles: List; + emojis: ImmutableList; + fields: ImmutableList; + roles: ImmutableList; display_name_html: string; note_emojified: string; note_plain: string | null; @@ -70,8 +70,8 @@ export const accountDefaultValues: AccountShape = { indexable: false, display_name: '', display_name_html: '', - emojis: List(), - fields: List(), + emojis: ImmutableList(), + fields: ImmutableList(), group: false, header: '', header_static: '', @@ -82,7 +82,7 @@ export const accountDefaultValues: AccountShape = { note: '', note_emojified: '', note_plain: 'string', - roles: List(), + roles: ImmutableList(), uri: '', url: '', username: '', @@ -139,11 +139,15 @@ export function createAccountFromServerJSON(serverJSON: ApiAccountJSON) { return AccountFactory({ ...accountJSON, moved: moved?.id, - fields: List( + fields: ImmutableList( serverJSON.fields.map((field) => createAccountField(field, emojiMap)), ), - emojis: List(serverJSON.emojis.map((emoji) => CustomEmojiFactory(emoji))), - roles: List(serverJSON.roles?.map((role) => AccountRoleFactory(role))), + emojis: ImmutableList( + serverJSON.emojis.map((emoji) => CustomEmojiFactory(emoji)), + ), + roles: ImmutableList( + serverJSON.roles?.map((role) => AccountRoleFactory(role)), + ), display_name_html: emojify( escapeTextContentForBrowser(displayName), emojiMap, diff --git a/app/javascript/mastodon/reducers/push_notifications.js b/app/javascript/mastodon/reducers/push_notifications.js index fa8af0e8ccbdaf..35c2955b857bea 100644 --- a/app/javascript/mastodon/reducers/push_notifications.js +++ b/app/javascript/mastodon/reducers/push_notifications.js @@ -1,11 +1,11 @@ -import Immutable from 'immutable'; +import { Map as ImmutableMap } from 'immutable'; import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, CLEAR_SUBSCRIPTION, SET_ALERTS } from '../actions/push_notifications'; import { STORE_HYDRATE } from '../actions/store'; -const initialState = Immutable.Map({ +const initialState = ImmutableMap({ subscription: null, - alerts: new Immutable.Map({ + alerts: ImmutableMap({ follow: false, follow_request: false, favourite: false, @@ -24,7 +24,7 @@ export default function push_subscriptions(state = initialState, action) { if (push_subscription) { return state - .set('subscription', new Immutable.Map({ + .set('subscription', ImmutableMap({ id: push_subscription.get('id'), endpoint: push_subscription.get('endpoint'), })) @@ -36,11 +36,11 @@ export default function push_subscriptions(state = initialState, action) { } case SET_SUBSCRIPTION: return state - .set('subscription', new Immutable.Map({ + .set('subscription', ImmutableMap({ id: action.subscription.id, endpoint: action.subscription.endpoint, })) - .set('alerts', new Immutable.Map(action.subscription.alerts)) + .set('alerts', ImmutableMap(action.subscription.alerts)) .set('isSubscribed', true); case SET_BROWSER_SUPPORT: return state.set('browserSupport', action.value);