diff --git a/angular.json b/angular.json index bddd0e9..ea2779d 100644 --- a/angular.json +++ b/angular.json @@ -35,13 +35,13 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kB", - "maximumError": "1MB" + "maximumWarning": "1.5MB", + "maximumError": "2MB" }, { "type": "anyComponentStyle", - "maximumWarning": "4kB", - "maximumError": "8kB" + "maximumWarning": "8kB", + "maximumError": "12kB" } ], "outputHashing": "all" diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 7b68c92..4cfa961 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,8 +1,13 @@ import { Routes } from '@angular/router'; +import { HomePage } from './pages/home/home.page'; import { SettingsPage } from './pages/settings/settings.page'; export const routes: Routes = [ - { path: '', pathMatch: 'full', redirectTo: '' }, + { + path: '', + title: 'دستیار هوشمند', + component: HomePage, + }, { path: 'settings', title: 'تنظیمات', diff --git a/src/app/pages/home/home.page.css b/src/app/pages/home/home.page.css new file mode 100644 index 0000000..263d522 --- /dev/null +++ b/src/app/pages/home/home.page.css @@ -0,0 +1,92 @@ +.home-page { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + min-height: 100%; + padding: 2rem 1rem; +} + +.home-content { + width: 100%; + max-width: 800px; + margin: 0 auto; +} + +.home-header { + text-align: center; + margin-bottom: 2rem; +} + +.home-icon-wrapper { + display: inline-flex; + align-items: center; + justify-content: center; + width: 140px; + height: 140px; + border-radius: 50%; + background: transparent; + margin-bottom: 1.5rem; + padding: 0.75rem; +} + +.home-logo { + width: 100%; + height: 100%; + object-fit: contain; + display: block; +} + +.home-title { + font-size: 1.75rem; + font-weight: 600; + color: var(--text-primary); + margin: 0 0 0.5rem; + line-height: 1.3; +} + +.home-subtitle { + font-size: 0.9375rem; + color: var(--text-muted); + margin: 0; + line-height: 1.5; +} + +@media (max-width: 640px) { + .home-page { + padding: 1.25rem 0.75rem; + } + + .home-header { + margin-bottom: 1.25rem; + } + + .home-icon-wrapper { + width: 100px; + height: 100px; + margin-bottom: 1.25rem; + padding: 0.5rem; + } + + .home-logo { + width: 100%; + height: 100%; + } + + .home-title { + font-size: 1.375rem; + } + + .home-subtitle { + font-size: 0.875rem; + } +} + +@media (prefers-reduced-motion: reduce) { + .home-page, + .home-header, + .home-icon-wrapper { + transition: none !important; + animation: none !important; + } +} diff --git a/src/app/pages/home/home.page.html b/src/app/pages/home/home.page.html new file mode 100644 index 0000000..7034df8 --- /dev/null +++ b/src/app/pages/home/home.page.html @@ -0,0 +1,22 @@ +
+
+
+
+ +
+

دستیار هوشمند

+

سوال خود را بپرسید، من اینجا هستم

+
+ + +
+
diff --git a/src/app/pages/home/home.page.ts b/src/app/pages/home/home.page.ts new file mode 100644 index 0000000..d9eade3 --- /dev/null +++ b/src/app/pages/home/home.page.ts @@ -0,0 +1,32 @@ +import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { AiChatInputComponent } from '../../shared/ui/ai-chat-input/ai-chat-input.component'; +import { ThemeService } from '../../services/theme/theme.service'; + +@Component({ + selector: 'app-home', + standalone: true, + imports: [CommonModule, AiChatInputComponent], + changeDetection: ChangeDetectionStrategy.OnPush, + templateUrl: './home.page.html', + styleUrl: './home.page.css', +}) +export class HomePage { + private readonly themeService = inject(ThemeService); + + readonly isDarkMode = this.themeService.isDarkMode; + + readonly logoSrc = () => this.isDarkMode() ? 'assets/images/RaymandLogo.png' : 'assets/images/login.png'; + + onMessageSent(message: string): void { + console.log('Message sent:', message); + } + + onFileSelected(file: File): void { + console.log('File selected:', file.name); + } + + onVoiceToggled(active: boolean): void { + console.log('Voice mode:', active ? 'active' : 'inactive'); + } +} diff --git a/src/app/pages/settings/settings.page.css b/src/app/pages/settings/settings.page.css index 3385492..2ab4558 100644 --- a/src/app/pages/settings/settings.page.css +++ b/src/app/pages/settings/settings.page.css @@ -12,6 +12,14 @@ .settings-tabs { position: relative; + display: flex; +} + +.tab-divider { + position: relative; + z-index: 10; + flex-shrink: 0; + margin: 0.75rem 0; } .tab-btn { diff --git a/src/app/pages/settings/settings.page.html b/src/app/pages/settings/settings.page.html index f07d199..1197fa0 100644 --- a/src/app/pages/settings/settings.page.html +++ b/src/app/pages/settings/settings.page.html @@ -37,6 +37,8 @@ } +
+ + +
+ +
+ + + + + + @if (isAttachmentMenuOpen()) { + + } + + + + + +
+
+
+

در حال گوش دادن...

