Skip to content

Commit

Permalink
chore: utilize let
Browse files Browse the repository at this point in the history
  • Loading branch information
dalenguyen committed Jul 14, 2024
1 parent cab926f commit 2bbd48a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 63 deletions.
22 changes: 7 additions & 15 deletions pdf/src/app/pages/pdf-chat/[pdfId].page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CommonModule } from '@angular/common'
import { HttpClient } from '@angular/common/http'
import {
Component,
OnDestroy,
OnInit,
WritableSignal,
inject,
Expand All @@ -27,7 +26,7 @@ import { IconFieldModule } from 'primeng/iconfield'
import { InputIconModule } from 'primeng/inputicon'
import { InputTextModule } from 'primeng/inputtext'
import { ProgressBarModule } from 'primeng/progressbar'
import { Subject, lastValueFrom } from 'rxjs'
import { lastValueFrom } from 'rxjs'

export const routeMeta: RouteMeta = {
title: 'PDFun - AI Chat',
Expand All @@ -43,28 +42,29 @@ export const routeMeta: RouteMeta = {
<p-progressBar mode="indeterminate" [style]="{ height: '6px' }" />
}
@if (assistant()) {
@let assistantId = assistant()?.id;
@if (assistantId) {
<section class="max-w-3xl m-auto">
<div>
<p-iconField iconPosition="right">
<p-inputIcon
styleClass="pi pi-search"
class="cursor-pointer"
(click)="sendChat(assistant()!.id)"
(click)="sendChat(assistantId)"
/>
<input
type="text"
class="w-full mb-2"
pInputText
[(ngModel)]="prompt"
(keyup.enter)="sendChat(assistant()!.id)"
(keyup.enter)="sendChat(assistantId)"
placeholder="Help me to summary the content"
/>
</p-iconField>
</div>
<small class="italic">
<small class="italic block mb-6">
You can start asking any questions that relate to your PDF file.
</small>
Expand All @@ -89,7 +89,7 @@ export const routeMeta: RouteMeta = {
BuyMeACoffeeComponent,
],
})
export default class PDFChatDetailComponent implements OnInit, OnDestroy {
export default class PDFChatDetailComponent implements OnInit {
private router = inject(Router)
private http = inject(HttpClient)

Expand All @@ -111,10 +111,6 @@ export default class PDFChatDetailComponent implements OnInit, OnDestroy {

assistant: WritableSignal<undefined | Assistant> = signal(undefined)

private stopTimer$ = new Subject()
// Polling interval
INTERVAL = 3000

async ngOnInit(): Promise<void> {
const docRef = doc(this.firestore, `${this.filePath}/${this.pdfId()}`)

Expand Down Expand Up @@ -151,8 +147,4 @@ export default class PDFChatDetailComponent implements OnInit, OnDestroy {
this.prompt.set('')
this.response.set(result.response)
}

ngOnDestroy() {
this.stopTimer$.next(true)
}
}
49 changes: 24 additions & 25 deletions pdf/src/app/pages/pdf-password-removal.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ButtonModule } from 'primeng/button'
import { FileUploadHandlerEvent, FileUploadModule } from 'primeng/fileupload'
import { FloatLabelModule } from 'primeng/floatlabel'
import { PasswordModule } from 'primeng/password'
import { ProgressBarModule } from 'primeng/progressbar'
import { ToastModule } from 'primeng/toast'
import { DisclaimerComponent } from '../shared/components/disclaimer/disclaimer.component'
import { PdfHandlerBase } from '../shared/components/pdf-handler-base/pdf-handler-base.directive'
Expand All @@ -36,6 +37,7 @@ export const routeMeta: RouteMeta = {
PasswordModule,
FormsModule,
FloatLabelModule,
ProgressBarModule,
],
template: `
<p-toast />
Expand Down Expand Up @@ -73,31 +75,28 @@ export const routeMeta: RouteMeta = {
class="mb-4"
/>
@if(loading()) {
<div class="flex items-center my-4">
<div class="mr-2">
<i class="fa fa-spinner fa-spin text-blue-500"></i>
@if (loading()) {
<p-progressBar mode="indeterminate" [style]="{ height: '6px' }" />
}
@if (errorMessage()) {
<p class="text-red-500 mb-4">{{ errorMessage() }}</p>
}
@let downloadUrl = downloadUrl$ | async;
@if (downloadUrl) {
<div class="my-4 flex flex-col gap-4 items-center">
<a
[href]="downloadUrl"
target="_blank"
class="w-[180px] inline-flex justify-evenly items-center px-4 py-3 bg-blue-500 text-white rounded-md hover:bg-blue-600"
>
<i class="pi pi-download pr-2"></i>
Download PDF
</a>
<lib-buy-me-a-coffee />
</div>
<span
>Your file is uploaded and processing. Please wait for a moment.</span
>
</div>
} @if(errorMessage()) {
<p class="text-red-500 mb-4">{{ errorMessage() }}</p>
} @if(downloadUrl$ | async; as downloadUrl) {
<div class="my-4 flex flex-col gap-4 items-center">
<a
[href]="downloadUrl"
target="_blank"
class="w-[180px] inline-flex justify-evenly items-center px-4 py-3 bg-blue-500 text-white rounded-md hover:bg-blue-600"
>
<i class="pi pi-download pr-2"></i>
Download PDF
</a>
<lib-buy-me-a-coffee />
</div>
}
<pdf-disclaimer class="mt-8" />
Expand Down Expand Up @@ -129,7 +128,7 @@ export default class PdfPasswordRemovalComponent extends PdfHandlerBase {

const storageRef = ref(
this.storage,
`${this.generateFilePath()}/${fileName}`
`${this.generateFilePath()}/${fileName}`,
)
const result = await uploadBytesResumable(storageRef, file)
const { uid = 'anonymous' } =
Expand Down
47 changes: 24 additions & 23 deletions pdf/src/app/pages/pdf-to-images.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BuyMeACoffeeComponent } from '@pdfun/ui/common'
import { nanoid } from 'nanoid'
import { ButtonModule } from 'primeng/button'
import { FileUploadHandlerEvent, FileUploadModule } from 'primeng/fileupload'
import { ProgressBarModule } from 'primeng/progressbar'
import { ToastModule } from 'primeng/toast'
import { DisclaimerComponent } from '../shared/components/disclaimer/disclaimer.component'
import { PdfHandlerBase } from '../shared/components/pdf-handler-base/pdf-handler-base.directive'
Expand All @@ -30,6 +31,7 @@ export const routeMeta: RouteMeta = {
FileUploadModule,
BuyMeACoffeeComponent,
DisclaimerComponent,
ProgressBarModule,
],
template: `
<p-toast />
Expand All @@ -54,29 +56,28 @@ export const routeMeta: RouteMeta = {
class="mb-4"
/>
@if(loading()) {
<div class="flex items-center mb-4">
<div class="mr-2">
<i class="fa fa-spinner fa-spin text-blue-500"></i>
@if (loading()) {
<p-progressBar mode="indeterminate" [style]="{ height: '6px' }" />
}
@if (errorMessage()) {
<p class="text-red-500 mb-4">{{ errorMessage() }}</p>
}
@let downloadUrl = downloadUrl$ | async;
@if (downloadUrl) {
<div class="my-4 flex flex-col gap-4 items-center">
<a
[href]="downloadUrl"
target="_blank"
class="w-[200px] inline-flex justify-evenly items-center px-4 py-3 bg-blue-500 text-white rounded-md hover:bg-blue-600"
>
<i class="pi pi-download pr-2"></i>
Download Images
</a>
<lib-buy-me-a-coffee />
</div>
<span
>Your file is uploaded and processing. Please wait for a moment.</span
>
</div>
} @if(errorMessage()) {
<p class="text-red-500 mb-4">{{ errorMessage() }}</p>
} @if(downloadUrl$ | async; as downloadUrl) {
<a
[href]="downloadUrl"
target="_blank"
class="inline-flex items-center px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 mb-4"
>
<i class="pi pi-download pr-2"></i>
Download Images
</a>
<lib-buy-me-a-coffee />
}
<pdf-disclaimer class="mt-8" />
Expand All @@ -99,7 +100,7 @@ export default class PdfToImagesComponent extends PdfHandlerBase {

const storageRef = ref(
this.storage,
`${this.generateFilePath()}/${fileName}`
`${this.generateFilePath()}/${fileName}`,
)
const result = await uploadBytesResumable(storageRef, file)
const { uid = 'anonymous' } =
Expand Down

0 comments on commit 2bbd48a

Please sign in to comment.