Skip to content

Commit 77a7980

Browse files
Improve loading method for buttons (#62)
1 parent 3ca67fc commit 77a7980

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/lib/blocks/Hero.svelte

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script>
2-
import { _, json, isLoading } from "svelte-i18n";
32
import { onMount } from "svelte";
3+
import { _, isLoading, json } from "svelte-i18n";
44
5-
import { osStore } from "$lib/store";
65
import { config } from "$lib/config";
6+
import { osStore } from "$lib/store";
77
8-
import Vanta from "$lib/components/Vanta.svelte";
98
import Button from "$lib/components/Button.svelte";
10-
import ImageCompare from "$lib/components/ImageCompare.svelte";
119
import Divider from "$lib/components/Divider.svelte";
10+
import ImageCompare from "$lib/components/ImageCompare.svelte";
11+
import Vanta from "$lib/components/Vanta.svelte";
1212
1313
export let id = "";
1414
export let classes = "";
@@ -18,6 +18,7 @@
1818
export let buttons = [];
1919
2020
let heroContent, heroImages, githubButton, githubButtonTranslation, translatedGithubButton, unsubscribeOs;
21+
let isOsLoading = true;
2122
2223
$: {
2324
heroContent = $json("config.site.heroContent") || "";
@@ -28,6 +29,7 @@
2829
2930
// Subscribe to osStore
3031
unsubscribeOs = osStore.subscribe((data) => {
32+
isOsLoading = data.loading;
3133
if (!data.loading && !$isLoading) {
3234
const translatedOsButtons = data.osButtons.map((button) => ({
3335
...button,
@@ -73,12 +75,17 @@
7375
<p class="text-center font-light md:text-lg xl:text-xl">
7476
{heroContent.description}
7577
</p>
76-
{#if buttons.length > 0}
78+
{#if buttons.length > 0 && !isOsLoading && !$isLoading}
7779
<div class="grid grid-flow-row items-center gap-4 md:grid-flow-col">
7880
{#each buttons as button}
7981
<Button highlight={button.highlight} icon={button.icon} text={button.text} href={button.href} />
8082
{/each}
8183
</div>
84+
{:else if heroContent.description}
85+
<div class="grid grid-flow-row items-center gap-4 md:grid-flow-col h-12 opacity-0">
86+
<!-- Placeholder to reserve space -->
87+
<div class="py-4 px-5 rounded min-h-12 w-32"></div>
88+
</div>
8289
{/if}
8390
</div>
8491

src/lib/components/Button.svelte

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script>
2+
import { onMount } from "svelte";
23
import DynamicIcon from "./DynamicIcon.svelte";
34
45
export let button = true;
@@ -37,6 +38,7 @@
3738
let translatedIcon = icons[icon] || "";
3839
let iconTheme = iconThemes[icon] || "bs";
3940
let hasIcon = translatedIcon !== "";
41+
let visible = false;
4042
4143
switch (textSize) {
4244
case "xs":
@@ -52,6 +54,13 @@
5254
iconSize *= 1.3;
5355
break;
5456
}
57+
58+
onMount(() => {
59+
// Small delay to ensure everything is loaded before showing
60+
setTimeout(() => {
61+
visible = true;
62+
}, 50);
63+
});
5564
</script>
5665

5766
{#if isLink}
@@ -71,7 +80,9 @@
7180
class:text-md={textSize === "md"}
7281
class:text-lg={textSize === "lg"}
7382
class:text-xl={textSize === "xl"}
74-
class="flex items-center justify-between gap-3 font-medium"
83+
class:fade-in={visible}
84+
class="flex items-center justify-between gap-3 font-medium transition-opacity duration-300"
85+
class:opacity-0={!visible}
7586
{rel}
7687
{href}
7788
{title}
@@ -156,4 +167,8 @@
156167
.button.regular {
157168
@apply from-mine-shaft-50 to-mine-shaft-100 text-neutral-700 border border-mine-shaft-300;
158169
}
170+
171+
.fade-in {
172+
@apply opacity-100;
173+
}
159174
</style>

0 commit comments

Comments
 (0)