feat(view-link): add ViewLink component and routing logic

This commit is contained in:
Jan Gleytenhoover 2025-01-21 10:32:55 +01:00
parent 6317c97d96
commit 79fc66ef6b
Signed by: jank
GPG key ID: 50620ADD22CD330B
6 changed files with 52 additions and 0 deletions

View file

@ -3,6 +3,7 @@ import { LoginComponent } from './login/login.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { AuthGuard } from './service/auth.service';
import { CreateLinkComponent } from './create-link/create-link.component';
import { ViewLinkComponent } from './view-link/view-link.component';
export const routes: Routes = [
{
@ -19,6 +20,10 @@ export const routes: Routes = [
component: CreateLinkComponent,
canActivate: [AuthGuard],
},
{
path: ':link',
component: ViewLinkComponent,
},
{
path: "**",
redirectTo: "",

View file

@ -14,6 +14,10 @@ export class LinkService {
return this.pb.collection<Link>('links').getFullList<Link>();
}
getLink(id: string): Promise<Link> {
return this.pb.collection('links').getOne<Link>(id);
}
deleteLink(id: string) {
this.pb.collection('links').delete(id);
}

View file

@ -0,0 +1 @@
<p>Your are being redirected.</p>

View file

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ViewLinkComponent } from './view-link.component';
describe('ViewLinkComponent', () => {
let component: ViewLinkComponent;
let fixture: ComponentFixture<ViewLinkComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ViewLinkComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ViewLinkComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -0,0 +1,19 @@
import { Component } from '@angular/core';
import { LinkService } from '../service/link.service';
import { ActivatedRoute, Router } from '@angular/router';
@Component({
selector: 'app-view-link',
imports: [],
templateUrl: './view-link.component.html',
styleUrl: './view-link.component.css'
})
export class ViewLinkComponent {
constructor(private linkService: LinkService, private route: ActivatedRoute, private router: Router) { }
ngOnInit(): void {
this.linkService.getLink(this.route.snapshot.params['link']).then(link => {
window.location.href = link.link;
});
}
}