feat: started working on PWA app

This commit is contained in:
2024-07-05 00:07:56 +03:00
35 changed files with 458 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}

View File

@@ -0,0 +1,29 @@
{
"$schema": "../../node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.webmanifest",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/**/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
]
}
}
]
}

View File

@@ -0,0 +1,75 @@
{
"name": "NwaifuAnime",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"prefix": "app",
"sourceRoot": "apps/NwaifuAnime/src",
"tags": [],
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/NwaifuAnime",
"index": "apps/NwaifuAnime/src/index.html",
"browser": "apps/NwaifuAnime/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/NwaifuAnime/tsconfig.app.json",
"inlineStyleLanguage": "less",
"assets": [
{
"glob": "**/*",
"input": "apps/NwaifuAnime/public"
}
],
"styles": ["apps/NwaifuAnime/src/styles.less"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all",
"serviceWorker": "apps/NwaifuAnime/ngsw-config.json"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "NwaifuAnime:build:production"
},
"development": {
"buildTarget": "NwaifuAnime:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "NwaifuAnime:build"
}
},
"lint": {
"executor": "@nx/eslint:lint"
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,59 @@
{
"name": "NwaifuAnime",
"short_name": "NwaifuAnime",
"theme_color": "#1976d2",
"background_color": "#fafafa",
"display": "standalone",
"scope": "./",
"start_url": "./",
"icons": [
{
"src": "icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable any"
}
]
}

View File

@@ -0,0 +1,11 @@
@if (serviceWorkerEnabled) {
@if (hasUpdate) {
<h1>Update available</h1>
<button (click)="update()">Update</button>
} @else {
<h1>Update not available</h1>
}
}
<app-header (searchEvent)="onSearch($event)"></app-header>
<div class="h-10"></div>
<router-outlet></router-outlet>

View File

@@ -0,0 +1,33 @@
import { Component } from "@angular/core";
import { RouterModule } from "@angular/router";
import { AppService } from "./app.service";
import { HeaderComponent } from "./components/header/header.component";
@Component({
standalone: true,
imports: [RouterModule, HeaderComponent],
selector: "app-root",
templateUrl: "./app.component.html",
styleUrl: "./app.component.less",
providers: [AppService],
})
export class AppComponent {
title = "NwaifuAnime";
constructor(private sw: AppService) {}
get hasUpdate() {
return this.sw.isUpdateAvailable;
}
update() {
this.sw.update();
}
get serviceWorkerEnabled() {
return this.sw.serviceWorkerEnabled;
}
onSearch(text: string) {
console.log(text);
}
}

View File

@@ -0,0 +1,11 @@
import { ApplicationConfig, provideZoneChangeDetection, isDevMode } from "@angular/core";
import { provideRouter } from "@angular/router";
import { appRoutes } from "./app.routes";
import { provideServiceWorker } from '@angular/service-worker';
export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(appRoutes), provideServiceWorker('ngsw-worker.js', {
enabled: !isDevMode(),
registrationStrategy: 'registerWhenStable:30000'
})],
};

View File

@@ -0,0 +1,9 @@
import { Route } from "@angular/router";
import { HomeComponent } from "./components/home/home.component";
export const appRoutes: Route[] = [
{
path: "",
component: HomeComponent,
},
];

View File

@@ -0,0 +1,40 @@
import { Injectable } from "@angular/core";
import { SwUpdate } from "@angular/service-worker";
@Injectable({ providedIn: "root" })
export class AppService {
private hasUpdate = false;
constructor(private sw: SwUpdate) {
if (this.sw.isEnabled) {
console.log("service init");
this.sw.checkForUpdate();
this.sw.versionUpdates.subscribe((ev) => {
if (ev.type == "VERSION_DETECTED") {
console.log("update detected");
this.hasUpdate = true;
} else {
console.log("no update");
}
});
}
}
get isUpdateAvailable() {
return this.hasUpdate;
}
get serviceWorkerEnabled() {
return this.sw.isEnabled;
}
update() {
this.sw.activateUpdate().then((res) => {
if (res) {
console.log("updated");
this.hasUpdate = false;
window.location.reload();
}
});
}
}

View File

@@ -0,0 +1,23 @@
<div
class="header fixed flex justify-between w-full p-2 bg-gray-700 md:h-8 h-auto items-center md:flex-row flex-col md:gap-0 gap-3"
>
<div class="flex justify-between flex-row w-full align-middle">
<h1 class="text-white">NwaifuAnime</h1>
<!-- Search bar on small screens -->
<button type="button" class="md:hidden" (click)="changeMenu()">
<i [class]="menuBtnClass"></i>
</button>
</div>
<!-- Search bar on big screens -->
<div [class]="searchBarClass">
<input
type="search"
#searchInput
class="outline-none ps-1 text-sm leading-6 w-full border-0 bg-transparent border-r border-gray-700"
/>
<button class="align-middle w-[100px] text-center" type="submit" (click)="search()">
<span class="text-sm text-black h-full">Поиск</span>
</button>
</div>
</div>

