From 0a645a2324294d61bdfa9bb7dcd5ff166d325608 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Tue, 30 Apr 2024 07:55:01 -0400 Subject: [PATCH] client: minor refactors for RoomSettingsForm --- client/src/components/RoomSettingsForm.vue | 35 ++++++++++++---------- common/models/types.ts | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/client/src/components/RoomSettingsForm.vue b/client/src/components/RoomSettingsForm.vue index 23cd39f7f..d5dfbc1a6 100644 --- a/client/src/components/RoomSettingsForm.vue +++ b/client/src/components/RoomSettingsForm.vue @@ -167,7 +167,7 @@ const { t } = useI18n(); const granted = useGrants(); const isLoadingRoomSettings = ref(false); -const inputRoomSettings: Ref = ref({ +const inputRoomSettings = ref({ title: "", description: "", visibility: Visibility.Public, @@ -176,30 +176,33 @@ const inputRoomSettings: Ref = ref({ autoSkipSegmentCategories: Array.from([]), restoreQueueBehavior: BehaviorOption.Prompt, enableVoteSkip: false, -}); +}) as Ref; onMounted(async () => { await loadRoomSettings(); }); +function intoSettings(obj: OttApiResponseGetRoom): RoomSettings { + return { + ..._.omit(obj, [ + "name", + "isTemporary", + "users", + "queue", + "permissions", + "hasOwner", + "grants", + ]), + grants: new Grants(obj.grants), + }; +} + async function loadRoomSettings() { // we have to make an API request because visibility is not sent in sync messages. isLoadingRoomSettings.value = true; try { const res = await API.get(`/room/${store.state.room.name}`); - const settings = res.data; - settings.grants = new Grants(res.data.grants); - inputRoomSettings.value = _.pick( - settings, - "title", - "description", - "visibility", - "queueMode", - "grants", - "autoSkipSegmentCategories", - "restoreQueueBehavior", - "enableVoteSkip" - ); + inputRoomSettings.value = intoSettings(res.data); } catch (err) { toast.add({ content: t("room-settings.load-failed"), @@ -210,7 +213,7 @@ async function loadRoomSettings() { isLoadingRoomSettings.value = false; } -function getRoomSettingsSubmit() { +function getRoomSettingsSubmit(): Partial { const propsToGrants = { title: "set-title", description: "set-description", diff --git a/common/models/types.ts b/common/models/types.ts index 8026a53dd..01324aa6a 100644 --- a/common/models/types.ts +++ b/common/models/types.ts @@ -62,7 +62,7 @@ export interface RoomSettings { visibility: Visibility; queueMode: QueueMode; grants: Grants; - autoSkipSegmentCategories: Array; + autoSkipSegmentCategories: Category[]; restoreQueueBehavior: BehaviorOption; enableVoteSkip: boolean; }