Skip to content

Commit b56fe50

Browse files
committed
Refactor modal import and enhance error page with emojis
1 parent 8fb6114 commit b56fe50

File tree

5 files changed

+97
-17
lines changed

5 files changed

+97
-17
lines changed

src/components/Modal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { onMount } from 'svelte';
33
onMount(async () => {
44
// Only runs in browser
5-
const bootstrap = await import('bootstrap/js/dist/modal.js');
5+
await import('bootstrap/js/dist/modal.js');
66
});
77
88
const {

src/components/emojis.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const emojis = {
2+
// TODO add the rest!
3+
420: '🫠',
4+
404: '🤔',
5+
500: '🤕'
6+
};

src/routes/+error.svelte

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script>
2+
import { page } from '$app/state';
3+
import { emojis } from '../components/emojis.js';
4+
</script>
5+
6+
<svelte:head>
7+
<title>ERROR {page.status} - {page.error.message}</title>
8+
<meta name="robots" content="noindex, follow" />
9+
</svelte:head>
10+
11+
<div id="notfound">
12+
<div class="notfound">
13+
<div class="notfound-404">
14+
<h1>Oops!</h1>
15+
{emojis[page.status] ?? emojis[500]}
16+
<h2>ERROR {page.status}: {page.error.message}</h2>
17+
</div>
18+
<p>
19+
Uh-oh! It seems the page you're looking for has either been removed, relocated, or may not
20+
exist at all. Before you venture further, double-check the URL in your browser. If all seems
21+
well, consider navigating back to our homepage to explore anew. Thanks for your understanding!
22+
</p>
23+
<a href="/">Go To Homepage</a>
24+
</div>
25+
</div>
26+
27+
<style>
28+
#notfound {
29+
height: 100svh;
30+
display: grid;
31+
place-content: center;
32+
}
33+
.notfound {
34+
max-width: 600px;
35+
width: 100%;
36+
text-align: center;
37+
}
38+
.notfound-404 h1 {
39+
font-size: 4rem;
40+
margin: 0 0 1rem 0;
41+
}
42+
.notfound p {
43+
line-height: 1.5rem;
44+
font-size: 1rem;
45+
}
46+
.notfound a {
47+
font-size: 1rem;
48+
text-decoration: none;
49+
text-transform: uppercase;
50+
background: #333;
51+
display: inline-block;
52+
padding: 1rem 2rem;
53+
border-radius: 1rem;
54+
color: #fff;
55+
font-weight: 700;
56+
box-shadow: 0 4px 15px -5px #333;
57+
}
58+
</style>

src/routes/+page.svelte

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import Counter from '/src/components/Counter.svelte';
33
import Logos from '/src/components/Logos.svelte';
44
import Modal from '/src/components/Modal.svelte';
5+
import { onMount } from 'svelte';
6+
7+
let hrefLocation = '';
8+
onMount(() => {
9+
hrefLocation = window.location.href;
10+
});
511
</script>
612

713
<svelte:head>
@@ -16,24 +22,34 @@
1622
<div class="container">
1723
<div class="row gap-4">
1824
<h1 class="h2">Welcome to SvelteKit + Bootstrap by Saaqi</h1>
25+
1926
<div class="d-flex gap-5">
2027
<Logos />
2128
</div>
22-
<div class="w-auto">
23-
<div class="d-flex gap-3">
24-
<div style="width: 10em">
25-
<Counter btnStyle="secondary" />
26-
</div>
27-
<div style="width: 10em">
28-
<Modal
29-
btnTitle="Demo Modal"
30-
modalTitle="Demo Modal title"
31-
id="demoModal"
32-
body="Hello, I'm a modal!"
33-
/>
34-
</div>
29+
30+
<div class="mb-5 col-xl-4 col-md-6">
31+
<div class="mb-3 d-flex justify-content-between gap-3">
32+
<Counter btnStyle="secondary" />
33+
<Modal
34+
id="modal-demo"
35+
btnTitle="Modal Demo"
36+
modalTitle="Cat's Diary"
37+
body="Make muffins give attitude chase mice sweet beast under the bed all of a sudden go crazy behind the couch destroy couch intently stare at the same spot chew ipad power cord bag stretch claw drapes, leave dead animals as gifts attack feet flop over hopped up on goofballs hunt anything that moves hide when guests come over intrigued by the shower stand in front of the computer screen rub face on everything."
38+
/>
39+
</div>
40+
41+
<div>
42+
<a
43+
href="https://pagespeed.web.dev/report?url={hrefLocation}"
44+
target="_blank"
45+
class="btn btn-light w-100"
46+
rel="noreferrer"
47+
>
48+
Google PageSpeed Report
49+
</a>
3550
</div>
3651
</div>
52+
3753
<p>
3854
Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation
3955
</p>

vite.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export default defineConfig({
4040

4141
/* ## Download Google Fonts and attach them with production build for offline use */
4242
IN_PRODUCTION &&
43-
webfontDownload([
44-
'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap'
45-
]),
43+
webfontDownload([
44+
'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap'
45+
])
4646
],
4747

4848
css: {

0 commit comments

Comments
 (0)