diff --git a/plugins/love-resources/src/components/ControlExt.svelte b/plugins/love-resources/src/components/ControlExt.svelte index ae5c1d3e8a..376c430180 100644 --- a/plugins/love-resources/src/components/ControlExt.svelte +++ b/plugins/love-resources/src/components/ControlExt.svelte @@ -19,30 +19,36 @@ import { Floor, Invite, + isOffice, JoinRequest, + loveId, Office, ParticipantInfo, RequestStatus, Room, - RoomType, - isOffice, - loveId + RoomType } from '@hcengineering/love' import { getEmbeddedLabel } from '@hcengineering/platform' - import { MessageBox, createQuery, getClient } from '@hcengineering/presentation' + import { createQuery, getClient, MessageBox } from '@hcengineering/presentation' import { - Location, - PopupResult, closePopup, eventToHTMLElement, + Location, location, + PopupResult, showPopup, tooltip } from '@hcengineering/ui' import view from '@hcengineering/view' import { onDestroy } from 'svelte' import workbench from '@hcengineering/workbench' - import { closeWidget, openWidget, sidebarStore } from '@hcengineering/workbench-resources' + import { + closeWidget, + minimizeSidebar, + openWidget, + sidebarStore, + SidebarVariant + } from '@hcengineering/workbench-resources' import love from '../plugin' import { @@ -283,8 +289,20 @@ showPopup(CamSettingPopup, {}, eventToHTMLElement(e)) } + $: isVideoWidgetOpened = $sidebarStore.widgetsState.has(love.ids.VideoWidget) + + $: if ( + isVideoWidgetOpened && + $sidebarStore.widget === undefined && + $location.path[2] !== loveId && + $sidebarStore.widgetsState.get(love.ids.VideoWidget)?.closedByUser !== true + ) { + sidebarStore.update((s) => ({ ...s, widget: love.ids.VideoWidget, variant: SidebarVariant.EXPANDED })) + } + function checkActiveVideo (loc: Location, video: boolean, room: Ref | undefined): void { - const isOpened = $sidebarStore.widgetsState.get(love.ids.VideoWidget) + const isOpened = $sidebarStore.widgetsState.has(love.ids.VideoWidget) + if (room === undefined) { if (isOpened) { closeWidget(love.ids.VideoWidget) @@ -292,13 +310,22 @@ return } - if (loc.path[2] !== loveId && video) { - if (isOpened) return - const widget = client.getModel().findAllSync(workbench.class.Widget, { _id: love.ids.VideoWidget })[0] - if (widget === undefined) return - openWidget(widget, { - room - }) + if (video) { + if (!isOpened) { + const widget = client.getModel().findAllSync(workbench.class.Widget, { _id: love.ids.VideoWidget })[0] + if (widget === undefined) return + openWidget( + widget, + { + room + }, + loc.path[2] !== loveId + ) + } + + if (loc.path[2] === loveId && $sidebarStore.widget === love.ids.VideoWidget) { + minimizeSidebar() + } } else { closeWidget(love.ids.VideoWidget) } diff --git a/plugins/love-resources/src/components/LoveWidget.svelte b/plugins/love-resources/src/components/LoveWidget.svelte index c0bcb5dc73..1d96d51c6f 100644 --- a/plugins/love-resources/src/components/LoveWidget.svelte +++ b/plugins/love-resources/src/components/LoveWidget.svelte @@ -79,7 +79,7 @@ {/if} {#if $floors.length > 1} -
+
{/if} @@ -92,7 +92,6 @@ flex-direction: column; justify-content: space-between; height: 100%; - padding-right: 0.5rem; padding-bottom: 1rem; } diff --git a/plugins/love-resources/src/components/Room.svelte b/plugins/love-resources/src/components/Room.svelte index 3f0bb1e38a..e1d2bd92d4 100644 --- a/plugins/love-resources/src/components/Room.svelte +++ b/plugins/love-resources/src/components/Room.svelte @@ -379,7 +379,7 @@ diff --git a/plugins/workbench-resources/src/components/sidebar/widgets/WidgetsBar.svelte b/plugins/workbench-resources/src/components/sidebar/widgets/WidgetsBar.svelte index 8635252380..5f5717b4db 100644 --- a/plugins/workbench-resources/src/components/sidebar/widgets/WidgetsBar.svelte +++ b/plugins/workbench-resources/src/components/sidebar/widgets/WidgetsBar.svelte @@ -19,7 +19,7 @@ import WidgetPresenter from './/WidgetPresenter.svelte' import AddWidgetsPopup from './AddWidgetsPopup.svelte' - import { openWidget, sidebarStore, SidebarVariant } from '../../../sidebar' + import { minimizeSidebar, openWidget, sidebarStore } from '../../../sidebar' export let widgets: Widget[] = [] export let preferences: WidgetPreference[] = [] @@ -31,9 +31,9 @@ function handleSelectWidget (widget: Widget): void { if (selected === widget._id) { - sidebarStore.update((state) => ({ ...state, widget: undefined, variant: SidebarVariant.MINI })) + minimizeSidebar(true) } else { - openWidget(widget) + openWidget(widget, $sidebarStore.widgetsState.get(widget._id)?.data, true) } } diff --git a/plugins/workbench-resources/src/sidebar.ts b/plugins/workbench-resources/src/sidebar.ts index 067896011a..4510ca91e6 100644 --- a/plugins/workbench-resources/src/sidebar.ts +++ b/plugins/workbench-resources/src/sidebar.ts @@ -30,6 +30,7 @@ export interface WidgetState { data?: Record tabs: WidgetTab[] tab?: string + closedByUser?: boolean } export interface SidebarState { @@ -95,7 +96,7 @@ function setSidebarStateToLocalStorage (state: SidebarState): void { ) } -export function openWidget (widget: Widget, data?: Record): void { +export function openWidget (widget: Widget, data?: Record, active = true): void { const state = get(sidebarStore) const { widgetsState } = state const widgetState = widgetsState.get(widget._id) @@ -106,7 +107,7 @@ export function openWidget (widget: Widget, data?: Record): void { ...state, widgetsState, variant: SidebarVariant.EXPANDED, - widget: widget._id + widget: active ? widget._id : state.widget }) } @@ -114,6 +115,10 @@ export function closeWidget (widget: Ref): void { const state = get(sidebarStore) const { widgetsState } = state + if (!widgetsState.has(widget) && state.widget !== widget && state.variant === SidebarVariant.MINI) { + return + } + widgetsState.delete(widget) if (state.widget === widget) { @@ -292,3 +297,15 @@ export function isElementFromSidebar (element: HTMLElement): boolean { return isDescendant(sidebarElement, element) } + +export function minimizeSidebar (closedByUser = false): void { + const state = get(sidebarStore) + const { widget, widgetsState } = state + const widgetState = widget == null ? undefined : widgetsState.get(widget) + + if (widget !== undefined && widgetState !== undefined && closedByUser) { + widgetsState.set(widget, { ...widgetState, closedByUser }) + } + + sidebarStore.set({ ...state, ...widgetsState, widget: undefined, variant: SidebarVariant.MINI }) +}