Skip to content

Commit c429446

Browse files
committed
fix: global event to clear search on navbar press
closes: modrinth#1979
1 parent 8dd32bb commit c429446

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

apps/frontend/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@modrinth/ui": "workspace:*",
4141
"@modrinth/utils": "workspace:*",
4242
"@pinia/nuxt": "^0.5.1",
43+
"@types/three": "^0.172.0",
4344
"@vintl/vintl": "^4.4.1",
4445
"@vueuse/core": "^11.1.0",
4546
"ace-builds": "^1.36.2",
@@ -53,12 +54,12 @@
5354
"js-yaml": "^4.1.0",
5455
"jszip": "^3.10.1",
5556
"markdown-it": "14.1.0",
57+
"mitt": "^3.0.1",
5658
"pathe": "^1.1.2",
5759
"pinia": "^2.1.7",
5860
"qrcode.vue": "^3.4.0",
5961
"semver": "^7.5.4",
6062
"three": "^0.172.0",
61-
"@types/three": "^0.172.0",
6263
"vue-multiselect": "3.0.0-alpha.2",
6364
"vue-typed-virtual-list": "^1.0.10",
6465
"vue3-ace-editor": "^2.2.4",

apps/frontend/src/layouts/default.vue

+9
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
:highlighted-style="
116116
route.name === 'search-mods' ? 'main-nav-primary' : 'main-nav-secondary'
117117
"
118+
@click="$emit('search:clear')"
118119
>
119120
<nuxt-link to="/mods"> <BoxIcon aria-hidden="true" /> Mods </nuxt-link>
120121
</ButtonStyled>
@@ -126,6 +127,7 @@
126127
:highlighted-style="
127128
route.name === 'search-resourcepacks' ? 'main-nav-primary' : 'main-nav-secondary'
128129
"
130+
@click="$emit('search:clear')"
129131
>
130132
<nuxt-link to="/resourcepacks">
131133
<PaintBrushIcon aria-hidden="true" /> Resource Packs
@@ -137,6 +139,7 @@
137139
:highlighted-style="
138140
route.name === 'search-datapacks' ? 'main-nav-primary' : 'main-nav-secondary'
139141
"
142+
@click="$emit('search:clear')"
140143
>
141144
<nuxt-link to="/datapacks"> <BracesIcon aria-hidden="true" /> Data Packs </nuxt-link>
142145
</ButtonStyled>
@@ -146,6 +149,7 @@
146149
:highlighted-style="
147150
route.name === 'search-modpacks' ? 'main-nav-primary' : 'main-nav-secondary'
148151
"
152+
@click="$emit('search:clear')"
149153
>
150154
<nuxt-link to="/modpacks"> <PackageOpenIcon aria-hidden="true" /> Modpacks </nuxt-link>
151155
</ButtonStyled>
@@ -155,6 +159,7 @@
155159
:highlighted-style="
156160
route.name === 'search-shaders' ? 'main-nav-primary' : 'main-nav-secondary'
157161
"
162+
@click="$emit('search:clear')"
158163
>
159164
<nuxt-link to="/shaders"> <GlassesIcon aria-hidden="true" /> Shaders </nuxt-link>
160165
</ButtonStyled>
@@ -164,6 +169,7 @@
164169
:highlighted-style="
165170
route.name === 'search-plugins' ? 'main-nav-primary' : 'main-nav-secondary'
166171
"
172+
@click="$emit('search:clear')"
167173
>
168174
<nuxt-link to="/plugins"> <PlugIcon aria-hidden="true" /> Plugins </nuxt-link>
169175
</ButtonStyled>
@@ -202,6 +208,7 @@
202208
},
203209
]"
204210
hoverable
211+
@select="$emit('search:clear')"
205212
>
206213
<BoxIcon
207214
v-if="route.name === 'search-mods' || route.path.startsWith('/mod/')"
@@ -705,6 +712,8 @@ import TeleportOverflowMenu from "~/components/ui/servers/TeleportOverflowMenu.v
705712
const { formatMessage } = useVIntl();
706713
707714
const app = useNuxtApp();
715+
const { $emit } = app;
716+
708717
const auth = await useAuth();
709718
const user = await useUser();
710719

apps/frontend/src/pages/search/[searchProjectType].vue

+8
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ import {
334334
ImageIcon,
335335
} from "@modrinth/assets";
336336
import { computed } from "vue";
337+
import { useNuxtApp } from "#app";
337338
import ProjectCard from "~/components/ui/ProjectCard.vue";
338339
import LogoAnimated from "~/components/brand/LogoAnimated.vue";
339340
import AdPlaceholder from "~/components/ui/AdPlaceholder.vue";
@@ -344,6 +345,8 @@ const { formatMessage } = useVIntl();
344345
const filtersMenuOpen = ref(false);
345346
346347
const data = useNuxtApp();
348+
const { $listen } = data;
349+
347350
const route = useNativeRoute();
348351
const router = useNativeRouter();
349352
@@ -484,6 +487,7 @@ const {
484487
485488
// Functions
486489
createPageParams,
490+
readQueryParams,
487491
} = useSearch(projectTypes, tags, serverFilters);
488492
489493
const messages = defineMessages({
@@ -654,6 +658,10 @@ useSeoMeta({
654658
ogTitle,
655659
ogDescription: description,
656660
});
661+
662+
$listen("search:clear", () => {
663+
readQueryParams();
664+
});
657665
</script>
658666
659667
<style lang="scss" scoped>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import mitt from "mitt";
2+
3+
export default defineNuxtPlugin(() => {
4+
const emitter = mitt();
5+
return {
6+
provide: {
7+
event: emitter.emit,
8+
listen: emitter.on,
9+
},
10+
};
11+
});

packages/ui/src/utils/search.ts

+1
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ export function useSearch(
669669
// Functions
670670
createPageParams,
671671
createPageParamsString,
672+
readQueryParams
672673
}
673674
}
674675

pnpm-lock.yaml

+11-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)