removed parazite
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import { Component, ChangeDetectionStrategy, inject, signal, computed, effect, OnDestroy } from '@angular/core';
|
import { Component, ChangeDetectionStrategy, inject, signal, computed, effect, OnDestroy } from '@angular/core';
|
||||||
import { AuthService } from '../../services/auth.service';
|
import { AuthService } from '../../services/auth.service';
|
||||||
import { CartService } from '../../services/cart.service';
|
|
||||||
import { TranslatePipe } from '../../i18n/translate.pipe';
|
import { TranslatePipe } from '../../i18n/translate.pipe';
|
||||||
import { getDiscountedPrice } from '../../utils/item.utils';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-telegram-login',
|
selector: 'app-telegram-login',
|
||||||
@@ -13,7 +11,6 @@ import { getDiscountedPrice } from '../../utils/item.utils';
|
|||||||
})
|
})
|
||||||
export class TelegramLoginComponent implements OnDestroy {
|
export class TelegramLoginComponent implements OnDestroy {
|
||||||
private authService = inject(AuthService);
|
private authService = inject(AuthService);
|
||||||
private cartService = inject(CartService);
|
|
||||||
|
|
||||||
showDialog = this.authService.showLoginDialog;
|
showDialog = this.authService.showLoginDialog;
|
||||||
status = this.authService.status;
|
status = this.authService.status;
|
||||||
@@ -98,7 +95,7 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
next: (session) => {
|
next: (session) => {
|
||||||
if (session?.active) {
|
if (session?.active) {
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
this.syncCartAndComplete(session.sessionId);
|
this.authService.onTelegramLoginComplete();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
@@ -108,22 +105,6 @@ export class TelegramLoginComponent implements OnDestroy {
|
|||||||
}, this.pollIntervalMs);
|
}, this.pollIntervalMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private syncCartAndComplete(sessionId: string): void {
|
|
||||||
const cartItems = this.cartService.items().map(item => ({
|
|
||||||
itemID: item.itemID,
|
|
||||||
quantity: item.quantity,
|
|
||||||
colour: item.colour || '',
|
|
||||||
size: item.size || '',
|
|
||||||
price: item.discount > 0
|
|
||||||
? item.price * (1 - item.discount / 100)
|
|
||||||
: item.price,
|
|
||||||
}));
|
|
||||||
|
|
||||||
this.authService.syncCart(sessionId, cartItems).subscribe(() => {
|
|
||||||
this.authService.onTelegramLoginComplete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private stopPolling(): void {
|
private stopPolling(): void {
|
||||||
if (this.pollTimer) {
|
if (this.pollTimer) {
|
||||||
clearInterval(this.pollTimer);
|
clearInterval(this.pollTimer);
|
||||||
|
|||||||
@@ -780,8 +780,8 @@ export const mockDataInterceptor: HttpInterceptorFn = (req, next) => {
|
|||||||
return respond([]);
|
return respond([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── POST /websession/:id (add to cart)
|
// ── POST /usersession/:id or /websession/:id (sync cart)
|
||||||
if (url.match(/\/websession\/[^/]+$/) && req.method === 'POST') {
|
if (url.match(/\/(?:user|web)session\/[^/]+$/) && req.method === 'POST') {
|
||||||
return respond({
|
return respond({
|
||||||
sessionId: 'mock-session',
|
sessionId: 'mock-session',
|
||||||
Status: true,
|
Status: true,
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ export class AuthService {
|
|||||||
/** Display name of authenticated user */
|
/** Display name of authenticated user */
|
||||||
readonly displayName = computed(() => this.sessionSignal()?.displayName ?? null);
|
readonly displayName = computed(() => this.sessionSignal()?.displayName ?? null);
|
||||||
|
|
||||||
private readonly apiUrl = environment.apiUrl;
|
|
||||||
private readonly authApiUrl = environment.authApiUrl;
|
private readonly authApiUrl = environment.authApiUrl;
|
||||||
private sessionCheckTimer?: ReturnType<typeof setTimeout>;
|
private sessionCheckTimer?: ReturnType<typeof setTimeout>;
|
||||||
|
|
||||||
@@ -113,14 +112,6 @@ export class AuthService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sync local cart to the backend session after login */
|
|
||||||
syncCart(sessionId: string, items: Array<{ itemID: number; quantity: number; colour?: string; size?: string; price?: number }>): Observable<unknown> {
|
|
||||||
if (!items.length) return of(null);
|
|
||||||
return this.http.post(`${this.apiUrl}/websession/${sessionId}`, items, {
|
|
||||||
withCredentials: true,
|
|
||||||
}).pipe(catchError(() => of(null)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Show login dialog (called when user tries to pay without being logged in) */
|
/** Show login dialog (called when user tries to pay without being logged in) */
|
||||||
requestLogin(): void {
|
requestLogin(): void {
|
||||||
this.showLoginSignal.set(true);
|
this.showLoginSignal.set(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user