-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path+layout.svelte
175 lines (168 loc) · 5.01 KB
/
+layout.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<script>
import { onMount } from "svelte";
import { storage, Statistics, CrateDocManager } from "querylib";
import "../app.css";
import { themeStore } from "../store/index";
let isDarkMode = false;
let hiddenMenu = true;
const menus = [
{
name: "Home",
path: "/",
},
{
name: "Crates",
path: "/crates",
},
{
name: "Stats",
path: "/stats",
},
{
name: "Settings",
path: "/settings",
},
];
function handleChangeThemeMode() {
if (isDarkMode) {
document.documentElement.classList.add("dark");
localStorage.setItem("QUERY_RS_THEME", "dark");
themeStore.update(() => "dark");
} else {
document.documentElement.classList.remove("dark");
localStorage.setItem("QUERY_RS_THEME", "light");
themeStore.update(() => "light");
}
}
function changeThemeMethod() {
isDarkMode = !isDarkMode;
handleChangeThemeMode();
}
onMount(async () => {
let firstVisit = await storage.getItem("first-visit");
if (firstVisit === null) {
let response = await fetch("https://crates.io/api/v1/crates/tokio");
let data = await response.json();
response = await fetch(
`https://query.rs/index/${data.crate.name}/${data.crate.newest_version}`
);
data = await response.json();
await CrateDocManager.addCrate(data);
// Create first query record
let statistics = await Statistics.load();
await statistics.record(
{
query: "hi",
content: "https://query.rs",
description: "Welcome to query.rs",
time: Date.now(),
},
true
);
await storage.setItem("first-visit", "false");
}
});
onMount(() => {
if (
localStorage.QUERY_RS_THEME === "dark" ||
(!("QUERY_RS_THEME" in localStorage) &&
window.matchMedia("(prefers-color-scheme: dark)").matches)
) {
isDarkMode = true;
} else {
isDarkMode = false;
}
handleChangeThemeMode();
});
</script>
<div class="flex-layout dark:bg-darkBgPrimary dark:text-darkTextPrimary" style="flex-direction: column;">
<div class="max-w-[1160px] w-full flex flex-col">
<ul
class="hidden list-none flex-row overflow-auto md:flex self-end py-5 text-base md:text-xl items-center"
>
{#each menus as menu}
<li
class="px-5 rounded-md hover:bg-[#f9bc2d46] dark:hover:bg-darkHoverColor"
>
<a
class="dark:text-darkTextPrimary dark:visited:text-darkTextPrimary"
href={menu.path}>{menu.name}</a
>
</li>
{/each}
<button
class="w-10 h-10 dark:hover:bg-darkHoverColor rounded-lg hover:bg-[#f9bc2d46]"
on:click={changeThemeMethod}
>
{#if isDarkMode}
<img src="/assets/light.svg" alt="light mode" />
{:else}
<img src="/assets/dark.svg" alt="dark mode" />
{/if}
</button>
</ul>
<div>
<div class="flex flex-row justify-between items-center md:hidden">
<img
src="/assets/logo.svg"
alt="logo"
class="w-24 mx-6 transition-opacity ease-in-out delay-300 duration-1000 dark:invert"
class:opacity-0={hiddenMenu}
class:opacity-100={!hiddenMenu}
/>
<button
on:click={() => (hiddenMenu = !hiddenMenu)}
class="z-50 p-4 inline-block"
>
<svg
class="w-5 h-5"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 17 14"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M1 1h15M1 7h15M1 13h15"
/>
</svg>
</button>
</div>
<button
on:click={() => (hiddenMenu = true)}
class="transition ease-in-out duration-700 z-10 right-0 text-left list-none absolute flex-col target:flex shadow-md text-base bg-[#fcfaf6] rounded-md w-full"
class:-translate-y-72={hiddenMenu}
class:translate-y-0={!hiddenMenu}
>
{#each menus as menu}
<a class="p-3 px-6 block" href={menu.path}>{menu.name}</a>
{/each}
</button>
</div>
<div
class="dark:bg-[#18181b] box-border px-4 py-12 md:px-12 md:py-24 bg-[white] relative rounded-[10px] mb-[50px] min-h-[calc(100vh_-_180px)]"
>
<a href="/" class="no-underline hover:no-underline">
<img
src="/assets/logo.svg"
alt="logo"
class="block mx-auto w-60 md:w-80 mt-8 mb-12 dark:invert"
/>
</a>
<slot />
</div>
</div>
<footer class="pb-6 text-center px-4 dark:text-darkTextPrimary">
© 2024 Query.rs, built by
<a
href="https://github.com/folyd"
target="_blank"
class="dark:text-darkTextPrimary">Folyd</a
>
with ❤️❤️, see <a href="/about" class="dark:text-darkTextPrimary">about</a> page
to learn more.
</footer>
</div>