Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix admin delete & reset buttons #782

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/src/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const expireAt = promisify(cache.expireat).bind(cache)
const del = promisify(cache.del).bind(cache)

const addToSet = promisify(cache.sadd).bind(cache)
const removeFromSet = promisify(cache.srem).bind(cache)
const removeFromSet: (key: string, member: string) => void = promisify(cache.srem).bind(cache)
const getSet = promisify(cache.smembers).bind(cache)

const redisKeys = promisify(cache.keys).bind(cache)
Expand Down Expand Up @@ -391,7 +391,7 @@ const Redis: RedisInternal = {
},

async deleteRoomData (roomId: string): Promise<void> {
await removeFromSet(roomId)
await removeFromSet(roomIdsKey, roomId)
return await del(roomDataKey(roomId))
},

Expand Down
4 changes: 2 additions & 2 deletions src/admin/components/RoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default function (props: {roomIds: string[]}) {
const roomIds = _.sortBy(props.roomIds || [])

const clickedResetData = async () => {
if (!confirm("Are you sure you'd like to reset room data?")) return
await resetRoomData()
if (!confirm("Are you sure you'd like to reset room data? This may cause irrevocable data loss. (will also force a page refresh sorry)")) return
await resetRoomData(true)
await getAllRooms()
}

Expand Down
5 changes: 3 additions & 2 deletions src/admin/components/RoomOptionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export default function (props: {roomId: string, updateRoom: () => void, createR
}

const clickedDelete = async () => {
if (!confirm('Are you SURE you want to delete this? This will delete it from the server memory, and you will only be able to restore it if it is saved on disk.')) return
if (!confirm('Are you SURE you want to delete this? This will delete it from the server memory, and you will only be able to restore it if it is saved on disk. (Will also cause a page refresh)')) return

await deleteRoom(props.roomId)
// TODO: Remove roomId from local list
// TODO: Remove roomId from local list in a less silly way
window.location.reload()
}

const clickedSave = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ServerSettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default function ServerSettingsView (props: { serverSettings: ServerSetti
}

const clickedResetRoomData = async () => {
if (!confirm("Are you sure you'd like to reset room data?")) return
await resetRoomData()
if (!confirm("Are you sure you'd like to reset room data? This may cause irrevocable data loss.")) return
await resetRoomData(false)
}

const clickedResetBadges = async () => {
Expand Down
9 changes: 7 additions & 2 deletions src/networking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,15 @@ export async function fetchProfile (userId: string) {
}
}

export async function resetRoomData () {
export async function resetRoomData (isFromAdminPanel: boolean) {
const response = await callAzureFunction('resetRoomData')
if (response.roomData) {
myDispatch(UpdatedRoomDataAction(convertServerRoomData(response.roomData)))
if (isFromAdminPanel) {
// Admin panel doesn't have the same state tracking and you can't dispatch
window.location.reload()
} else {
myDispatch(UpdatedRoomDataAction(convertServerRoomData(response.roomData)))
}
}
}

Expand Down
Loading