Merge branch 'feature/WW-26-architecture'

This commit is contained in:
Fran Jurmanović
2021-06-05 00:00:58 +02:00
8 changed files with 52 additions and 35 deletions

View File

@@ -13,6 +13,11 @@ class AppMainElement extends HTMLElement {
@target appModal: AppModalElement; @target appModal: AppModalElement;
@target mainRoot: AppRootElement; @target mainRoot: AppRootElement;
@closest appMain: AppMainElement; @closest appMain: AppMainElement;
public domEvents: any = {
routechanged: new Event("routechanged"),
tokenchange: new Event("tokenchange"),
walletupdate: new Event("walletupdate"),
};
constructor() { constructor() {
super(); super();
@@ -114,6 +119,10 @@ class AppMainElement extends HTMLElement {
this.appendChild(_appModal); this.appendChild(_appModal);
}; };
public triggerWalletUpdate = () => {
this.dispatchEvent(this.domEvents.walletupdate);
};
private createAppModal = () => { private createAppModal = () => {
const _appModal = document.createElement("app-modal"); const _appModal = document.createElement("app-modal");
_appModal.setAttribute("data-target", "app-main.appModal"); _appModal.setAttribute("data-target", "app-main.appModal");

View File

@@ -23,15 +23,17 @@ class AppMenuElement extends BaseComponentElement {
this.update(); this.update();
} }
this.appMain.addEventListener("tokenchange", this.updateToken); this.appMain.addEventListener("tokenchange", this.updateToken);
this.appMain.addEventListener("walletupdate", this.updateToken);
}; };
elementDisconnected = (appMain: AppMainElement): void => { elementDisconnected = (appMain: AppMainElement): void => {
appMain?.removeEventListener("tokenchange", this.updateToken); appMain?.removeEventListener("tokenchange", this.updateToken);
appMain?.removeEventListener("walletupdate", this.updateToken);
}; };
getWallets = async (): Promise<void> => { getWallets = async (): Promise<void> => {
try { try {
const response = await this.walletService.getAll({ rpp: 2 }); const response = await this.walletService.getAll({ rpp: 3 });
this.setWallets(response.items, response.totalRecords); this.setWallets(response.items, response.totalRecords);
} catch (err) { } catch (err) {
this.update(); this.update();
@@ -96,15 +98,23 @@ class AppMenuElement extends BaseComponentElement {
} }
return html`<menu-item data-path="${path}">${title}</menu-item>`; return html`<menu-item data-path="${path}">${title}</menu-item>`;
}; };
const authMenu = (path: string, title: string): TemplateResult => { const authMenu = (
path: string,
title: string,
action?: string
): TemplateResult => {
if (isAuth) { if (isAuth) {
return regularMenu(path, title); return regularMenu(path, title, action);
} }
return html``; return html``;
}; };
const notAuthMenu = (path: string, title: string): TemplateResult => { const notAuthMenu = (
path: string,
title: string,
action?: string
): TemplateResult => {
if (!isAuth) { if (!isAuth) {
return regularMenu(path, title); return regularMenu(path, title, action);
} }
return html``; return html``;
}; };
@@ -117,12 +127,6 @@ class AppMenuElement extends BaseComponentElement {
} }
return html``; return html``;
}; };
const otherWallets = (action: string) => {
if (isAuth && totalWallets > 2) {
return regularMenu("/wallet/all", "Other Wallets", action);
}
return html``;
};
const menuHeader = (title) => const menuHeader = (title) =>
html`<div class="menu-item menu-header">${title}</div>`; html`<div class="menu-item menu-header">${title}</div>`;
@@ -130,8 +134,12 @@ class AppMenuElement extends BaseComponentElement {
<div data-target="app-menu.sidebar"> <div data-target="app-menu.sidebar">
${menuHeader("Wallets")} ${regularMenu("/", "Home")} ${menuHeader("Wallets")} ${regularMenu("/", "Home")}
${authMenu("/history", "Transaction History")} ${authMenu("/history", "Transaction History")}
${authMenu(
"/wallet/all",
"My Wallets",
"click:app-menu#openModal"
)}
${renderWallets(walletData)} ${renderWallets(walletData)}
${otherWallets("click:app-menu#openModal")}
<span class="menu-item divider"></span> <span class="menu-item divider"></span>
${authMenu("/logout", "Logout")} ${authMenu("/logout", "Logout")}
${notAuthMenu("/login", "Login")} ${notAuthMenu("/login", "Login")}

View File

@@ -44,7 +44,7 @@ class MenuItemElement extends BaseComponentElement {
data-target="menu-item.customButton" data-target="menu-item.customButton"
data-action="${this.customaction}" data-action="${this.customaction}"
> >
Add +
</div>` </div>`
: html``} : html``}
</div> </div>

