Skip to content

Commit

Permalink
[semver:patch] Add a loader to initial load
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 2983a62 commit 543022b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/modules/document/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export function removeWidget(hostingAppWindow: Window): void {
hostingAppWindow.document.getElementById('strigo-widget').remove();
}

export function removeLoader(): void {
const loader = document.getElementById('loader');
loader.remove();

const academyHatIcon = document.getElementById('strigo-academy-hat-icon');
academyHatIcon.classList.remove('loader');
}

export function openWidget(): void {
const widget = document.getElementById('strigo-widget');
widget.classList.add('slide-in');
Expand Down Expand Up @@ -191,11 +199,16 @@ export function createWidget(url: string): HTMLIFrameElement {
};

const academyHatIcon = document.createElement('div');
academyHatIcon.className = 'strigo-academy-hat-icon';
academyHatIcon.className = 'strigo-academy-hat-icon loader';
academyHatIcon.id = 'strigo-academy-hat-icon';
academyHatIcon.innerHTML = ACADEMY_HAT;
academyHatDiv.appendChild(academyHatIcon);

const loaderElement = document.createElement('div');
loaderElement.className = 'loader';
loaderElement.id = 'loader';
academyHatDiv.appendChild(loaderElement);

// Create collapse div
const collapseDiv = document.createElement('div');
collapseDiv.className = 'strigo-collapse-div';
Expand Down
2 changes: 2 additions & 0 deletions src/modules/listeners/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function onHostEventHandler(ev: MessageEvent<any>): void {

case MessageTypes.RENDERED: {
Logger.info('Panel rendered message received');
sessionManager.setSessionValue('isRendered', true);

window.Strigo?.expandPanel();

break;
Expand Down
1 change: 1 addition & 0 deletions src/modules/session/session.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface StrigoSession {
isLoading?: boolean;
widgetFlavor: WidgetFlavors;
isRecordingMode?: boolean;
isRendered: boolean;
}
7 changes: 6 additions & 1 deletion src/strigo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as widgetFactory from '../modules/widgets/widget-factory';
import { MessageTypes } from '../modules/listeners/listeners.types';
import { DockingSide, User } from '../modules/config/config.types';
import { getElementSelection } from '../modules/element-selector/element-selector';
import { customizeHatColors } from '../modules/document/document';
import { customizeHatColors, removeLoader } from '../modules/document/document';
import { setupUrlTriggers } from '../modules/url-trigger/url-trigger';
import { getLocalStorageConfig } from '../modules/config/config';

Expand Down Expand Up @@ -183,6 +183,7 @@ class StrigoSDK implements IStrigoSDK {
currentUrl: config.initSite.href,
shouldPanelBeOpen: sessionManager.shouldPanelBeOpen(),
isLoading: true,
isRendered: false,
widgetFlavor: config.selectedWidgetFlavor,
});

Expand All @@ -201,6 +202,10 @@ class StrigoSDK implements IStrigoSDK {

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

if (sessionManager.getSessionValue('isRendered')) {
removeLoader();
}
}

collapse(): void {
Expand Down
25 changes: 25 additions & 0 deletions src/styles/strigo-academy-hat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
--customizable-hat-bg-hover-color: #696cbf;
--customizable-hat-text-color: #e2e2e7;
}

.loader {
width: 12px;
height: 12px;
border: 2px solid #fff;
border-bottom-color: transparent;
border-radius: 50%;
display: inline-block;
box-sizing: border-box;
animation: rotation 0.6s linear infinite;
}

@keyframes rotation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

.strigo-academy-hat {
position: fixed;
top: 50%;
Expand Down Expand Up @@ -58,5 +79,9 @@
width: 16px;
padding-top: 1px;
fill: var(--customizable-hat-text-color);

&.loader {
display: none;
}
}
}

0 comments on commit 543022b

Please sign in to comment.