Skip to content

Commit

Permalink
fix: dummy links won't redirect to front page (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Microwawe authored Nov 10, 2023
1 parent 0ac37b9 commit ac2f1f9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildsize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'
- uses: actions/cache@v3
with:
path: ~/.npm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'
- uses: actions/cache@v3
with:
path: ~/.npm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18'
- uses: actions/cache@v3
with:
path: ~/.npm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<button
aria-label="Slide back"
type="button"
class="absolute left-0 z-30 p-2 ml-10 focus:outline-none focus:bg-gray-400 focus:ring-2 focus:ring-offset-2 focus:ring-gray-400"
[ngClass]="['bg' + contrast]"
class="absolute left-0 z-30 p-2 ml-10 bg-opacity-50 rounded-full focus:outline-none focus:bg-gray-400 focus:ring-2 focus:ring-offset-2 focus:ring-gray-400"
>
<svg
class="w-4 h-4"
Expand All @@ -28,13 +29,14 @@
<img
src="https://source.unsplash.com/random/240x360/?{{ i }}"
alt="Image {{ i }}"
class="object-cover object-center h-96 aspect-square bg-gray-500"
class="object-cover object-center bg-gray-500 h-96 aspect-square"
/>
</div>
</div>
<button
aria-label="Slide forward"
class="absolute right-0 z-30 p-2 mr-10 focus:outline-none focus:bg-gray-400 focus:ring-2 focus:ring-offset-2 focus:ring-gray-400"
[ngClass]="['bg' + contrast]"
class="absolute right-0 z-30 p-2 mr-10 bg-opacity-50 rounded-full focus:outline-none focus:bg-gray-400 focus:ring-2 focus:ring-offset-2 focus:ring-gray-400"
id="next"
>
<svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ <h3 class="font-medium" [ngClass]="['text' + defaultInv]">
class="px-4 py-2 mb-2 text-sm border rounded sm:mb-0"
[ngClass]="['bg' + default, 'border' + plain, 'hover:border' + contrast]"
rel="noopener noreferrer"
href="/"
href="#"
>
Do something
</a>
<a
class="px-4 py-2 text-sm border rounded"
[ngClass]="['bg' + default, 'border' + plain, 'hover:border' + contrast]"
rel="noopener noreferrer"
href="/"
href="#"
>
Do something else
</a>
Expand Down Expand Up @@ -96,7 +96,7 @@ <h3 class="font-medium" [ngClass]="['text' + defaultInv]">
class="px-4 py-6 rounded-md shadow"
[ngClass]="['bg' + contrast]"
rel="noopener noreferrer"
href="/"
href="#"
>
<div class="flex flex-col space-y-4">
<div class="flex flex-col space-y-1">
Expand Down
22 changes: 22 additions & 0 deletions src/app/shared/directives/dummylink.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Directive, Input} from '@angular/core';

@Directive({
selector: '[href]',
host: {
'(click)': 'handleLinkClick($event)',
},
})
export class DummylinkDirective {
@Input() href;

/**
* Prevents the default action of the link if the href is empty or '#'
* So basically this prevents the <a> in the components from redirecting to the front page
*/
handleLinkClick(event) {
if (this.href === '' || this.href === '#') {
event.preventDefault();
event.stopPropagation();
}
}
}
8 changes: 6 additions & 2 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {ShowcaseComponent} from '@shared/components/showcase/showcase.component'
import {SearchComponent} from '@shared/components/search/search.component';
import {EmptyChildRouteComponent} from '@shared/components/empty-child-route/empty-child-route.component';
import {AdsComponent} from './components/ads/ads.component';
import {DummylinkDirective} from './directives/dummylink.directive';

const components = [
AdsComponent,
Expand All @@ -24,12 +25,15 @@ const components = [
ShowcaseComponent,
ShowCodeComponent,
];

const pipes = [FilterPipe];

const directives = [DummylinkDirective];

@NgModule({
imports: [CommonModule, HttpClientModule, FormsModule, RouterModule],
declarations: [...components, ...pipes],
exports: [CommonModule, HttpClientModule, FormsModule, ...components, ...pipes],
declarations: [...components, ...pipes, ...directives],
exports: [CommonModule, HttpClientModule, FormsModule, ...components, ...pipes, ...directives],
providers: [],
})
export class SharedModule {}
18 changes: 9 additions & 9 deletions src/app/templates/portfolio/portfolio2/portfolio2.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<header
class="container flex items-center justify-between w-full max-w-3xl px-6 py-10 mx-auto xl:max-w-5xl"
>
<a rel="noopener noreferrer" href="/" class="block h-6 text-2xl font-semibold">
<a rel="noopener noreferrer" href="#" class="block h-6 text-2xl font-semibold">
Leroy Jenkins
</a>
<div class="flex items-center">
<div class="hidden space-x-2 font-medium sm:block">
<a class="p-1" rel="noopener noreferrer" href="/">Blog</a>
<a class="p-1" rel="noopener noreferrer" href="/">Tags</a>
<a class="p-1" rel="noopener noreferrer" href="/">Projects</a>
<a class="p-1" rel="noopener noreferrer" href="/">About</a>
<a class="p-1" rel="noopener noreferrer" href="#">Blog</a>
<a class="p-1" rel="noopener noreferrer" href="#">Tags</a>
<a class="p-1" rel="noopener noreferrer" href="#">Projects</a>
<a class="p-1" rel="noopener noreferrer" href="#">About</a>
</div>
<button
aria-label="Toggle Dark Mode"
Expand Down Expand Up @@ -64,7 +64,7 @@
class="text-2xl font-bold tracking-widest"
[ngClass]="['text' + contrast]"
rel="noopener noreferrer"
href="/"
href="#"
>
Blog
</a>
Expand All @@ -74,7 +74,7 @@
class="text-2xl font-bold tracking-widest"
[ngClass]="['text' + contrast]"
rel="noopener noreferrer"
href="/"
href="#"
>
Tags
</a>
Expand All @@ -84,7 +84,7 @@
class="text-2xl font-bold tracking-widest"
[ngClass]="['text' + contrast]"
rel="noopener noreferrer"
href="/"
href="#"
>
Projects
</a>
Expand All @@ -94,7 +94,7 @@
class="text-2xl font-bold tracking-widest"
[ngClass]="['text' + contrast]"
rel="noopener noreferrer"
href="/"
href="#"
>
About
</a>
Expand Down

1 comment on commit ac2f1f9

@vercel
Copy link

@vercel vercel bot commented on ac2f1f9 Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mamba-ui – ./

mamba-ui-git-master-microwawe.vercel.app
mamba-ui-microwawe.vercel.app

Please sign in to comment.