Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add settings screen #1

Merged
merged 6 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {}
"rules": {
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/ban-types": "off",
"no-inner-declarations": "off"
}
},
{
"files": ["*.js", "*.jsx"],
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"trailingComma": "all"
}
42 changes: 24 additions & 18 deletions apps/game-companion/src/app/app.element.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
mixinRootElement,
GenericScorePlayerStats,
getRoutes,
IncrementalScorePlayerStats,
NamedScorePlayerStats,
NavigatableRouter,
} from '@game-companion/core';
import '@game-companion/core/provider';
import '@game-companion/core/update-notification';
import { customElement, html, state } from '@game-companion/lit';
import { customElement, html, LitElement, state } from '@game-companion/lit';
import { registerSW } from 'virtual:pwa-register';

declare global {
Expand All @@ -15,40 +17,44 @@ declare global {
}

@customElement(GameAppElement.selector)
export class GameAppElement extends mixinRootElement({
selector: 'game-companion-root',
playerStats: [
new GenericScorePlayerStats(),
new IncrementalScorePlayerStats(),
new NamedScorePlayerStats(),
],
}) {
export class GameAppElement extends LitElement {
static readonly selector = 'game-companion-root';

@state() private declare needRefresh: boolean;
@state() private declare offlineReady: boolean;

private updateSw: () => Promise<void>;
#router = new NavigatableRouter(this, getRoutes());
#playerStats = [
new GenericScorePlayerStats(),
new IncrementalScorePlayerStats(),
new NamedScorePlayerStats(),
];
#updateSw: () => Promise<void>;

constructor() {
super();

this.needRefresh = false;
this.offlineReady = false;

this.updateSw = registerSW({
this.#updateSw = registerSW({
immediate: true,
onNeedRefresh: () => (this.needRefresh = true),
onOfflineReady: () => (this.offlineReady = true),
});
}

protected override render() {
return html`${super.render()}
<gc-update-notification
.needRefresh=${this.needRefresh}
.offlineReady=${this.offlineReady}
@gcUpdateNotificationRefresh=${this.updateSw}
></gc-update-notification>`;
return html`
<gc-provider .router=${this.#router} .playerStats=${this.#playerStats}>
${this.#router.outlet()}

<gc-update-notification
.needRefresh=${this.needRefresh}
.offlineReady=${this.offlineReady}
@gcUpdateNotificationRefresh=${this.#updateSw}
></gc-update-notification>
</gc-provider>
`;
}
}
33 changes: 19 additions & 14 deletions apps/tfm-companion/src/app/app.element.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mixinRootElement } from '@game-companion/core';
import { getRoutes, NavigatableRouter } from '@game-companion/core';
import '@game-companion/core/provider';
import '@game-companion/core/update-notification';
import { customElement, html, state } from '@game-companion/lit';
import { customElement, html, LitElement, state } from '@game-companion/lit';
import { tfmPlayerStats } from '@game-companion/tfm';
import { registerSW } from 'virtual:pwa-register';

Expand All @@ -11,36 +12,40 @@ declare global {
}

@customElement(TfmAppElement.selector)
export class TfmAppElement extends mixinRootElement({
selector: 'tfm-companion-root',
playerStats: [...tfmPlayerStats],
}) {
export class TfmAppElement extends LitElement {
static readonly selector = 'tfm-companion-root';

@state() private declare needRefresh: boolean;
@state() private declare offlineReady: boolean;

private updateSw: () => Promise<void>;
#router = new NavigatableRouter(this, getRoutes());
#playerStats = [...tfmPlayerStats];
#updateSw: () => Promise<void>;

constructor() {
super();

this.needRefresh = false;
this.offlineReady = false;

this.updateSw = registerSW({
this.#updateSw = registerSW({
immediate: true,
onNeedRefresh: () => (this.needRefresh = true),
onOfflineReady: () => (this.offlineReady = true),
});
}

protected override render() {
return html`${super.render()}
<gc-update-notification
.needRefresh=${this.needRefresh}
.offlineReady=${this.offlineReady}
@gcUpdateNotificationRefresh=${this.updateSw}
></gc-update-notification>`;
return html`
<gc-provider .router=${this.#router} .playerStats=${this.#playerStats}>
${this.#router.outlet()}

<gc-update-notification
.needRefresh=${this.needRefresh}
.offlineReady=${this.offlineReady}
@gcUpdateNotificationRefresh=${this.#updateSw}
></gc-update-notification>
</gc-provider>
`;
}
}
10 changes: 10 additions & 0 deletions libs/context/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nrwl/web/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions libs/context/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# context

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build context` to build the library.

## Running unit tests

Run `nx test context` to execute the unit tests via [Jest](https://jestjs.io).
9 changes: 9 additions & 0 deletions libs/context/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@game-companion/context",
"version": "0.0.1",
"description": "Context API for Web Components",
"type": "module",
"main": "index.cjs",
"module": "index.js",
"types": "index.d.ts"
}
43 changes: 43 additions & 0 deletions libs/context/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "context",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/context/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/context"
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"command": "node tools/scripts/publish.mjs context {args.ver} {args.tag}"
},
"dependsOn": ["build"]
},
"test": {
"executor": "@nrwl/vite:test",
"outputs": ["coverage/libs/context"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/libs/context"
},
"configurations": {
"watch": {
"watch": true
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/context/**/*.ts"]
}
}
},
"tags": []
}