2026-05-08 18:08:57 +03:30
|
|
|
import { CommonModule } from '@angular/common';
|
2026-05-11 15:59:57 +03:30
|
|
|
import { Component, computed, inject, signal } from '@angular/core';
|
|
|
|
|
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
|
|
|
|
|
import { filter } from 'rxjs';
|
2026-05-11 13:36:06 +03:30
|
|
|
import { PosSplashComponent } from '../components/splash.component';
|
|
|
|
|
import { PosPagesLayoutComponent } from './pagesLayout/layout.component';
|
2026-03-18 13:35:57 +03:30
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'pos-layout',
|
2026-05-11 13:36:06 +03:30
|
|
|
templateUrl: 'layout.component.html',
|
|
|
|
|
imports: [PosSplashComponent, PosPagesLayoutComponent, RouterOutlet, CommonModule],
|
2026-03-18 13:35:57 +03:30
|
|
|
})
|
2026-05-11 13:36:06 +03:30
|
|
|
export class PosLayoutComponent {
|
2026-05-11 15:59:57 +03:30
|
|
|
private readonly router = inject(Router);
|
|
|
|
|
|
2026-05-11 13:36:06 +03:30
|
|
|
showSplash = signal(true);
|
2026-05-11 15:59:57 +03:30
|
|
|
private readonly currentUrl = signal(this.router.url);
|
|
|
|
|
isAuth = computed(() => this.currentUrl() === '/auth');
|
2026-05-06 22:01:20 +03:30
|
|
|
|
2026-05-08 18:08:57 +03:30
|
|
|
private touchStartY = 0;
|
|
|
|
|
private pulling = false;
|
|
|
|
|
pullDistance = signal(0);
|
|
|
|
|
readonly pullThreshold = 80;
|
2026-03-18 13:35:57 +03:30
|
|
|
|
2026-05-11 15:59:57 +03:30
|
|
|
constructor() {
|
|
|
|
|
this.router.events
|
|
|
|
|
.pipe(filter((event) => event instanceof NavigationEnd))
|
|
|
|
|
.subscribe(() => this.currentUrl.set(this.router.url));
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 13:36:06 +03:30
|
|
|
onSplashCompleted() {
|
|
|
|
|
this.showSplash.set(false);
|
2026-04-30 16:27:42 +03:30
|
|
|
}
|
2026-05-06 22:01:20 +03:30
|
|
|
|
2026-05-08 18:08:57 +03:30
|
|
|
onTouchStart(event: TouchEvent) {
|
|
|
|
|
if (window.scrollY > 0 || event.touches.length !== 1) return;
|
|
|
|
|
this.touchStartY = event.touches[0].clientY;
|
|
|
|
|
this.pulling = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onTouchMove(event: TouchEvent) {
|
|
|
|
|
if (!this.pulling) return;
|
|
|
|
|
const delta = event.touches[0].clientY - this.touchStartY;
|
|
|
|
|
if (delta <= 0) {
|
|
|
|
|
this.pullDistance.set(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const damped = Math.min(delta * 0.5, 140);
|
|
|
|
|
this.pullDistance.set(damped);
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onTouchEnd() {
|
|
|
|
|
if (!this.pulling) return;
|
|
|
|
|
const shouldRefresh = this.pullDistance() >= this.pullThreshold;
|
|
|
|
|
this.pulling = false;
|
|
|
|
|
this.pullDistance.set(0);
|
|
|
|
|
if (shouldRefresh) {
|
2026-05-11 13:36:06 +03:30
|
|
|
this.showSplash.set(true);
|
2026-05-08 18:08:57 +03:30
|
|
|
}
|
2026-05-06 22:01:20 +03:30
|
|
|
}
|
2026-03-18 13:35:57 +03:30
|
|
|
}
|