Skip to content

Commit

Permalink
Merge branch 'release' into analog-1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dalenguyen authored Jun 14, 2024
2 parents d89884c + 395b87e commit 24e4a63
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
8 changes: 7 additions & 1 deletion pdf/src/app/pages/(home).page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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'
import { ShoutOutComponent } from '../shared/components/shout-out/shout-out.component'
import { ByteSizeFormatter } from '../shared/pipes'
import { getNextDays } from '../shared/utils'

export const routeMeta: RouteMeta = {
Expand Down Expand Up @@ -55,7 +56,11 @@ export const routeMeta: RouteMeta = {
@if(this.newFileSize() < this.currentFileSize()) {
<p class="mb-4">
Congratulations! Your file is reduced by
{{ this.currentFileSize() - this.newFileSize() }} bytes!
<strong
>{{
this.currentFileSize() - this.newFileSize() | byteSizeFormatter
}}!</strong
>
</p>
}
Expand All @@ -82,6 +87,7 @@ export const routeMeta: RouteMeta = {
BuyMeACoffeeComponent,
ShoutOutComponent,
DisclaimerComponent,
ByteSizeFormatter,
],
})
export default class HomeComponent extends PdfHandlerBase {
Expand Down
6 changes: 4 additions & 2 deletions pdf/src/app/shared/components/footer/footer.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { RouterTestingModule } from '@angular/router/testing'
import { provideRouter } from '@angular/router'
import { FooterComponent } from './footer.component'

describe('FooterComponent', () => {
Expand All @@ -8,7 +8,9 @@ describe('FooterComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FooterComponent, RouterTestingModule],
imports: [FooterComponent],
imports: [FooterComponent],
providers: [provideRouter([])],
}).compileComponents()

fixture = TestBed.createComponent(FooterComponent)
Expand Down
8 changes: 4 additions & 4 deletions pdf/src/app/shared/components/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ import { LoginComponent, ProfileComponent } from '@pdfun/ui/auth'
<div class="flex gap-4">
<a
routerLink="/"
routerLinkActive="text-gray-200"
[routerLinkActiveOptions]="{ exact: true }"
class="text-gray-400 no-underline hover:text-white transition-colors duration-300"
routerLinkActive="active"
class="link"
>
Resize PDF
</a>
<a
routerLink="/pdf-to-images"
routerLinkActive="text-gray-200"
class="text-gray-400 no-underline hover:text-white transition-colors duration-300"
routerLinkActive="active"
class="link"
>
PDF to Images
</a>
Expand Down
22 changes: 22 additions & 0 deletions pdf/src/app/shared/pipes/byte-size-formatter.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Pipe, PipeTransform } from '@angular/core'

@Pipe({
name: 'byteSizeFormatter',
standalone: true,
})
export class ByteSizeFormatter implements PipeTransform {
transform(bytes: number, precision = 1): string {
if (isNaN(parseFloat(String(bytes))) || !isFinite(bytes))
return 'Invalid number'

const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB']
let unitIndex = 0

while (bytes >= 1024 && unitIndex < units.length - 1) {
bytes /= 1024
unitIndex++
}

return `${bytes.toFixed(precision)} ${units[unitIndex]}`
}
}
1 change: 1 addition & 0 deletions pdf/src/app/shared/pipes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './byte-size-formatter.pipe'
15 changes: 14 additions & 1 deletion pdf/src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer tailwind-base, tailwind-utilities, primeng;
@layer tailwind-base, tailwind-utilities, tailwind-component, primeng;

@layer tailwind-base {
@tailwind base;
Expand All @@ -8,6 +8,19 @@
@tailwind utilities;
}

@layer tailwind-components {
@tailwind components;
}

@layer tailwind-components {
.link {
@apply text-gray-400 no-underline hover:text-white transition-colors duration-300;
}
.active {
@apply text-gray-200;
}
}

@import 'primeng/resources/themes/tailwind-light/theme.css';
@import 'primeng/resources/primeng.css';
@import 'primeicons/primeicons.css';
Expand Down

0 comments on commit 24e4a63

Please sign in to comment.