+ +
+
+ diff --git a/src/app/shared/ui/ai-chat-input/ai-chat-input.component.ts b/src/app/shared/ui/ai-chat-input/ai-chat-input.component.ts new file mode 100644 index 0000000..fa88342 --- /dev/null +++ b/src/app/shared/ui/ai-chat-input/ai-chat-input.component.ts @@ -0,0 +1,177 @@ +import { + ChangeDetectionStrategy, + Component, + input, + output, + signal, + ViewChild, + ElementRef, + AfterViewChecked, + OnInit, + OnDestroy, + inject, +} from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { VoiceOrbService } from '../../../services/voice-orb/voice-orb.service'; + +@Component({ + selector: 'app-ai-chat-input', + standalone: true, + imports: [CommonModule], + changeDetection: ChangeDetectionStrategy.OnPush, + templateUrl: './ai-chat-input.component.html', + styleUrl: './ai-chat-input.component.css', +}) +export class AiChatInputComponent implements AfterViewChecked, OnInit, OnDestroy { + private readonly voiceOrbService = inject(VoiceOrbService); + + readonly placeholder = input('پیام خود را بنویسید...'); + readonly disabled = input(false); + + readonly messageSent = output(); + readonly fileSelected = output(); + readonly voiceToggled = output(); + + readonly message = signal(''); + readonly isVoiceMode = signal(false); + readonly isAttachmentMenuOpen = signal(false); + + @ViewChild('textarea') textareaRef!: ElementRef; + @ViewChild('composer') composerRef!: ElementRef; + @ViewChild('voiceContainer') voiceContainerRef!: ElementRef; + @ViewChild('orbContainer') orbContainerRef!: ElementRef; + @ViewChild('fileInput') fileInputRef!: ElementRef; + + private orbInited = false; + private menuCloseHandler: ((event: MouseEvent) => void) | null = null; + private escapeHandler: ((event: KeyboardEvent) => void) | null = null; + + selectFile(): void { + this.fileInputRef?.nativeElement.click(); + } + + ngOnInit(): void { + this.attachDocumentListeners(); + } + + ngAfterViewChecked(): void { + if (this.isVoiceMode() && !this.orbInited && this.orbContainerRef) { + this.orbInited = true; + this.voiceOrbService.init(this.orbContainerRef.nativeElement); + this.voiceOrbService.resetOrbGeometry(); + this.voiceOrbService.startAnimation(); + this.voiceOrbService.startListening().catch(() => { + /* orb continues without audio reactivity */ + }); + } + } + + ngOnDestroy(): void { + this.detachDocumentListeners(); + this.voiceOrbService.dispose(); + } + + onTextareaInput(): void { + const textarea = this.textareaRef?.nativeElement; + if (!textarea) return; + + this.message.set(textarea.value); + + textarea.style.height = 'auto'; + const scrollHeight = textarea.scrollHeight; + const maxHeight = 192; + const newHeight = Math.min(scrollHeight, maxHeight); + textarea.style.height = newHeight + 'px'; + } + + onKeyDown(event: KeyboardEvent): void { + if (event.key === 'Enter' && !event.shiftKey) { + event.preventDefault(); + this.sendMessage(); + } + } + + sendMessage(): void { + const text = this.message().trim(); + if (!text) return; + + this.messageSent.emit(text); + this.message.set(''); + + const textarea = this.textareaRef?.nativeElement; + if (textarea) { + textarea.value = ''; + textarea.style.height = 'auto'; + } + } + + toggleAttachmentMenu(): void { + this.isAttachmentMenuOpen.update((open) => !open); + } + + closeAttachmentMenu(): void { + this.isAttachmentMenuOpen.set(false); + } + + onFileChange(event: Event): void { + const input = event.target as HTMLInputElement; + const file = input.files?.[0]; + if (file) { + this.fileSelected.emit(file); + } + if (input.value) { + input.value = ''; + } + this.closeAttachmentMenu(); + } + + toggleVoiceMode(): void { + if (this.isVoiceMode()) { + this.exitVoiceMode(); + } else { + this.enterVoiceMode(); + } + } + + private enterVoiceMode(): void { + this.isVoiceMode.set(true); + this.orbInited = false; + this.voiceToggled.emit(true); + } + + exitVoiceMode(): void { + this.voiceOrbService.stopAnimation(); + this.voiceOrbService.stopListening(); + this.isVoiceMode.set(false); + this.voiceToggled.emit(false); + } + + private attachDocumentListeners(): void { + this.menuCloseHandler = (event: MouseEvent) => { + if (!this.isAttachmentMenuOpen()) return; + const target = event.target as Node; + if (this.composerRef && this.composerRef.nativeElement.contains(target)) { + return; + } + this.closeAttachmentMenu(); + }; + + this.escapeHandler = (event: KeyboardEvent) => { + if (event.key === 'Escape' && this.isAttachmentMenuOpen()) { + this.closeAttachmentMenu(); + } + }; + + document.addEventListener('mousedown', this.menuCloseHandler); + document.addEventListener('keydown', this.escapeHandler); + } + + private detachDocumentListeners(): void { + if (this.menuCloseHandler) { + document.removeEventListener('mousedown', this.menuCloseHandler); + } + if (this.escapeHandler) { + document.removeEventListener('keydown', this.escapeHandler); + } + } +}