Skip to content

Commit

Permalink
feat: add pkg details page
Browse files Browse the repository at this point in the history
  • Loading branch information
manekinekko committed Mar 13, 2023
1 parent d56674f commit 5cda09e
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NotFoundComponent } from './shared/not-found/not-found.component';
export const routes: Routes = [
{ path: '', redirectTo: '/search', pathMatch: 'full' },
{ path: 'search', loadChildren: () => import('./search/search.module').then(m => m.SearchModule) },
{ path: 'pkg', loadChildren: () => import('./details/details.module').then(m => m.DetailsModule) },
{ path: '**', component: NotFoundComponent }
];

Expand Down
13 changes: 13 additions & 0 deletions src/app/details/details-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DetailsComponent } from './details.component';

export const routes: Routes = [
{ path: '', redirectTo: ':name', pathMatch: 'full' },
{ path: ':name', component: DetailsComponent }
];

@NgModule({
imports: [RouterModule.forChild(routes)]
})
export class DetailsRoutingModule { }
4 changes: 4 additions & 0 deletions src/app/details/details.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:host {
display: block;
padding: 100px 20px;
}
4 changes: 4 additions & 0 deletions src/app/details/details.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<app-card [package]="pkg()"></app-card>
<mat-card class="package-details-readme" *ngIf="pkg()?.readme">
<mat-card-content [innerHTML]="readme()"></mat-card-content>
</mat-card>
23 changes: 23 additions & 0 deletions src/app/details/details.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DetailsComponent } from './details.component';

describe('DetailsComponent', () => {
let component: DetailsComponent;
let fixture: ComponentFixture<DetailsComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DetailsComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(DetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
42 changes: 42 additions & 0 deletions src/app/details/details.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Component, OnInit, signal } from '@angular/core';
import { Router } from '@angular/router';
import * as showdown from 'showdown';
import { PackageType } from 'src/typings';


@Component({
selector: 'app-details',
templateUrl: './details.component.html',
styleUrls: ['./details.component.css'],
host: {
class: 'package-details-wide'
}
})
export class DetailsComponent implements OnInit {

pkg = signal<PackageType | null>(null);
query = signal('');

constructor(private router: Router) {
window.scrollTo(0, 0);
}

ngOnInit(): void {

const { pkg, query } = window.history.state;

if (!pkg) {
this.router.navigate(['/']);
return;
}

this.query.set(query);
this.pkg.set(pkg as PackageType);

}

readme() {
const converter = new showdown.Converter();
return converter.makeHtml(this.pkg()?.readme || '');
}
}
10 changes: 10 additions & 0 deletions src/app/details/details.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { DetailsRoutingModule } from './details-routing.module';

@NgModule({
imports: [CommonModule, DetailsRoutingModule],
declarations: [],
providers: [],
})
export class DetailsModule {}

0 comments on commit 5cda09e

Please sign in to comment.