update playlist name
This commit is contained in:
parent
124e6dc894
commit
0bb83325bd
@ -90,13 +90,10 @@ const Content = ({ form, playlistId }) => {
|
|||||||
<Draggable key={index} index={index} draggableId={index.toString()}>
|
<Draggable key={index} index={index} draggableId={index.toString()}>
|
||||||
{(provided) => (
|
{(provided) => (
|
||||||
<Group ref={provided.innerRef} mt="xs" {...provided.draggableProps} position="center">
|
<Group ref={provided.innerRef} mt="xs" {...provided.draggableProps} position="center">
|
||||||
<Center {...provided.dragHandleProps}>
|
|
||||||
<IconGripVertical size="1.2rem" />
|
|
||||||
</Center>
|
|
||||||
<Paper p="xs" radius="sm" shadow="sm" withBorder spacing="xs" style={{ width: '90%' }}>
|
<Paper p="xs" radius="sm" shadow="sm" withBorder spacing="xs" style={{ width: '90%' }}>
|
||||||
<Flex direction="row" align="center" gap="lg" justify="flex-end">
|
<Flex direction="row" align="center" gap="lg" justify="flex-end">
|
||||||
<Image height={100} src={'/api/file/' + form.getInputProps(`files.${index}.id`).value} />
|
|
||||||
<Text>{form.getInputProps(`files.${index}.name`).value}</Text>
|
<Text>{form.getInputProps(`files.${index}.name`).value}</Text>
|
||||||
|
<Image width={150} src={'/api/file/' + form.getInputProps(`files.${index}.id`).value} />
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required
|
||||||
hideControls
|
hideControls
|
||||||
@ -108,13 +105,16 @@ const Content = ({ form, playlistId }) => {
|
|||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
<Center {...provided.dragHandleProps}>
|
||||||
|
<IconGripVertical size="1.2rem" />
|
||||||
|
</Center>
|
||||||
</Group>
|
</Group>
|
||||||
)}
|
)}
|
||||||
</Draggable>
|
</Draggable>
|
||||||
));
|
));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box mx="auto">
|
<Box mx="auto" maw={1200}>
|
||||||
<DragDropContext
|
<DragDropContext
|
||||||
onDragEnd={({ destination, source }) => {
|
onDragEnd={({ destination, source }) => {
|
||||||
form.reorderListItem('files', { from: source.index, to: destination.index });
|
form.reorderListItem('files', { from: source.index, to: destination.index });
|
||||||
|
@ -11,12 +11,12 @@ import Content from './content';
|
|||||||
const Playlist = (item) => {
|
const Playlist = (item) => {
|
||||||
const id = window.location.href.split('/').slice(-1)[0];
|
const id = window.location.href.split('/').slice(-1)[0];
|
||||||
const [playlist, setPlaylist] = useState(null);
|
const [playlist, setPlaylist] = useState(null);
|
||||||
const [update, setUpdate] = useState(false);
|
const [showUpdate, setShowUpdate] = useState(false);
|
||||||
const [addFile, setAddFile] = useState(false);
|
const [addFile, setAddFile] = useState(false);
|
||||||
const [files, setFiles] = useState([]);
|
const [files, setFiles] = useState([]);
|
||||||
const [duration, setDuration] = useState(0);
|
const [duration, setDuration] = useState(0);
|
||||||
|
|
||||||
const toggleUpdate = () => setUpdate(!update);
|
const toggleUpdate = () => setShowUpdate(!showUpdate);
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
@ -32,6 +32,10 @@ const Playlist = (item) => {
|
|||||||
setDuration(duration);
|
setDuration(duration);
|
||||||
}, [form.values]);
|
}, [form.values]);
|
||||||
|
|
||||||
|
const updatePlaylist = (playlist) => {
|
||||||
|
setPlaylist(playlist);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (JSON.stringify(item) !== '{}') {
|
if (JSON.stringify(item) !== '{}') {
|
||||||
setPlaylist(item);
|
setPlaylist(item);
|
||||||
@ -39,7 +43,7 @@ const Playlist = (item) => {
|
|||||||
API.getPlaylist(id)
|
API.getPlaylist(id)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
console.log(res.data)
|
console.log(res.data);
|
||||||
setPlaylist(res.data);
|
setPlaylist(res.data);
|
||||||
form.setFieldValue('files', res.data.files);
|
form.setFieldValue('files', res.data.files);
|
||||||
}
|
}
|
||||||
@ -78,10 +82,14 @@ const Playlist = (item) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
<Paper p="xs" radius="sm" shadow="sm" withBorder my="md">
|
<Paper p="xs" radius="sm" shadow="sm" withBorder my="md">
|
||||||
<Content form={form} playlistId={id}/>
|
<Content form={form} playlistId={id} />
|
||||||
</Paper>
|
</Paper>
|
||||||
<Button>Save</Button>
|
<ModalUpdate
|
||||||
<ModalUpdate open={update} handler={toggleUpdate} id={playlist?.id} />
|
opened={showUpdate}
|
||||||
|
handler={toggleUpdate}
|
||||||
|
item={playlist}
|
||||||
|
updatePlaylist={(playlist) => updatePlaylist(playlist)}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@ const PlaylistViewEditor = ({ item, handler, buttonText, APICall }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
console.log(item);
|
||||||
// todo permissions
|
// todo permissions
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
@ -25,14 +25,10 @@ const PlaylistViewEditor = ({ item, handler, buttonText, APICall }) => {
|
|||||||
if (form.validate().hasErrors) return;
|
if (form.validate().hasErrors) return;
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
const res = await APICall(item?.id, { name: form.values.name });
|
||||||
if (item) {
|
|
||||||
form.values.id = item?.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await APICall(form.values);
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
handleClose(res.data);
|
item.name = form.values.name;
|
||||||
|
handleClose(item);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
// todo
|
// todo
|
||||||
|
@ -13,6 +13,9 @@ const API = {
|
|||||||
createPlaylist(data) {
|
createPlaylist(data) {
|
||||||
return caller().put('/playlist', data);
|
return caller().put('/playlist', data);
|
||||||
},
|
},
|
||||||
|
updatePlaylist(playlistId, data) {
|
||||||
|
return caller().post(`/playlist/${playlistId}/update`, data);
|
||||||
|
},
|
||||||
getPlaylist(id) {
|
getPlaylist(id) {
|
||||||
return caller().get(`/playlist/${id}`);
|
return caller().get(`/playlist/${id}`);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user