Skip to content

Commit

Permalink
Collapse when opening and expand after rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
Omry Zobel authored and ZobelOmry committed Oct 24, 2022
1 parent 453b0e6 commit 2983a62
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/modules/document/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function openWidget(): void {
academyHat.classList.remove('slide-in');
}

export function collapseWidget(): void {
function collapse(): void {
const widget = document.getElementById('strigo-widget');
widget.classList.remove('slide-in');
widget.classList.remove('loaded');
Expand All @@ -139,6 +139,12 @@ export function collapseWidget(): void {
academyHat.classList.add('slide-in');
}

export function collapseWidget(): void {
sessionManager.setSessionValue('shouldPanelBeOpen', false);

collapse();
}

const navigationObserver = function (pageMutations): void {
const filteredMutations = pageMutations.filter((mutation) => {
return ['HTML', 'BODY'].includes(mutation.target.nodeName);
Expand Down Expand Up @@ -167,7 +173,7 @@ export function toggleWidget(): void {
if (shouldPanelBeOpen) {
openWidget();
} else {
collapseWidget();
collapse();
}
}

Expand Down Expand Up @@ -219,7 +225,7 @@ export function createWidget(url: string): HTMLIFrameElement {
if (shouldPanelBeOpen) {
openWidget();
} else {
collapseWidget();
collapse();
}

return strigoExercisesIframe;
Expand Down
13 changes: 10 additions & 3 deletions src/modules/listeners/listeners.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as sessionManager from '../session/session';
import * as configManager from '../config/config';
import ovelayWidget from '../widgets/overlay';
import overlayWidget from '../widgets/overlay';
import { Logger } from '../../services/logger';
import { WidgetFlavors } from '../widgets/widget.types';

Expand All @@ -16,7 +16,7 @@ function onHostEventHandler(ev: MessageEvent<any>): void {
Logger.info('Panel move message received');

if (sessionManager.getWidgetFlavor() === WidgetFlavors.OVERLAY) {
ovelayWidget.move();
overlayWidget.move();
}

break;
Expand All @@ -40,12 +40,19 @@ function onHostEventHandler(ev: MessageEvent<any>): void {
Logger.info('Challenge event success received');

if (sessionManager.getWidgetFlavor() === WidgetFlavors.OVERLAY) {
ovelayWidget.open();
overlayWidget.open();
}

break;
}

case MessageTypes.RENDERED: {
Logger.info('Panel rendered message received');
window.Strigo?.expandPanel();

break;
}

default: {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/widgets/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IOverlayWidget } from './widget.types';
const MINIMUM_WIDTH = 342;

function postDockableStateToStrigo(): void {
Logger.info('Posting dockable state to Strigo...');
Logger.info('Posting dockable state to Strigo', {});
const dockingSide = configManager.getConfigValue('dockingSide');
const strigoIframe = document.getElementById('strigo-exercises') as HTMLIFrameElement;
strigoIframe.contentWindow.postMessage({ dockable: true, dockingSide }, '*');
Expand Down Expand Up @@ -114,7 +114,7 @@ class OverlayWidget implements IOverlayWidget {

collapse(): void {
Logger.info('overlay collapse called');
documentTools.toggleWidget();
documentTools.collapseWidget();
}

open(): void {
Expand Down
12 changes: 12 additions & 0 deletions src/strigo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class StrigoSDK implements IStrigoSDK {

if (openWidget) {
this.open();

// Collapse the panel so it would open when fully loaded
sessionManager.setSessionValue('shouldPanelBeOpen', false);
this.collapse();
}
} catch (err) {
Logger.error('Could not setup SDK', { err });
Expand Down Expand Up @@ -191,6 +195,14 @@ class StrigoSDK implements IStrigoSDK {
}
}

expandPanel(): void {
Logger.info('Expanding academy panel');
const config = configManager.getLocalStorageConfig();

const widget = widgetFactory.getWidget(config.selectedWidgetFlavor);
widget.open();
}

collapse(): void {
Logger.info('Collapsing academy panel');
const { selectedWidgetFlavor } = configManager.getLocalStorageConfig();
Expand Down
1 change: 1 addition & 0 deletions src/strigo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface IStrigoSDK {
init: () => void;
setup: (data?: SDKSetupData) => Promise<void>;
open: () => void;
expandPanel: () => void;
collapse?: () => void;
shutdown: () => void;
destroy: () => void;
Expand Down

0 comments on commit 2983a62

Please sign in to comment.