Skip to content

feat: global event to clear search on navbar btn press #3620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@modrinth/ui": "workspace:*",
"@modrinth/utils": "workspace:*",
"@pinia/nuxt": "^0.5.1",
"@types/three": "^0.172.0",
"@vintl/vintl": "^4.4.1",
"@vueuse/core": "^11.1.0",
"ace-builds": "^1.36.2",
Expand All @@ -53,12 +54,12 @@
"js-yaml": "^4.1.0",
"jszip": "^3.10.1",
"markdown-it": "14.1.0",
"mitt": "^3.0.1",
"pathe": "^1.1.2",
"pinia": "^2.1.7",
"qrcode.vue": "^3.4.0",
"semver": "^7.5.4",
"three": "^0.172.0",
"@types/three": "^0.172.0",
"vue-multiselect": "3.0.0-alpha.2",
"vue-typed-virtual-list": "^1.0.10",
"vue3-ace-editor": "^2.2.4",
Expand Down
14 changes: 14 additions & 0 deletions apps/frontend/src/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
:highlighted-style="
route.name === 'search-mods' ? 'main-nav-primary' : 'main-nav-secondary'
"
@click="attemptSearchClear"
>
<nuxt-link to="/mods"> <BoxIcon aria-hidden="true" /> Mods </nuxt-link>
</ButtonStyled>
Expand All @@ -126,6 +127,7 @@
:highlighted-style="
route.name === 'search-resourcepacks' ? 'main-nav-primary' : 'main-nav-secondary'
"
@click="attemptSearchClear"
>
<nuxt-link to="/resourcepacks">
<PaintBrushIcon aria-hidden="true" /> Resource Packs
Expand All @@ -137,6 +139,7 @@
:highlighted-style="
route.name === 'search-datapacks' ? 'main-nav-primary' : 'main-nav-secondary'
"
@click="attemptSearchClear"
>
<nuxt-link to="/datapacks"> <BracesIcon aria-hidden="true" /> Data Packs </nuxt-link>
</ButtonStyled>
Expand All @@ -146,6 +149,7 @@
:highlighted-style="
route.name === 'search-modpacks' ? 'main-nav-primary' : 'main-nav-secondary'
"
@click="attemptSearchClear"
>
<nuxt-link to="/modpacks"> <PackageOpenIcon aria-hidden="true" /> Modpacks </nuxt-link>
</ButtonStyled>
Expand All @@ -155,6 +159,7 @@
:highlighted-style="
route.name === 'search-shaders' ? 'main-nav-primary' : 'main-nav-secondary'
"
@click="attemptSearchClear"
>
<nuxt-link to="/shaders"> <GlassesIcon aria-hidden="true" /> Shaders </nuxt-link>
</ButtonStyled>
Expand All @@ -164,6 +169,7 @@
:highlighted-style="
route.name === 'search-plugins' ? 'main-nav-primary' : 'main-nav-secondary'
"
@click="attemptSearchClear"
>
<nuxt-link to="/plugins"> <PlugIcon aria-hidden="true" /> Plugins </nuxt-link>
</ButtonStyled>
Expand Down Expand Up @@ -202,6 +208,7 @@
},
]"
hoverable
@select="attemptSearchClear"
>
<BoxIcon
v-if="route.name === 'search-mods' || route.path.startsWith('/mod/')"
Expand Down Expand Up @@ -705,6 +712,8 @@ import TeleportOverflowMenu from "~/components/ui/servers/TeleportOverflowMenu.v
const { formatMessage } = useVIntl();

const app = useNuxtApp();
const { $emit } = app;

const auth = await useAuth();
const user = await useUser();

Expand Down Expand Up @@ -1108,6 +1117,11 @@ function runAnalytics() {
console.error(`Sending analytics failed (CORS error? If so, ignore)`, e);
}
}

function attemptSearchClear() {
$emit("search:clear");
}

function toggleMobileMenu() {
isMobileMenuOpen.value = !isMobileMenuOpen.value;
if (isMobileMenuOpen.value) {
Expand Down
8 changes: 8 additions & 0 deletions apps/frontend/src/pages/search/[searchProjectType].vue
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ import {
ImageIcon,
} from "@modrinth/assets";
import { computed } from "vue";
import { useNuxtApp } from "#app";
import ProjectCard from "~/components/ui/ProjectCard.vue";
import LogoAnimated from "~/components/brand/LogoAnimated.vue";
import AdPlaceholder from "~/components/ui/AdPlaceholder.vue";
Expand All @@ -344,6 +345,8 @@ const { formatMessage } = useVIntl();
const filtersMenuOpen = ref(false);

const data = useNuxtApp();
const { $listen } = data;

const route = useNativeRoute();
const router = useNativeRouter();

Expand Down Expand Up @@ -484,6 +487,7 @@ const {

// Functions
createPageParams,
readQueryParams,
} = useSearch(projectTypes, tags, serverFilters);

const messages = defineMessages({
Expand Down Expand Up @@ -654,6 +658,10 @@ useSeoMeta({
ogTitle,
ogDescription: description,
});

$listen("search:clear", () => {
readQueryParams();
});
</script>

<style lang="scss" scoped>
Expand Down
11 changes: 11 additions & 0 deletions apps/frontend/src/plugins/global-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import mitt from "mitt";

export default defineNuxtPlugin(() => {
const emitter = mitt();
return {
provide: {
event: emitter.emit,
listen: emitter.on,
},
};
});
1 change: 1 addition & 0 deletions packages/ui/src/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ export function useSearch(
// Functions
createPageParams,
createPageParamsString,
readQueryParams
}
}

Expand Down
19 changes: 11 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.