Merge branch 'feature/WW-26-architecture'

This commit is contained in:
Fran Jurmanović
2021-06-06 12:51:10 +02:00
14 changed files with 78 additions and 20 deletions

View File

@@ -1,5 +1,45 @@
import { attr } from "@github/catalyst";
import { html, render } from "@github/jtml";
import { BaseElement } from "common/"; import { BaseElement } from "common/";
import { isTrue } from "core/utils";
class BasePageElement extends BaseElement {} class BasePageElement extends BaseElement {
public pageTitle: string = "";
@attr hidetitle: string;
@attr customtitle: string;
constructor(options: OptionType) {
super();
if (options?.title) {
this.pageTitle = options?.title;
}
this.connectedCallback = this.connectedCallback.bind(this);
this.disconnectedCallback = this.disconnectedCallback.bind(this);
}
public renderTitle = () => {
if (!isTrue(this.hidetitle)) {
return html`<div class="page --title">
${this.customtitle ? this.customtitle : this.pageTitle}
</div>`;
}
return html``;
};
update = (): void => {
const _render = () => html` ${this.renderTitle()} ${this.render()} `;
render(_render(), this);
this.bindEvents();
this.updateCallback();
};
connectedCallback() {
this.appMain.setTitle(this.pageTitle);
super.connectedCallback();
}
}
export default BasePageElement; export default BasePageElement;
export type OptionType = {
title?: string;
};

View File

@@ -23,12 +23,6 @@ class AppFormElement extends BaseComponentElement {
this.update(); this.update();
}; };
public keyUp = (e) => {
if (e.keyCode === 13) {
this.onSubmit(e);
}
};
public onSubmit = (e) => { public onSubmit = (e) => {
e.preventDefault(); e.preventDefault();
if (!this.valid) { if (!this.valid) {

View File

@@ -44,7 +44,10 @@ class AppLinkElement extends BaseComponentElement {
}; };
get disabled(): boolean { get disabled(): boolean {
return isTrue(this.goBack) && this.routerService.emptyState; if (isTrue(this.goBack)) {
return this.routerService.emptyState;
}
return false;
} }
render = (): TemplateResult => { render = (): TemplateResult => {
@@ -56,7 +59,7 @@ class AppLinkElement extends BaseComponentElement {
>${this.title}</a >${this.title}</a
>` >`
: html`<a : html`<a
class="btn btn-link btn-disabled" class="btn btn-link"
data-target="app-link.main" data-target="app-link.main"
data-action="click:app-link#goTo" data-action="click:app-link#goTo"
href="${this.to}" href="${this.to}"

View File

@@ -126,6 +126,11 @@ class AppMainElement extends HTMLElement {
this.dispatchEvent(this.domEvents.walletupdate); this.dispatchEvent(this.domEvents.walletupdate);
}; };
public setTitle = (title: string): void => {
if (!title) title = __CONFIG__.appName;
window.document.title = title;
};
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

@@ -120,7 +120,7 @@ class AppPaginationElement extends BaseComponentElement {
return html` return html`
<div> <div>
<button <button
class="btn btn-blue btn-squared ${page <= 1 class="btn btn-primary btn-squared ${page <= 1
? "disabled" ? "disabled"
: ""}" : ""}"
data-action="click:app-pagination#pageBack" data-action="click:app-pagination#pageBack"
@@ -128,7 +128,8 @@ class AppPaginationElement extends BaseComponentElement {
Prev Prev
</button> </button>
<button <button
class="btn btn-blue btn-squared ${page >= pageRange class="btn btn-primary btn-squared ${page >=
pageRange
? "disabled" ? "disabled"
: ""}" : ""}"
data-action="click:app-pagination#pageNext" data-action="click:app-pagination#pageNext"

View File

@@ -105,7 +105,6 @@ class InputFieldElement extends BaseComponentElement {
data-target="input-field.inp" data-target="input-field.inp"
data-action=" data-action="
input:input-field#inputChange input:input-field#inputChange
keyup:app-form#keyUp
blur:input-field#validateDisplay blur:input-field#validateDisplay
" "
/>`; />`;

View File

@@ -9,7 +9,9 @@ class HistoryPageElement extends BasePageElement {
private transactionsService: TransactionsService; private transactionsService: TransactionsService;
@target pagination: AppPaginationElement; @target pagination: AppPaginationElement;
constructor() { constructor() {
super(); super({
title: "Transaction History",
});
} }
elementConnected = (): void => { elementConnected = (): void => {

View File

@@ -8,7 +8,9 @@ import { BasePageElement } from "common/";
class HomePageElement extends BasePageElement { class HomePageElement extends BasePageElement {
private pingService: PingService; private pingService: PingService;
constructor() { constructor() {
super(); super({
title: "Home",
});
} }
elementConnected = (): void => { elementConnected = (): void => {

View File

@@ -11,7 +11,9 @@ class LoginPageElement extends BasePageElement {
@target appForm: AppFormElement; @target appForm: AppFormElement;
authService: AuthService; authService: AuthService;
constructor() { constructor() {
super(); super({
title: "Login",
});
} }
elementConnected = (): void => { elementConnected = (): void => {
this.authService = new AuthService(this.appMain.appService); this.authService = new AuthService(this.appMain.appService);

View File

@@ -6,7 +6,9 @@ import { BasePageElement } from "common/";
class LogoutPageElement extends BasePageElement { class LogoutPageElement extends BasePageElement {
authService: AuthService; authService: AuthService;
constructor() { constructor() {
super(); super({
title: "Logout",
});
} }
elementConnected = (): void => { elementConnected = (): void => {
this.authService = new AuthService(this.appMain.appService); this.authService = new AuthService(this.appMain.appService);

View File

@@ -5,7 +5,9 @@ import { BasePageElement } from "common/";
@controller @controller
class NotFoundElement extends BasePageElement { class NotFoundElement extends BasePageElement {
constructor() { constructor() {
super(); super({
title: "404 - Not Found",
});
} }
elementConnected = (): void => { elementConnected = (): void => {
this.update(); this.update();

View File

@@ -9,7 +9,9 @@ class RegisterPageElement extends BasePageElement {
@targets inputs: Array<InputFieldElement>; @targets inputs: Array<InputFieldElement>;
authService: AuthService; authService: AuthService;
constructor() { constructor() {
super(); super({
title: "Register",
});
} }
elementConnected = (): void => { elementConnected = (): void => {
this.authService = new AuthService(this.appMain.appService); this.authService = new AuthService(this.appMain.appService);

View File

@@ -12,7 +12,9 @@ class WalletCreateElement extends BasePageElement {
authService: AuthService; authService: AuthService;
errorMessage: string; errorMessage: string;
constructor() { constructor() {
super(); super({
title: "New Wallet",
});
} }
elementConnected = (): void => { elementConnected = (): void => {
this.walletService = new WalletService(this.appMain?.appService); this.walletService = new WalletService(this.appMain?.appService);

View File

@@ -12,7 +12,9 @@ class WalletListElement extends BasePageElement {
authService: AuthService; authService: AuthService;
errorMessage: string; errorMessage: string;
constructor() { constructor() {
super(); super({
title: "Wallet List",
});
} }
elementConnected = (): void => { elementConnected = (): void => {
this.walletService = new WalletService(this.appMain?.appService); this.walletService = new WalletService(this.appMain?.appService);