Skip to content

Commit 25eb4ed

Browse files
authored
Merge pull request #90 from idlip/feeling-lucky
implement an "Im feeling lucky" button to open random maintainer
2 parents 8325c43 + 6edbcf0 commit 25eb4ed

File tree

2 files changed

+56
-21
lines changed

2 files changed

+56
-21
lines changed

components/MaintainerList.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const normalizedMaintainers = computed(() =>
1010
maintainers.value?.map((m) => ({
1111
...m,
1212
projects_list: m.projects.map((p) => p.name).join(", "),
13-
}))
13+
})),
1414
);
1515
1616
const query = ref("");
@@ -51,11 +51,14 @@ onMounted(() => {
5151
<template>
5252
<div class="flex flex-col gap-8 px-8 py-10">
5353
<UiSearchInput
54-
ref="searchInputRef"
55-
class="max-w-90"
54+
v-if="maintainers"
5655
v-model="query"
57-
placeholder="Search Maintainers"
56+
:maintainers="maintainers"
57+
ref="searchInputRef"
58+
class="max-w-100"
59+
placeholder="Search"
5860
/>
61+
5962
<MaintainerCard
6063
v-for="maintainer in result"
6164
:key="maintainer.id"

components/ui/SearchInput.vue

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
11
<script setup lang="ts">
2-
const query = defineModel<string>();
2+
import { useRouter } from "vue-router";
3+
import type { MaintainersCollectionItem } from "@nuxt/content";
34
4-
const inputRef = ref<HTMLInputElement | null>(null);
5-
defineExpose({ focus: () => inputRef.value?.focus?.() });
5+
const props = defineProps<{
6+
modelValue: string;
7+
maintainers?: MaintainersCollectionItem[];
8+
placeholder?: string;
9+
}>();
10+
11+
const emit = defineEmits(["update:modelValue"]);
12+
13+
const router = useRouter();
14+
15+
const goToRandomMaintainer = () => {
16+
const list = props.maintainers || [];
17+
if (list.length === 0) return;
18+
19+
const randomIndex = Math.floor(Math.random() * list.length);
20+
const randomMaintainer = list[randomIndex];
21+
22+
if (randomMaintainer.path) {
23+
router.push(randomMaintainer.path);
24+
} else {
25+
console.warn("Missing path in random maintainer", randomMaintainer);
26+
}
27+
};
628
</script>
29+
730
<template>
8-
<div
9-
class="flex items-center px-4 py-2 gap-4 border has-focus:outline-1 transition-all duration-300 ease-linear"
10-
>
11-
<IconsSearch class="w-4 h-4" />
12-
<input
13-
ref="inputRef"
14-
v-model="query"
15-
type="text"
16-
placeholder="Search"
17-
class="input w-full dark:placeholder:text-secondary-dark placeholder:text-secondary-light text-sm focus:outline-none"
18-
/>
19-
<span class="text-xs border rounded px-2 hidden md:inline-block opacity-50">
20-
ctrl+k
21-
</span>
31+
<div class="grid grid-cols-1 sm:grid-cols-[1fr_auto] gap-2 items-center">
32+
<div class="flex items-center px-4 py-2 gap-4 border transition-all">
33+
<IconsSearch class="w-4 h-4" />
34+
<input
35+
:value="modelValue"
36+
@input="emit('update:modelValue', $event.target.value)"
37+
type="text"
38+
:placeholder="placeholder || 'Search'"
39+
class="input w-full dark:placeholder:text-secondary-dark placeholder:text-secondary-light text-sm focus:outline-none"
40+
/>
41+
<span
42+
class="text-xs border rounded px-2 hidden md:inline-block opacity-50"
43+
>
44+
ctrl+k
45+
</span>
46+
</div>
47+
48+
<button
49+
@click="goToRandomMaintainer"
50+
class="ml-2 flex text-sm gap-2 items-center btn-subtle w-fit"
51+
>
52+
Surprise Me!
53+
</button>
2254
</div>
2355
</template>

0 commit comments

Comments
 (0)