first commit
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import { ChangeDetectionStrategy, Component, signal, inject, computed, effect } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ThemeService } from '../../services/theme/theme.service';
|
||||
|
||||
type TabId = 'faq' | 'app';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
templateUrl: './settings.page.html',
|
||||
styleUrl: './settings.page.css',
|
||||
})
|
||||
export class SettingsPage {
|
||||
private readonly themeService = inject(ThemeService);
|
||||
|
||||
readonly tabs: { id: TabId; label: string }[] = [
|
||||
{ id: 'faq', label: 'آپلود FAQ' },
|
||||
{ id: 'app', label: 'تنظیمات برنامه' },
|
||||
];
|
||||
|
||||
readonly activeTab = signal<TabId>('faq');
|
||||
|
||||
readonly uploadedFiles = signal<File[]>([]);
|
||||
readonly isDragging = signal(false);
|
||||
|
||||
readonly language = signal('fa');
|
||||
readonly notificationsEnabled = signal(true);
|
||||
readonly isDarkMode = this.themeService.isDarkMode;
|
||||
readonly isRTL = signal(true);
|
||||
|
||||
selectTab(id: TabId): void {
|
||||
this.activeTab.set(id);
|
||||
}
|
||||
|
||||
onFileSelected(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const files = input.files ? Array.from(input.files) : [];
|
||||
this.uploadedFiles.set(files);
|
||||
}
|
||||
|
||||
onDragOver(event: DragEvent): void {
|
||||
event.preventDefault();
|
||||
this.isDragging.set(true);
|
||||
}
|
||||
|
||||
onDragLeave(): void {
|
||||
this.isDragging.set(false);
|
||||
}
|
||||
|
||||
onDrop(event: DragEvent): void {
|
||||
event.preventDefault();
|
||||
this.isDragging.set(false);
|
||||
const files = event.dataTransfer?.files ? Array.from(event.dataTransfer.files) : [];
|
||||
this.uploadedFiles.set(files);
|
||||
}
|
||||
|
||||
removeFile(index: number): void {
|
||||
this.uploadedFiles.update((files) => files.filter((_, i) => i !== index));
|
||||
}
|
||||
|
||||
clearAllFiles(): void {
|
||||
this.uploadedFiles.set([]);
|
||||
}
|
||||
|
||||
formatFileSize(bytes: number): string {
|
||||
if (bytes === 0) return '0 بایت';
|
||||
const k = 1024;
|
||||
const sizes = ['بایت', 'کیلوبایت', 'مگابایت', 'گیگابایت'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
toggleDarkMode(): void {
|
||||
this.themeService.toggleDarkMode();
|
||||
}
|
||||
|
||||
toggleRTL(): void {
|
||||
this.isRTL.update(val => !val);
|
||||
document.documentElement.dir = this.isRTL() ? 'rtl' : 'ltr';
|
||||
document.body.style.direction = this.isRTL() ? 'rtl' : 'ltr';
|
||||
}
|
||||
|
||||
get fileCount(): number {
|
||||
return this.uploadedFiles().length;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user