Skip to content

Commit 5e649b4

Browse files
committed
Refactor the tiles + hooks to the store
1 parent 27332b9 commit 5e649b4

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/lib/store.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
import { writable, type Writable } from "svelte/store"
1+
import { readable, type Readable, writable, type Writable, derived } from "svelte/store"
2+
import type { Tile } from "./types"
23

34
export const selectedTile: Writable<number> = writable(0)
5+
6+
export const tiles: Readable<Tile[]> = readable([
7+
{ id: 0, url: "/", label: "Home", title: "Home", icon: "home" },
8+
{ id: 1, url: "/useState", label: "useState", title: "useState", icon: "code" },
9+
{ id: 2, url: "/useEffect", label: "useEffect", title: "useEffect", icon: "code" },
10+
{ id: 3, url: "/useMemo", label: "useMemo", title: "useMemo", icon: "code" },
11+
{ id: 4, url: "/useRef", label: "useRef", title: "useRef", icon: "code" },
12+
{ id: 5, url: "/useReducer", label: "useReducer", title: "useReducer", icon: "code" },
13+
{ id: 6, url: "/useCallback", label: "useCallback", title: "useCallback", icon: "code" },
14+
{ id: 7, url: "/useContext", label: "useContext", title: "useContext", icon: "code" }
15+
])
16+
17+
export const hooks = derived(tiles, $tiles => $tiles.slice(1))

src/lib/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface Tile {
2+
id: number
3+
url: string
4+
label: string
5+
title: string
6+
icon: string
7+
}

src/routes/+layout.svelte

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,10 @@
22
import "@skeletonlabs/skeleton/themes/theme-skeleton.css"
33
import "@skeletonlabs/skeleton/styles/all.css"
44
import "../app.postcss"
5-
import { selectedTile } from "../lib/store"
5+
import { selectedTile, tiles } from "../lib/store"
66
import { page } from "$app/stores"
77
import { AppShell, AppBar, AppRail, AppRailTile } from "@skeletonlabs/skeleton"
88
import Icon from "../lib/Icon.svelte"
9-
10-
let tiles = [
11-
{ id: 0, url: "/", label: "Home", title: "Home", icon: "home" },
12-
{ id: 1, url: "/useState", label: "useState", title: "useState", icon: "code" },
13-
{ id: 2, url: "/useEffect", label: "useEffect", title: "useEffect", icon: "code" },
14-
{ id: 3, url: "/useMemo", label: "useMemo", title: "useMemo", icon: "code" },
15-
{ id: 4, url: "/useRef", label: "useRef", title: "useRef", icon: "code" },
16-
{ id: 5, url: "/useReducer", label: "useReducer", title: "useReducer", icon: "code" },
17-
{ id: 6, url: "/useCallback", label: "useCallback", title: "useCallback", icon: "code" },
18-
{ id: 7, url: "/useContext", label: "useContext", title: "useContext", icon: "code" }
19-
]
209
</script>
2110

2211
<!-- App Shell -->
@@ -45,7 +34,7 @@
4534
<AppRail selected={selectedTile}>
4635
<svelte:fragment slot="lead">
4736
<!-- AppRailTiles -->
48-
{#each tiles as tile (tile.id)}
37+
{#each $tiles as tile (tile.id)}
4938
<AppRailTile
5039
label={tile.label}
5140
title={tile.title}

0 commit comments

Comments
 (0)