View File

@@ -1,5 +1,5 @@
{ {
"apiUrl": "localhost:4000", "apiUrl": "main-wallet--dtnyc2vcdgu2re9j-gtw.qovery.io",
"apiVersion": "v1", "apiVersion": "v1",
"ssl": false "ssl": true
} }

View File

@@ -4,9 +4,6 @@ import { AppMainElement } from "components/";
class RouterService { class RouterService {
private historyStack: Array<RouteState> = []; private historyStack: Array<RouteState> = [];
private _routes: Array<RouteState> = []; private _routes: Array<RouteState> = [];
private domEvents: any = {
routechanged: new Event("routechanged"),
};
constructor( constructor(
private appMain: AppMainElement, private appMain: AppMainElement,
private mainRoot: ShadowRoot | HTMLElement private mainRoot: ShadowRoot | HTMLElement
@@ -154,7 +151,7 @@ class RouterService {
this.historyStack.push(newRoute); this.historyStack.push(newRoute);
this.update(); this.update();
} }
this.appMain.dispatchEvent(this.domEvents.routechanged); this.appMain.dispatchEvent(this.appMain?.domEvents.routechanged);
}; };
public goTo = (path: string, data?: any): void => { public goTo = (path: string, data?: any): void => {

View File

@@ -7,9 +7,6 @@ class AuthStore {
private _token: string; private _token: string;
private _userDetails: UserDetails; private _userDetails: UserDetails;
private authService: AuthService; private authService: AuthService;
private domEvents: any = {
tokenchange: new Event("tokenchange"),
};
constructor( constructor(
private appMain: AppMainElement, private appMain: AppMainElement,
private appService: AppService private appService: AppService
@@ -33,7 +30,7 @@ class AuthStore {
if (_changed) { if (_changed) {
this._token = token; this._token = token;
localStorage.setItem("token", token); localStorage.setItem("token", token);
this.appMain.dispatchEvent(this.domEvents.tokenchange); this.appMain.dispatchEvent(this.appMain?.domEvents.tokenchange);
} }
} }

View File

@@ -45,11 +45,10 @@ class WalletCreateElement extends BasePageElement {
const response = await this.walletService.post(this.values); const response = await this.walletService.post(this.values);
if (response?.id) { if (response?.id) {
this.appMain.triggerWalletUpdate();
this.routerService.goTo("/wallet/:walletId", { this.routerService.goTo("/wallet/:walletId", {
walletId: response.id, walletId: response.id,
}); });
const { token } = this.authStore;
this.authStore.token = token;
} }
} catch (err) { } catch (err) {
this.errorMessage = "Unable to create wallet!"; this.errorMessage = "Unable to create wallet!";

View File

@@ -50,22 +50,29 @@ menu-item {
[data-target="menu-item.customButton"] { [data-target="menu-item.customButton"] {
grid-area: custom; grid-area: custom;
display: flex; display: flex;
visibility: hidden; width: 10px;
width: 0px;
display: flex;
transition: width 0.3s;
}
&:hover {
[data-target="menu-item.customButton"] {
grid-area: custom;
visibility: visible;
align-items: center;
justify-content: center;
width: 50px;
height: 50px; height: 50px;
background-color: $blue-09; background-color: $blue-09;
cursor: pointer; cursor: pointer;
user-select: none; user-select: none;
align-items: center;
justify-content: center;
overflow: hidden;
transition: width 0.3s;
color: transparent;
* {
visibility: hidden;
}
}
&:hover {
[data-target="menu-item.customButton"] {
grid-area: custom;
width: 50px;
transition: color 0.3s step-start;
color: $white;
* {
transition: visibility 0.3s;
}
&:hover { &:hover {
background-color: $blue-08; background-color: $blue-08;
} }