Skip to content

Commit

Permalink
feat: store query params to location href in app store page
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <[email protected]>
  • Loading branch information
ruibaby committed Sep 26, 2023
1 parent 309e554 commit 764bbaa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
1 change: 1 addition & 0 deletions console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@halo-dev/console-shared": "^2.9.0",
"@tanstack/vue-query": "^4.34.4",
"@vueuse/core": "^10.4.1",
"@vueuse/router": "^10.4.1",
"axios": "^1.5.0",
"dayjs": "^1.11.9",
"github-markdown-css": "^5.2.0",
Expand Down
16 changes: 16 additions & 0 deletions console/pnpm-lock.yaml

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

38 changes: 25 additions & 13 deletions console/src/views/AppStore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useLocalStorage } from "@vueuse/core";
import { computed, nextTick, watch } from "vue";
import { ref } from "vue";
import RiApps2Line from "~icons/ri/apps-2-line";
import { useRouteQuery } from "@vueuse/router";
const Types = [
{
Expand Down Expand Up @@ -70,22 +71,32 @@ const viewTypes = [
const viewType = useLocalStorage<string>("app-store-list-view", "grid");
const keyword = ref("");
const page = ref(1);
const size = ref(20);
const selectedSort = ref("latestReleaseTimestamp,desc");
const selectedPriceMode = ref();
const selectedType = ref();
const onlyQueryInstalled = ref(false);
const keyword = useRouteQuery<string>("keyword", "");
const page = useRouteQuery<number>("page", 1, { transform: Number });
const size = useRouteQuery<number>("size", 20, { transform: Number });
const selectedSort = useRouteQuery<string | undefined>("sort", "latestReleaseTimestamp,desc");
const selectedPriceMode = useRouteQuery("price-mode");
const selectedType = useRouteQuery<string | undefined>("type");
const onlyQueryInstalled = useRouteQuery<string>("installed", "false");
const onlyQueryInstalledAsBoolean = computed(() => onlyQueryInstalled.value === "true");
const { installedPlugins } = useFetchInstalledPlugins(onlyQueryInstalled);
const { installedThemes } = useFetchInstalledThemes(onlyQueryInstalled);
const { installedPlugins } = useFetchInstalledPlugins(onlyQueryInstalledAsBoolean);
const { installedThemes } = useFetchInstalledThemes(onlyQueryInstalledAsBoolean);
const { data, isFetching, isLoading, refetch } = useQuery<ListResponse<ApplicationSearchResult>>({
queryKey: ["store-apps", keyword, selectedSort, page, size, selectedPriceMode, selectedType, onlyQueryInstalled],
queryKey: [
"store-apps",
keyword,
selectedSort,
page,
size,
selectedPriceMode,
selectedType,
onlyQueryInstalledAsBoolean,
],
queryFn: async () => {
const appIds: string[] = [];
if (onlyQueryInstalled.value) {
if (onlyQueryInstalledAsBoolean.value) {
if (installedPlugins.value?.length) {
appIds.push(
...((installedPlugins.value?.map((plugin) => plugin.metadata.annotations?.[STORE_APP_ID]) || []).filter(
Expand Down Expand Up @@ -122,7 +133,7 @@ const { data, isFetching, isLoading, refetch } = useQuery<ListResponse<Applicati
size.value = data.size;
},
enabled: computed(() => {
if (onlyQueryInstalled.value) {
if (onlyQueryInstalledAsBoolean.value) {
return !!installedPlugins.value && !!installedThemes.value;
}
return true;
Expand Down Expand Up @@ -203,14 +214,15 @@ watch([selectedPriceMode, selectedType, selectedSort, onlyQueryInstalled, keywor
id="onlyQueryInstalled"
v-model="onlyQueryInstalled"
type="checkbox"
value="true"
class="as-h-3.5 as-w-3.5 as-rounded as-border-gray-300 as-text-indigo-600 focus:as-ring-indigo-600"
/>
</div>
<div class="as-text-sm">
<label
for="onlyQueryInstalled"
class="as-text-sm as-text-gray-700 hover:as-text-black"
:class="{ 'as-font-semibold as-text-gray-700': onlyQueryInstalled }"
:class="{ 'as-font-semibold as-text-gray-700': onlyQueryInstalledAsBoolean }"
>
已安装
</label>
Expand Down

0 comments on commit 764bbaa

Please sign in to comment.