Skip to content

Commit 7db836d

Browse files
feat: lazy import icons
Update +layout.svelte Update +layout.svelte Update +layout.svelte Update +layout.svelte
1 parent 7d02db3 commit 7db836d

1 file changed

Lines changed: 18 additions & 33 deletions

File tree

  • src/frontend/src/routes/(needs_onboarding)/(navbar_and_footer)

src/frontend/src/routes/(needs_onboarding)/(navbar_and_footer)/+layout.svelte

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@
2323
import * as Tooltip from '$lib/components/ui/tooltip/index';
2424
import favicon from '$lib/assets/logo.svg';
2525
import { PUBLIC_INSTANCE_URL } from '#consts/urls';
26-
import {
27-
SiGithub,
28-
SiBuymeacoffee,
29-
SiLiberapay,
30-
SiKofi,
31-
SiPatreon,
32-
SiUptimekuma
33-
} from '@icons-pack/svelte-simple-icons';
3426
import { env } from '$env/dynamic/public';
35-
27+
import { SiGithub, SiUptimekuma } from '@icons-pack/svelte-simple-icons';
3628
const { isAuthenticated, user: userData } = useAuth();
3729
3830
let { children } = $props();
@@ -100,33 +92,26 @@
10092
}
10193
]);
10294
103-
$effect(() => {
104-
type DonationKey =
105-
| 'PUBLIC_BUY_ME_A_COFFEE'
106-
| 'PUBLIC_LIBERAPAY'
107-
| 'PUBLIC_KO_FI'
108-
| 'PUBLIC_PATREON';
109-
110-
interface DonationPlatform {
111-
key: DonationKey;
112-
name: string;
113-
icon: any;
114-
}
115-
116-
const donationPlatforms: DonationPlatform[] = [
117-
{ key: 'PUBLIC_BUY_ME_A_COFFEE', name: 'Support by buying a coffee', icon: SiBuymeacoffee },
118-
{ key: 'PUBLIC_LIBERAPAY', name: 'Support by Liberapay', icon: SiLiberapay },
119-
{ key: 'PUBLIC_KO_FI', name: 'Support by Ko-Fi', icon: SiKofi },
120-
{ key: 'PUBLIC_PATREON', name: 'Support by Patreon', icon: SiPatreon }
95+
$effect.pre(() => {
96+
const donationPlatforms = [
97+
{ key: 'PUBLIC_BUY_ME_A_COFFEE', name: 'Buy Me A Coffee', path: 'SiBuymeacoffee' },
98+
{ key: 'PUBLIC_LIBERAPAY', name: 'Liberapay', path: 'SiLiberapay' },
99+
{ key: 'PUBLIC_KO_FI', name: 'Ko-Fi', path: 'SiKofi' },
100+
{ key: 'PUBLIC_PATREON', name: 'Patreon', path: 'SiPatreon' }
121101
];
122-
// Get the current largest order in footerLinks
123-
let maxOrder = footerLinks.reduce((max, link) => Math.max(max, link.order ?? 0), 0);
124102
125-
donationPlatforms.forEach(({ key, name, icon }) => {
103+
donationPlatforms.forEach(async ({ key, name, path }) => {
126104
const href = (env as Record<string, string | undefined>)[key];
127-
if (href) {
128-
maxOrder += 1; // increment for each new donation link
129-
footerLinks.push({ href, name, icon, order: maxOrder });
105+
106+
if (href && !footerLinks.some((link) => link.href === href)) {
107+
const module = await import(`@icons-pack/svelte-simple-icons/icons/${path}.svelte`);
108+
109+
footerLinks.push({
110+
href,
111+
name,
112+
icon: module.default,
113+
order: footerLinks.length + 1
114+
});
130115
}
131116
});
132117
});

0 commit comments

Comments
 (0)