From 22f5266241b39c4c82c097e0b95c91324b33e155 Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 13 Jan 2024 12:43:51 +0900 Subject: [PATCH] feat: automatically populate search parameters when opening search box on search results page --- packages/client/src/components/MkSearchBox.vue | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/client/src/components/MkSearchBox.vue b/packages/client/src/components/MkSearchBox.vue index 33ff4217..6d636b0c 100644 --- a/packages/client/src/components/MkSearchBox.vue +++ b/packages/client/src/components/MkSearchBox.vue @@ -115,10 +115,20 @@ const emit = defineEmits<{ const modal = shallowRef>(); -const searchWords = ref(""); -const searchUsers = ref(""); -const searchRange = ref(""); -const searchPostsWithFiles = ref(false); +const searchParams = new URLSearchParams(window.location.search); + +const searchWords = ref(searchParams.get("q") ?? ""); +const searchUsers = ref( + searchParams.get("user") ?? searchParams.get("host") ?? "", +); +const searchRange = ref( + searchParams.has("since") || searchParams.has("until") + ? `${searchParams.get("since") ?? ""}-${ + searchParams.get("until") ?? "" + }` + : "", +); +const searchPostsWithFiles = ref(searchParams.get("withFiles") === "true"); function done(canceled: boolean, result?: searchQuery) { emit("done", { canceled, result });