feat: clone rooms

fix #191
pull/220/head
Specht, David 2022-03-25 16:47:19 +01:00 committed by sualko
parent 9564fcd63c
commit 46806ebe1a
2 changed files with 42 additions and 7 deletions

View File

@ -43,7 +43,7 @@ const App: React.FC<Props> = () => {
const [orderBy, setOrderBy] = useState<SortKey>('name'); const [orderBy, setOrderBy] = useState<SortKey>('name');
const [sortOrder, setSortOrder] = useState(SortOrder.ASC); const [sortOrder, setSortOrder] = useState(SortOrder.ASC);
const rows = rooms.sort(sortRooms(orderBy, sortOrder)).map(room => <RoomRow room={room} restriction={restriction} key={room.id} updateRoom={updateRoom} deleteRoom={deleteRoom} />); const rows = rooms.sort(sortRooms(orderBy, sortOrder)).map(room => <RoomRow room={room} restriction={restriction} key={room.id} updateRoom={updateRoom} deleteRoom={deleteRoom} cloneRoom={cloneRoom}/>);
useEffect(() => { useEffect(() => {
Promise.all([ Promise.all([
@ -105,13 +105,18 @@ const App: React.FC<Props> = () => {
function updateRoom(room: Room) { function updateRoom(room: Room) {
return api.updateRoom(room).then(updatedRoom => { return api.updateRoom(room).then(updatedRoom => {
setRooms(rooms.map(room => {
if (room.id === updatedRoom.id) {
return updatedRoom;
}
return room; if (!rooms.find(room => room.id === updatedRoom.id)) {
})); setRooms(rooms.concat([updatedRoom]));
} else {
setRooms(rooms.map(room => {
if (room.id === updatedRoom.id) {
return updatedRoom;
}
return room;
}));
}
}); });
} }
@ -121,6 +126,25 @@ const App: React.FC<Props> = () => {
}); });
} }
function cloneRoom(room: Room) {
if (room.moderatorToken !== null) {
room.moderatorToken = 'true';
}
return api.createRoom(room.name, room.access, room.maxParticipants).then(newRoom => {
api.getRoomShares(room.id).then(shares => shares.forEach(share => {
api.createRoomShare(newRoom.id, share.shareType, share.shareWith, share.permission);
}));
updateRoom({
...room,
uid: newRoom.uid,
id: newRoom.id,
});
});
}
const maxRooms = restriction?.maxRooms || 0; const maxRooms = restriction?.maxRooms || 0;
const quota = maxRooms < 0 ? t('bbb', 'unlimited') : rooms.filter(room => room.userId === OC.currentUser).length + ' / ' + maxRooms; const quota = maxRooms < 0 ? t('bbb', 'unlimited') : rooms.filter(room => room.userId === OC.currentUser).length + ' / ' + maxRooms;
@ -151,6 +175,7 @@ const App: React.FC<Props> = () => {
</th> </th>
<th /> <th />
<th /> <th />
<th />
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

@ -11,6 +11,7 @@ type Props = {
restriction?: Restriction; restriction?: Restriction;
updateRoom: (room: Room) => Promise<void>; updateRoom: (room: Room) => Promise<void>;
deleteRoom: (id: number) => void; deleteRoom: (id: number) => void;
cloneRoom: (room: Room) => void;
} }
type RecordingsNumberProps = { type RecordingsNumberProps = {
@ -175,6 +176,10 @@ const RoomRow: React.FC<Props> = (props) => {
return <EditableValue field={field} value={room[field]} setValue={updateRoom} type={type} options={options} />; return <EditableValue field={field} value={room[field]} setValue={updateRoom} type={type} options={options} />;
} }
function cloneRow() {
props.cloneRoom({...props.room});
}
const avatarUrl = OC.generateUrl('/avatar/' + encodeURIComponent(room.userId) + '/' + 24, { const avatarUrl = OC.generateUrl('/avatar/' + encodeURIComponent(room.userId) + '/' + 24, {
user: room.userId, user: room.userId,
size: 24, size: 24,
@ -225,6 +230,11 @@ const RoomRow: React.FC<Props> = (props) => {
<td className="edit icon-col"> <td className="edit icon-col">
<EditRoom room={props.room} restriction={props.restriction} updateProperty={updateRoom} /> <EditRoom room={props.room} restriction={props.restriction} updateProperty={updateRoom} />
</td> </td>
<td className="clone icon-col">
<button className="action-item" onClick={cloneRow} title={t('bbb', 'Clone Room')}>
<span className="icon icon-template-add icon-visible"></span>
</button>
</td>
<td className="remove icon-col"> <td className="remove icon-col">
<button className="action-item" onClick={deleteRow as any} title={t('bbb', 'Delete')}> <button className="action-item" onClick={deleteRow as any} title={t('bbb', 'Delete')}>
<span className="icon icon-delete icon-visible"></span> <span className="icon icon-delete icon-visible"></span>