Skip to content

Commit 63aadb8

Browse files
committed
feat: update implementation of @waradu/keyboard
1 parent cadda34 commit 63aadb8

11 files changed

Lines changed: 156 additions & 143 deletions

File tree

app/app.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
</template>
88

99
<script setup lang="ts">
10-
import { Key } from "@waradu/keyboard";
11-
12-
useKeybind(
13-
[Key.F],
14-
async () => {
10+
useKeybind({
11+
keys: ["f"],
12+
run() {
1513
useToast().success("You payed respect to the easter egg");
1614
},
17-
{ ignoreIfEditable: true }
18-
);
15+
config: { ignoreIfEditable: true },
16+
});
1917
</script>
2018

2119
<style lang="scss">

app/components/LeaderboardSetup.vue

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
<script setup lang="ts">
1717
import type { User } from "@prisma/client";
18-
import { Key } from "@waradu/keyboard";
1918
2019
const userState = useState<User | null>("user");
2120
@@ -33,21 +32,21 @@ async function setLeaderboard(option: boolean) {
3332
}
3433
}
3534
36-
useKeybind(
37-
[Key.Alt, Key.Y],
38-
async () => {
35+
useKeybind({
36+
keys: ["alt_y"],
37+
run() {
3938
setLeaderboard(true);
4039
},
41-
{ prevent: true, ignoreIfEditable: true }
42-
);
40+
config: { prevent: true, ignoreIfEditable: true },
41+
});
4342
44-
useKeybind(
45-
[Key.Alt, Key.N],
46-
async () => {
43+
useKeybind({
44+
keys: ["alt_n"],
45+
run() {
4746
setLeaderboard(false);
4847
},
49-
{ prevent: true, ignoreIfEditable: true }
50-
);
48+
config: { prevent: true, ignoreIfEditable: true },
49+
});
5150
</script>
5251

5352
<style scoped lang="scss">

app/pages/admin.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
</template>
9292

9393
<script setup lang="ts">
94-
import { Key } from "@waradu/keyboard";
94+
9595
import { LucideKeyRound } from "lucide-vue-next";
9696
import { ref, onMounted, onUnmounted } from "vue";
9797
@@ -223,25 +223,25 @@ function formatDate(date: string): string {
223223
});
224224
}
225225
226-
useKeybind(
227-
[Key.Alt, Key.L],
228-
async () => {
226+
useKeybind({
227+
keys: ["alt_l"],
228+
run: async () => {
229229
try {
230230
window.location.href = "/api/auth/logout";
231231
} catch (e: any) {
232232
useToast().error(e.data?.message || "Logout failed");
233233
}
234234
},
235-
{ prevent: true, ignoreIfEditable: true }
236-
);
235+
config: { prevent: true, ignoreIfEditable: true },
236+
});
237237
238-
useKeybind(
239-
[Key.Enter],
240-
async () => {
238+
useKeybind({
239+
keys: ["enter"],
240+
run: async () => {
241241
authenticate();
242242
},
243-
{ prevent: true, ignoreIfEditable: true }
244-
);
243+
config: { prevent: true, ignoreIfEditable: true },
244+
});
245245
246246
function formatMinutes(minutes: number): string {
247247
const h = Math.floor(minutes / 60);

app/pages/index.vue

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
import { ref, computed, watch, onMounted, onUnmounted } from "vue";
242242
import { LucideMaximize } from "lucide-vue-next";
243243
import type { User } from "@prisma/client";
244-
import { Key } from "@waradu/keyboard";
244+
245245
import * as statsLib from "~~/lib/stats";
246246
import type { Heartbeat } from "~~/lib/stats";
247247
import {
@@ -256,6 +256,7 @@ import {
256256
} from "chart.js";
257257
import { useTimeRangeOptions } from "~/composables/useTimeRangeOptions";
258258
import UiListModal from "~/components/Ui/ListModal.vue";
259+
import type { KeyString } from "@waradu/keyboard";
259260
260261
Chart.register(
261262
CategoryScale,
@@ -450,13 +451,13 @@ onMounted(async () => {
450451
timeRangeOptions.value.forEach(
451452
(option: { key: string; value: statsLib.TimeRange }) => {
452453
if (option.key && option.value) {
453-
useKeybind(
454-
[Key[option.key as keyof typeof Key]],
455-
async () => {
454+
useKeybind({
455+
keys: [option.key.toLocaleLowerCase() as KeyString],
456+
run: async () => {
456457
statsLib.setTimeRange(option.value);
457458
},
458-
{ prevent: true }
459-
);
459+
config: { prevent: true },
460+
});
460461
}
461462
}
462463
);
@@ -466,17 +467,17 @@ onMounted(async () => {
466467
}
467468
});
468469
469-
useKeybind(
470-
[Key.Alt, Key.L],
471-
async () => {
470+
useKeybind({
471+
keys: ["alt_l"],
472+
run: async () => {
472473
try {
473474
window.location.href = "/api/auth/logout";
474475
} catch (e: any) {
475476
toast.error(e.data?.message || "Logout failed");
476477
}
477478
},
478-
{ prevent: true, ignoreIfEditable: true }
479-
);
479+
config: { prevent: true, ignoreIfEditable: true },
480+
});
480481
481482
onUnmounted(() => {
482483
if (chart) {

app/pages/leaderboard.vue

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,54 @@
77

88
<td
99
:class="getHeaderClass('totalMinutes')"
10-
@click="setSort('totalMinutes')"
11-
>
10+
@click="setSort('totalMinutes')">
1211
Total Time
1312
</td>
1413

1514
<td
1615
v-if="!isMobile"
1716
:class="getHeaderClass('topLanguage')"
18-
@click="setSort('topLanguage')"
19-
>
17+
@click="setSort('topLanguage')">
2018
Top Language
2119
</td>
2220

2321
<td
2422
v-if="!isMobile"
2523
:class="getHeaderClass('topEditor')"
26-
@click="setSort('topEditor')"
27-
>
24+
@click="setSort('topEditor')">
2825
Top Editor
2926
</td>
3027

3128
<td
3229
v-if="!isMobile"
3330
:class="getHeaderClass('topOS')"
34-
@click="setSort('topOS')"
35-
>
31+
@click="setSort('topOS')">
3632
Top OS
3733
</td>
3834
</tr>
3935
</thead>
4036
<tbody>
4137
<tr v-for="user in sortedLeaderboard" :key="user.userId" class="row">
4238
<td class="userid">{{ user.userId }}</td>
43-
<td :class="getCellClass('totalMinutes')">{{ formatMinutes(user.totalMinutes) }}</td>
44-
<td v-if="!isMobile" :class="getCellClass('topLanguage')">{{ user.topLanguage || "Unknown" }}</td>
45-
<td v-if="!isMobile" :class="getCellClass('topEditor')">{{ user.topEditor || "Unknown" }}</td>
46-
<td v-if="!isMobile" :class="getCellClass('topOS')">{{ user.topOS || "Unknown" }}</td>
39+
<td :class="getCellClass('totalMinutes')">
40+
{{ formatMinutes(user.totalMinutes) }}
41+
</td>
42+
<td v-if="!isMobile" :class="getCellClass('topLanguage')">
43+
{{ user.topLanguage || "Unknown" }}
44+
</td>
45+
<td v-if="!isMobile" :class="getCellClass('topEditor')">
46+
{{ user.topEditor || "Unknown" }}
47+
</td>
48+
<td v-if="!isMobile" :class="getCellClass('topOS')">
49+
{{ user.topOS || "Unknown" }}
50+
</td>
4751
</tr>
4852
</tbody>
4953
</table>
5054
</NuxtLayout>
5155
</template>
5256

53-
5457
<script setup lang="ts">
55-
import { Key } from "@waradu/keyboard";
5658
import { ref, onMounted, onUnmounted } from "vue";
5759
5860
interface LeaderboardUser {
@@ -63,8 +65,9 @@ interface LeaderboardUser {
6365
topOS?: string;
6466
}
6567
66-
const { data: leaderboard } =
67-
await useFetch<LeaderboardUser[]>("/api/public/leaderboard");
68+
const { data: leaderboard } = await useFetch<LeaderboardUser[]>(
69+
"/api/public/leaderboard"
70+
);
6871
6972
const isMobile = ref(false);
7073
@@ -128,17 +131,17 @@ function formatMinutes(minutes: number): string {
128131
return `${h}h ${m}m`;
129132
}
130133
131-
useKeybind(
132-
[Key.Alt, Key.L],
133-
async () => {
134+
useKeybind({
135+
keys: ["alt_l"],
136+
run() {
134137
try {
135138
window.location.href = "/api/auth/logout";
136139
} catch (e: any) {
137140
useToast().error(e.data?.message || "Logout failed");
138141
}
139142
},
140-
{ prevent: true, ignoreIfEditable: true }
141-
);
143+
config: { prevent: true, ignoreIfEditable: true },
144+
});
142145
143146
useSeoMeta({
144147
title: "Ziit - Leaderboard",

app/pages/login.vue

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151

5252
<script setup lang="ts">
5353
import { LucideKeyRound, LucideMail } from "lucide-vue-next";
54-
import { Key } from "@waradu/keyboard";
5554
5655
const error = ref("");
5756
const email = ref("");
@@ -83,21 +82,21 @@ onMounted(() => {
8382
}
8483
});
8584
86-
useKeybind(
87-
[Key.G],
88-
async () => {
85+
useKeybind({
86+
keys: ["g"],
87+
async run() {
8988
await githubAuth();
9089
},
91-
{ ignoreIfEditable: true }
92-
);
90+
config: { ignoreIfEditable: true },
91+
});
9392
94-
useKeybind(
95-
[Key.Enter],
96-
async () => {
93+
useKeybind({
94+
keys: ["enter"],
95+
async run() {
9796
await login();
9897
},
99-
{ prevent: true }
100-
);
98+
config: { prevent: true },
99+
});
101100
102101
async function login() {
103102
error.value = "";

app/pages/register.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555

5656
<script setup lang="ts">
5757
import { LucideKeyRound, LucideMail } from "lucide-vue-next";
58-
import { Key } from "@waradu/keyboard";
5958
6059
const error = ref("");
6160
const email = ref("");
@@ -86,18 +85,18 @@ async function githubAuth() {
8685
window.location.href = "/api/auth/github";
8786
}
8887
89-
useKeybind([Key.G], async () => {
88+
useKeybind({keys: ["g"], async run() {
9089
if (isInputFocused.value) return;
9190
await githubAuth();
92-
});
91+
}});
9392
94-
useKeybind(
95-
[Key.Enter],
96-
async () => {
93+
useKeybind({
94+
keys: ["enter"],
95+
async run() {
9796
await register();
9897
},
99-
{ prevent: true }
100-
);
98+
config: { prevent: true }
99+
});
101100
102101
useSeoMeta({
103102
title: "Register - Ziit",

0 commit comments

Comments
 (0)