From 30dc2b5f314161fe7f50fb29d5fd563ce9c3aaaa Mon Sep 17 00:00:00 2001 From: grimhilt Date: Mon, 14 Aug 2023 12:22:21 +0200 Subject: [PATCH] fix warning --- src/pages/playlist/content.jsx | 119 ++++++++++++++++++--------------- src/pages/playlist/index.jsx | 10 +-- src/pages/playlists/index.jsx | 2 +- 3 files changed, 69 insertions(+), 62 deletions(-) diff --git a/src/pages/playlist/content.jsx b/src/pages/playlist/content.jsx index 4880ceb..0ca6c2e 100644 --- a/src/pages/playlist/content.jsx +++ b/src/pages/playlist/content.jsx @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react'; import ModalFileSelector from '../files/file-selector'; import API from '../../services/api'; import setNotification from '../errors/error-notification'; -import GrantAccess, { Perm, checkPerm } from '../../tools/grant-access'; +import { Perm, checkPerm } from '../../tools/grant-access'; import { useAuth } from '../../tools/auth-provider'; import { parseTime } from '../../tools/timeUtil'; @@ -21,10 +21,11 @@ const Content = ({ form, playlistId, playlist }) => { useEffect(() => { if (!user || !playlist) return; const canEditTmp = checkPerm(Perm.EDIT_PLAYLIST, user, playlist); - if (canEditTmp != canEdit) { + if (canEditTmp !== canEdit) { setCanEdit(canEditTmp); } return () => {}; + // eslint-disable-next-line }, [playlist, user]); const handleAddFiles = (files) => { @@ -141,67 +142,77 @@ const Content = ({ form, playlistId, playlist }) => { }); }; - const fields = form.values.files.map((_, index) => ( - - {(provided) => ( - - - - {form.getInputProps(`files.${index}.name`).value} - - { canEdit ? - handleChangeSeconds(secs, index)} - error={form.getInputProps(`files.${index}.seconds`).errors && 'This field is required'} - /> - : Display time: {parseTime(form.getInputProps(`files.${index}.seconds`).value)} - } - {canEdit ? ( + const fields = form.values.files.map((_, index) => + canEdit ? ( + + {(provided) => ( + + + + {form.getInputProps(`files.${index}.name`).value} + + handleChangeSeconds(secs, index)} + error={ + form.getInputProps(`files.${index}.seconds`).errors && 'This field is required' + } + /> + + Display time: {parseTime(form.getInputProps(`files.${index}.seconds`).value)} + handleDelete(index)}> - ) : ( - <> - )} - - - {canEdit ? ( + +
- ) : ( - <> - )} -
- )} -
- )); + + )} + + ) : ( + + + + {form.getInputProps(`files.${index}.name`).value} + + Display time: {parseTime(form.getInputProps(`files.${index}.seconds`).value)} + + + + ) + ); return ( - { - form.reorderListItem('files', { from: source.index, to: destination.index }); - changePositionValue(source.index, destination.index).then((success) => { - if (!success) { - form.reorderListItem('files', { from: destination.index, to: source.index }); - } - }); - }} - > - - {(provided) => ( -
- {fields} - {provided.placeholder} -
- )} -
-
+ {canEdit ? ( + { + form.reorderListItem('files', { from: source.index, to: destination.index }); + changePositionValue(source.index, destination.index).then((success) => { + if (!success) { + form.reorderListItem('files', { from: destination.index, to: source.index }); + } + }); + }} + > + + {(provided) => ( +
+ {fields} + {provided.placeholder} +
+ )} +
+
+ ) : ( + fields + )} {canEdit ? ( <> diff --git a/src/pages/playlist/index.jsx b/src/pages/playlist/index.jsx index 6ac2d2b..affab61 100644 --- a/src/pages/playlist/index.jsx +++ b/src/pages/playlist/index.jsx @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'; import API from '../../services/api'; import { parseTime } from '../../tools/timeUtil'; import setNotification from '../errors/error-notification'; -import ModalUpdate from '../playlists/update'; +import ModalUpdatePlaylist from '../playlists/update'; import { useForm } from '@mantine/form'; import Content from './content'; import { useNavigate } from 'react-router-dom'; @@ -50,10 +50,6 @@ const Playlist = (item) => { setDuration(duration); }, [form.values]); - const updatePlaylist = (playlist) => { - setPlaylist(playlist); - }; - useEffect(() => { if (JSON.stringify(item) !== '{}') { setPlaylist(item); @@ -119,11 +115,11 @@ const Playlist = (item) => { - updatePlaylist(playlist)} + updatePlaylist={(playlist) => setPlaylist(playlist)} /> ); diff --git a/src/pages/playlists/index.jsx b/src/pages/playlists/index.jsx index e5d0e3c..343c46f 100644 --- a/src/pages/playlists/index.jsx +++ b/src/pages/playlists/index.jsx @@ -63,7 +63,7 @@ const Playlists = () => { setPlaylist(playlists.filter((item) => item._id != id))} updateHandler={toggleModalUpdate} loadMore={loadMore}