добавил кнопку установки pwa
This commit is contained in:
gofnnp 2023-05-20 16:09:36 +04:00
parent 24edd456db
commit 877cf018af
6 changed files with 19 additions and 18 deletions

View File

@ -1,7 +1,5 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component'; import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
@ -33,7 +31,6 @@ import { ShareButtonsModule } from 'ngx-sharebuttons/buttons';
import { ShareIconsModule } from 'ngx-sharebuttons/icons'; import { ShareIconsModule } from 'ngx-sharebuttons/icons';
import { MessagingService } from './services/messaging.service'; import { MessagingService } from './services/messaging.service';
import { NotFoundComponent } from './pages/not-found/not-found.component'; import { NotFoundComponent } from './pages/not-found/not-found.component';
import { DownloadAppDirective } from './directives/download-app.directive';
import { MatIconModule } from '@angular/material/icon'; import { MatIconModule } from '@angular/material/icon';
import { GuestCardComponent } from './pages/guest-card/guest-card.component'; import { GuestCardComponent } from './pages/guest-card/guest-card.component';
import { QrCodeModule } from 'ng-qrcode'; import { QrCodeModule } from 'ng-qrcode';
@ -46,7 +43,6 @@ import { LoginComponent } from './pages/login/login.component';
import { NgxMatIntlTelInputComponent } from 'ngx-mat-intl-tel-input'; import { NgxMatIntlTelInputComponent } from 'ngx-mat-intl-tel-input';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { FocusNextInputDirective } from './directives/focus-next-input.directive';
import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MatSnackBarModule } from '@angular/material/snack-bar';
import { import {
MAT_BOTTOM_SHEET_DATA, MAT_BOTTOM_SHEET_DATA,
@ -72,7 +68,6 @@ import { DirectivesModule } from './directives/directives.module';
UserDataComponent, UserDataComponent,
RefSystemComponent, RefSystemComponent,
NotFoundComponent, NotFoundComponent,
DownloadAppDirective,
GuestCardComponent, GuestCardComponent,
AccordionComponent, AccordionComponent,
LastOrderComponent, LastOrderComponent,

View File

@ -1,12 +1,13 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { FocusNextInputDirective } from './focus-next-input.directive'; import { FocusNextInputDirective } from './focus-next-input.directive';
import { DownloadAppDirective } from './download-app.directive';
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule CommonModule
], ],
declarations: [FocusNextInputDirective], declarations: [FocusNextInputDirective, DownloadAppDirective],
exports: [FocusNextInputDirective] exports: [FocusNextInputDirective, DownloadAppDirective]
}) })
export class DirectivesModule { } export class DirectivesModule { }

View File

@ -5,6 +5,7 @@ import {
OnInit, OnInit,
Renderer2, Renderer2,
} from '@angular/core'; } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { MessageService } from 'primeng/api'; import { MessageService } from 'primeng/api';
@Directive({ @Directive({
@ -17,7 +18,8 @@ export class DownloadAppDirective implements OnInit {
constructor( constructor(
private messageService: MessageService, private messageService: MessageService,
public renderer: Renderer2, public renderer: Renderer2,
private el: ElementRef private el: ElementRef,
private _snackBar: MatSnackBar,
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
@ -57,10 +59,8 @@ export class DownloadAppDirective implements OnInit {
event.preventDefault(); event.preventDefault();
} }
if (this.deviceType === 'ios') { if (this.deviceType === 'ios') {
this.messageService.add({ this._snackBar.open(`Для установки нажмите на кнопку поделиться в Вашем браузере и выберите пункт 'На экран «Домой»'`, '', {
severity: 'custom', duration: 5000,
summary: `Для установки нажмите на кнопку поделиться в Вашем браузере и выберите пункт 'На экран «Домой»'`,
life: 5000,
}); });
return; return;
} }
@ -69,14 +69,16 @@ export class DownloadAppDirective implements OnInit {
severity: 'error', severity: 'error',
summary: 'Не поддерживается в Вашем браузере!', summary: 'Не поддерживается в Вашем браузере!',
}); });
this._snackBar.open('Не поддерживается в Вашем браузере!', '', {
duration: 3000,
});
return; return;
} }
this.deferredPrompt.prompt(); this.deferredPrompt.prompt();
this.deferredPrompt.userChoice.then((res: any) => { this.deferredPrompt.userChoice.then((res: any) => {
if (res.outcome === 'accepted') { if (res.outcome === 'accepted') {
this.messageService.add({ this._snackBar.open('Спасибо за установку!', '', {
severity: 'custom', duration: 3000,
summary: 'Спасибо за установку!',
}); });
} }
this.deferredPrompt = null; this.deferredPrompt = null;

View File

@ -1,5 +1,6 @@
<div class="container"> <div class="container">
<mat-icon style="cursor: pointer;" aria-hidden="false" aria-label="Назад" fontIcon="arrow_back_ios" class="back-arrow" (click)="back()"></mat-icon> <mat-icon style="cursor: pointer;" aria-hidden="false" aria-label="Назад" fontIcon="arrow_back_ios" class="back-arrow" (click)="back()"></mat-icon>
<h1 class="title">{{title}}</h1> <h1 class="title">{{title}}</h1>
<div class="plug"></div> <!-- <div class="plug"></div> -->
<button mat-stroked-button appDownloadApp>Установить</button>
</div> </div>

View File

@ -19,6 +19,7 @@ import { NgxMatIntlTelInputComponent } from 'ngx-mat-intl-tel-input';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { DirectivesModule } from 'src/app/directives/directives.module'; import { DirectivesModule } from 'src/app/directives/directives.module';
import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component'; import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component';
import {MatButtonModule} from '@angular/material/button';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -44,7 +45,8 @@ import { LoyalityProgramComponent } from './pages/loyality-program/loyality-prog
NgxMatIntlTelInputComponent, NgxMatIntlTelInputComponent,
ReactiveFormsModule, ReactiveFormsModule,
MatInputModule, MatInputModule,
DirectivesModule DirectivesModule,
MatButtonModule
], ],
bootstrap: [IndexComponent], bootstrap: [IndexComponent],
}) })

View File

@ -45,7 +45,7 @@ export class WpJsonService {
getCustomerInfo(systemId: string, token: string, url: string): Observable<any> { getCustomerInfo(systemId: string, token: string, url: string): Observable<any> {
return this._request(`customer_info/${systemId}/${token}/`, 'GET', null, false, url).pipe( return this._request(`customer_info/${systemId}/${token}/`, 'GET', null, false, url).pipe(
switchMap((response) => { switchMap((response) => {
if (response.customer_info.errorCode !== 'Customer_CustomerNotFound') { if (response?.customer_info?.errorCode !== 'Customer_CustomerNotFound') {
return of(response) return of(response)
} else { } else {
return this.newCustomer(systemId, token, url).pipe( return this.newCustomer(systemId, token, url).pipe(