View File

@@ -0,0 +1,3 @@
.header {
transition: height 0.3s;
}

View File

@@ -0,0 +1,33 @@
import { CommonModule } from "@angular/common";
import { Component, ElementRef, EventEmitter, Output, ViewChild } from "@angular/core";
@Component({
selector: "app-header",
templateUrl: "./header.component.html",
styleUrls: ["./header.component.less"],
standalone: true,
imports: [CommonModule],
})
export class HeaderComponent {
@Output() searchEvent: EventEmitter<string> = new EventEmitter();
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
menuOpened = false;
changeMenu() {
this.menuOpened = !this.menuOpened;
}
get menuBtnClass(): string {
return `lni ${this.menuOpened ? "lni-close" : "lni-menu"} text-white`;
}
get searchBarClass(): string {
return `search-bar bg-slate-300 md:w-[50%] w-full md:m-0 ms-2 me-2 max-h-6 md:flex justify-start flex-row items-center rounded-md ${this.menuOpened ? "flex" : "hidden"}`;
}
search() {
if (this.searchInput) {
const text = this.searchInput.nativeElement.value;
this.searchEvent.emit(text);
}
}
}

View File

@@ -0,0 +1 @@
<h1>It's home component</h1>

View File

@@ -0,0 +1,11 @@
import { CommonModule } from "@angular/common";
import { Component } from "@angular/core";
@Component({
standalone: true,
selector: "app-home",
templateUrl: "./home.component.html",
styleUrls: ["./home.component.less"],
imports: [CommonModule],
})
export class HomeComponent {}

View File

@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>NwaifuAnime</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<link href="https://cdn.lineicons.com/4.0/lineicons.css" rel="stylesheet" />
<link rel="manifest" href="manifest.webmanifest" />
<meta name="theme-color" content="#1976d2" />
</head>
<body>
<app-root></app-root>
<noscript>Please enable JavaScript to continue using this application.</noscript>
</body>
</html>

View File

@@ -0,0 +1,5 @@
import { bootstrapApplication } from "@angular/platform-browser";
import { appConfig } from "./app/app.config";
import { AppComponent } from "./app/app.component";
bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));

View File

@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View File

@@ -0,0 +1,14 @@
const { createGlobPatternsForDependencies } = require("@nx/angular/tailwind");
const { join } = require("path");
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
join(__dirname, "src/**/!(*.stories|*.spec).{ts,html}"),
...createGlobPatternsForDependencies(__dirname),
],
theme: {
extend: {},
},
plugins: [],
};

View File

@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": []
},
"files": ["src/main.ts"],
"include": ["src/**/*.d.ts"],
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
}

View File

@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"compilerOptions": {},
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
}

View File

@@ -0,0 +1,30 @@
{
"compilerOptions": {
"target": "es2022",
"useDefineForClassFields": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.editor.json"
},
{
"path": "./tsconfig.app.json"
}
],
"extends": "../../tsconfig.base.json",
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}

BIN
bun.lockb

Binary file not shown.

View File

@@ -19,6 +19,7 @@
"@angular/platform-browser": "18.0.3", "@angular/platform-browser": "18.0.3",
"@angular/platform-browser-dynamic": "18.0.3", "@angular/platform-browser-dynamic": "18.0.3",
"@angular/router": "18.0.3", "@angular/router": "18.0.3",
"@angular/service-worker": "18.0.3",
"@fortawesome/angular-fontawesome": "0.14.1", "@fortawesome/angular-fontawesome": "0.14.1",
"@fortawesome/fontawesome-svg-core": "^6.4.2", "@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-brands-svg-icons": "^6.4.2", "@fortawesome/free-brands-svg-icons": "^6.4.2",

View File

@@ -13,9 +13,7 @@
"skipLibCheck": true, "skipLibCheck": true,
"skipDefaultLibCheck": true, "skipDefaultLibCheck": true,
"paths": { "paths": {
"@nwaifu-ui": [ "@nwaifu-ui": ["nwaifu-ui/src/index.ts"]
"nwaifu-ui/src/index.ts"
]
}, },
"baseUrl": ".", "baseUrl": ".",
"rootDir": "." "rootDir": "."