diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 3fb9e53..467203d 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -25,7 +25,7 @@ describe('AppComponent', () => { fixture.detectChanges(); const compiled = fixture.nativeElement as HTMLElement; expect(compiled.querySelector('h1')?.textContent).toContain( - 'Hello, jklink', + 'Hello, jklink' ); }); }); diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index c9976fa..9168254 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -21,7 +21,7 @@ export const routes: Routes = [ canActivate: [AuthGuard], }, { - path: ':link', + path: ':slug', component: ViewLinkComponent, }, { diff --git a/src/app/confirmation-modal/confirmation-modal.component.html b/src/app/confirmation-modal/confirmation-modal.component.html index 13635d0..ed62bbc 100644 --- a/src/app/confirmation-modal/confirmation-modal.component.html +++ b/src/app/confirmation-modal/confirmation-modal.component.html @@ -1,6 +1,14 @@

{{ data.title }}

{{ data.description }} - + diff --git a/src/app/create-link/create-link.component.html b/src/app/create-link/create-link.component.html index 304eb92..5fc49cc 100644 --- a/src/app/create-link/create-link.component.html +++ b/src/app/create-link/create-link.component.html @@ -1,6 +1,13 @@
- @@ -20,6 +27,11 @@ placeholder="https://kjan.de" /> + + {{ errorMessages["slug"] }} + Custom slug (optional) + + diff --git a/src/app/create-link/create-link.component.ts b/src/app/create-link/create-link.component.ts index ebf9788..9ca3530 100644 --- a/src/app/create-link/create-link.component.ts +++ b/src/app/create-link/create-link.component.ts @@ -32,10 +32,7 @@ export class CreateLinkComponent { public requestFailed: boolean = false; public errorMessages: Record = {}; - constructor( - private linkService: LinkService, - private router: Router, - ) {} + constructor(private linkService: LinkService, private router: Router) {} private validationErrorMessages: Record = { required: 'This field is required', @@ -53,7 +50,7 @@ export class CreateLinkComponent { .map( (errorKey) => this.validationErrorMessages[errorKey] || - `Unknown error: ${errorKey}`, + `Unknown error: ${errorKey}` ) .join(' '); } @@ -70,9 +67,10 @@ export class CreateLinkComponent { link: new FormControl('', [ Validators.required, Validators.pattern( - /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/, + /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/ ), ]), + slug: new FormControl(''), }); this.createLinkForm.valueChanges.subscribe(() => { this.updateErrorMessages(); @@ -89,6 +87,7 @@ export class CreateLinkComponent { .createLink({ name: this.createLinkForm.get('name')?.value, link: this.createLinkForm.get('link')?.value, + slug: this.createLinkForm.get('slug')?.value, }) .catch(() => (this.requestFailed = true)) .finally(() => { diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html index 21581f1..ca085e2 100644 --- a/src/app/dashboard/dashboard.component.html +++ b/src/app/dashboard/dashboard.component.html @@ -24,11 +24,11 @@ The actual rendered columns are set as a property on the row definition" --> - - ID + + Slug - {{ element.id }} + {{ element.slug }} @@ -49,11 +49,7 @@ Short link - diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index 6b8fee8..1acced3 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -27,7 +27,7 @@ import { AuthRecord } from 'pocketbase'; }) export class DashboardComponent { public links: Link[] = []; - displayedColumns: string[] = ['id', 'name', 'link', 'shortLink', 'actions']; + displayedColumns: string[] = ['slug', 'name', 'link', 'shortLink', 'actions']; public user!: AuthRecord; constructor( @@ -35,15 +35,15 @@ export class DashboardComponent { private router: Router, private dialog: MatDialog, private snackBar: MatSnackBar, - private userService: UserService, + private userService: UserService ) {} - copyLink(id: string) { - navigator.clipboard.writeText(this.getShortLink(id)); + copyLink(link: Link) { + navigator.clipboard.writeText(this.getShortLink(link)); } - getShortLink(id: string): string { - return 'https://' + window.location.hostname + '/' + id; + getShortLink(link: Link): string { + return 'https://' + window.location.hostname + '/' + link.slug; } goToLink(link: Link) { @@ -91,7 +91,7 @@ export class DashboardComponent { if (accepted) { this.linkService.deleteLink(link.id).catch(() => { const errorNotification = this.snackBar.open( - 'Something went wrong.', + 'Something went wrong.' ); setTimeout(() => { errorNotification.dismiss(); diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 8d2b906..d05fa7a 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -35,10 +35,7 @@ export class LoginComponent { private pb = new PocketBase(environment.POCKETBASE); public errorMessages: Record = {}; - constructor( - private router: Router, - private snackBar: MatSnackBar, - ) {} + constructor(private router: Router, private snackBar: MatSnackBar) {} private validationErrorMessages: Record = { required: 'This field is required', @@ -55,7 +52,7 @@ export class LoginComponent { .map( (errorKey) => this.validationErrorMessages[errorKey] || - `Unknown error: ${errorKey}`, + `Unknown error: ${errorKey}` ) .join(' '); } @@ -105,7 +102,7 @@ export class LoginComponent { .collection('users') .authWithPassword( this.loginForm.get('email')?.value, - this.loginForm.get('password')?.value, + this.loginForm.get('password')?.value ) .then(() => { this.router.navigate(['dashboard']); diff --git a/src/app/models/link.ts b/src/app/models/link.ts index 0f961c3..86ce99a 100644 --- a/src/app/models/link.ts +++ b/src/app/models/link.ts @@ -3,4 +3,5 @@ export interface Link { link: string; name: string; owner: string; + slug: string; } diff --git a/src/app/service/auth.service.ts b/src/app/service/auth.service.ts index 4290efa..387a6c3 100644 --- a/src/app/service/auth.service.ts +++ b/src/app/service/auth.service.ts @@ -18,7 +18,7 @@ export class AuthGuard implements CanActivate { async canActivate( route: ActivatedRouteSnapshot, - state: RouterStateSnapshot, + state: RouterStateSnapshot ): Promise { const pb = new PocketBase(environment.POCKETBASE); await pb diff --git a/src/app/service/link.service.ts b/src/app/service/link.service.ts index 77c01ee..a4a3f91 100644 --- a/src/app/service/link.service.ts +++ b/src/app/service/link.service.ts @@ -13,8 +13,8 @@ export class LinkService { return this.pb.collection('links').getFullList(); } - getLink(id: string): Promise { - return this.pb.collection('links').getOne(id); + getLink(slug: string): Promise { + return this.pb.collection('links').getFirstListItem(`slug="${slug}"`); } deleteLink(id: string): Promise { @@ -26,6 +26,7 @@ export class LinkService { name: link.name, link: link.link, owner: this.pb.authStore.record?.id, + slug: link.slug, }); } } diff --git a/src/app/service/user.service.ts b/src/app/service/user.service.ts index ad6a555..6893b96 100644 --- a/src/app/service/user.service.ts +++ b/src/app/service/user.service.ts @@ -1,6 +1,6 @@ -import { Injectable } from "@angular/core"; +import { Injectable } from '@angular/core'; import PocketBase, { AuthRecord } from 'pocketbase'; -import { environment } from "../../environments/environment"; +import { environment } from '../../environments/environment'; @Injectable({ providedIn: 'root', diff --git a/src/app/view-link/view-link.component.ts b/src/app/view-link/view-link.component.ts index 635e560..c8fa572 100644 --- a/src/app/view-link/view-link.component.ts +++ b/src/app/view-link/view-link.component.ts @@ -12,12 +12,12 @@ export class ViewLinkComponent { constructor( private linkService: LinkService, private route: ActivatedRoute, - private router: Router, + private router: Router ) {} ngOnInit(): void { this.linkService - .getLink(this.route.snapshot.params['link']) + .getLink(this.route.snapshot.params['slug']) .then((link) => { window.location.href = link.link; }); diff --git a/src/index.html b/src/index.html index 9d15f1b..b554755 100644 --- a/src/index.html +++ b/src/index.html @@ -1,4 +1,4 @@ - + diff --git a/src/main.ts b/src/main.ts index 8882c45..514c89a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,5 +3,5 @@ import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; bootstrapApplication(AppComponent, appConfig).catch((err) => - console.error(err), + console.error(err) );