добавил кнопку установки 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 { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@ -33,7 +31,6 @@ import { ShareButtonsModule } from 'ngx-sharebuttons/buttons';
import { ShareIconsModule } from 'ngx-sharebuttons/icons';
import { MessagingService } from './services/messaging.service';
import { NotFoundComponent } from './pages/not-found/not-found.component';
import { DownloadAppDirective } from './directives/download-app.directive';
import { MatIconModule } from '@angular/material/icon';
import { GuestCardComponent } from './pages/guest-card/guest-card.component';
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 { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { FocusNextInputDirective } from './directives/focus-next-input.directive';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import {
MAT_BOTTOM_SHEET_DATA,
@ -72,7 +68,6 @@ import { DirectivesModule } from './directives/directives.module';
UserDataComponent,
RefSystemComponent,
NotFoundComponent,
DownloadAppDirective,
GuestCardComponent,
AccordionComponent,
LastOrderComponent,

View File

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

View File

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

View File

@ -1,5 +1,6 @@
<div class="container">
<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>
<div class="plug"></div>
<!-- <div class="plug"></div> -->
<button mat-stroked-button appDownloadApp>Установить</button>
</div>

View File

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

View File

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