Skip to content

Commit

Permalink
client: minor refactors for RoomSettingsForm
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Apr 30, 2024
1 parent e347440 commit 2b7d80f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions client/src/components/RoomSettingsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const { t } = useI18n();
const granted = useGrants();
const isLoadingRoomSettings = ref(false);
const inputRoomSettings: Ref<RoomSettings> = ref<RoomSettings>({
const inputRoomSettings = ref<RoomSettings>({
title: "",
description: "",
visibility: Visibility.Public,
Expand All @@ -176,30 +176,33 @@ const inputRoomSettings: Ref<RoomSettings> = ref<RoomSettings>({
autoSkipSegmentCategories: Array.from([]),
restoreQueueBehavior: BehaviorOption.Prompt,
enableVoteSkip: false,
});
}) as Ref<RoomSettings>;
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<OttApiResponseGetRoom>(`/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"),
Expand All @@ -210,7 +213,7 @@ async function loadRoomSettings() {
isLoadingRoomSettings.value = false;
}
function getRoomSettingsSubmit() {
function getRoomSettingsSubmit(): Partial<RoomSettings> {
const propsToGrants = {
title: "set-title",
description: "set-description",
Expand Down
2 changes: 1 addition & 1 deletion common/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface RoomSettings {
visibility: Visibility;
queueMode: QueueMode;
grants: Grants;
autoSkipSegmentCategories: Array<Category>;
autoSkipSegmentCategories: Category[];
restoreQueueBehavior: BehaviorOption;
enableVoteSkip: boolean;
}
Expand Down

0 comments on commit 2b7d80f

Please sign in to comment.