pl-fe: Remove some immutable usage

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-11-05 23:32:43 +01:00
parent f560896311
commit 563e5288fb
41 changed files with 482 additions and 463 deletions

View File

@ -25,7 +25,7 @@ const CompareHistoryModal: React.FC<BaseModalProps & CompareHistoryModalProps> =
const loading = useAppSelector(state => state.history.getIn([statusId, 'loading']));
const versions = useAppSelector(state => state.history.get(statusId)?.items);
const status = useAppSelector(state => state.statuses.get(statusId));
const status = useAppSelector(state => state.statuses[statusId]);
const onClickClose = () => {
onClose('COMPARE_HISTORY');

View File

@ -15,7 +15,7 @@ interface IStatusCheckBox {
}
const StatusCheckBox: React.FC<IStatusCheckBox> = ({ id, disabled, checked, toggleStatusReport }) => {
const status = useAppSelector((state) => state.statuses.get(id));
const status = useAppSelector((state) => state.statuses[id]);
const onToggle: React.ChangeEventHandler<HTMLInputElement> = (e) => toggleStatusReport(e.target.checked);

View File

@ -44,7 +44,7 @@ const reportSteps = {
};
const SelectedStatus = ({ statusId }: { statusId: string }) => {
const status = useAppSelector((state) => state.statuses.get(statusId));
const status = useAppSelector((state) => state.statuses[statusId]);
if (!status) {
return null;

View File

@ -16,7 +16,6 @@ import { useAppSelector } from 'pl-fe/hooks/use-app-selector';
import { makeGetStatus } from 'pl-fe/selectors';
import type { BaseModalProps } from '../modal-root';
import type { Status as StatusEntity } from 'pl-fe/normalizers/status';
interface SelectBookmarkFolderModalProps {
statusId: string;
@ -24,7 +23,7 @@ interface SelectBookmarkFolderModalProps {
const SelectBookmarkFolderModal: React.FC<SelectBookmarkFolderModalProps & BaseModalProps> = ({ statusId, onClose }) => {
const getStatus = useCallback(makeGetStatus(), []);
const status = useAppSelector(state => getStatus(state, { id: statusId })) as StatusEntity;
const status = useAppSelector(state => getStatus(state, { id: statusId }))!;
const dispatch = useAppDispatch();
const [selectedFolder, setSelectedFolder] = useState(status.bookmark_folder);

View File

@ -1,4 +1,3 @@
import { List as ImmutableList } from 'immutable';
import React, { useState, useEffect } from 'react';
import { FormattedMessage } from 'react-intl';
@ -28,7 +27,7 @@ const GroupMediaPanel: React.FC<IGroupMediaPanel> = ({ group }) => {
const isMember = !!group?.relationship?.member;
const isPrivate = group?.locked;
const attachments: ImmutableList<AccountGalleryAttachment> = useAppSelector((state) => group ? getGroupGallery(state, group?.id) : ImmutableList());
const attachments: Array<AccountGalleryAttachment> = useAppSelector((state) => group ? getGroupGallery(state, group?.id) : []);
const handleOpenMedia = (attachment: AccountGalleryAttachment): void => {
if (attachment.type === 'video') {
@ -55,7 +54,7 @@ const GroupMediaPanel: React.FC<IGroupMediaPanel> = ({ group }) => {
const renderAttachments = () => {
const nineAttachments = attachments.slice(0, 9);
if (!nineAttachments.isEmpty()) {
if (nineAttachments.length) {
return (
<div className='grid grid-cols-3 gap-0.5 overflow-hidden rounded-md'>
{nineAttachments.map((attachment, index) => (
@ -63,7 +62,7 @@ const GroupMediaPanel: React.FC<IGroupMediaPanel> = ({ group }) => {
key={`${attachment.status.id}+${attachment.id}`}
attachment={attachment}
onOpenMedia={handleOpenMedia}
isLast={index === nineAttachments.size - 1}
isLast={index === nineAttachments.length - 1}
/>
))}
</div>

View File

@ -1,4 +1,3 @@
import { List as ImmutableList } from 'immutable';
import React, { useState, useEffect } from 'react';
import { FormattedMessage } from 'react-intl';
@ -25,7 +24,7 @@ const ProfileMediaPanel: React.FC<IProfileMediaPanel> = ({ account }) => {
const [loading, setLoading] = useState(true);
const attachments: ImmutableList<AccountGalleryAttachment> = useAppSelector((state) => account ? getAccountGallery(state, account?.id) : ImmutableList());
const attachments: Array<AccountGalleryAttachment> = useAppSelector((state) => account ? getAccountGallery(state, account?.id) : []);
const handleOpenMedia = (attachment: AccountGalleryAttachment): void => {
if (attachment.type === 'video') {
@ -53,7 +52,7 @@ const ProfileMediaPanel: React.FC<IProfileMediaPanel> = ({ account }) => {
const publicAttachments = attachments.filter(attachment => attachment.status.visibility === 'public');
const nineAttachments = publicAttachments.slice(0, 9);
if (!nineAttachments.isEmpty()) {
if (nineAttachments.length) {
return (
<div className='grid grid-cols-3 gap-0.5 overflow-hidden rounded-md'>
{nineAttachments.map((attachment, index) => (
@ -61,7 +60,7 @@ const ProfileMediaPanel: React.FC<IProfileMediaPanel> = ({ account }) => {
key={`${attachment.status.id}+${attachment.id}`}
attachment={attachment}
onOpenMedia={handleOpenMedia}
isLast={index === nineAttachments.size - 1}
isLast={index === nineAttachments.length - 1}
/>
))}
</div>