Skip to content

Commit

Permalink
add kz district and district availability check (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninedev-i authored Dec 16, 2024
1 parent 6e3c61b commit b278cae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
6 changes: 4 additions & 2 deletions common/districts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import type { Districts } from '~/common/types';

export const districts: Districts = {
ru: [
{ value: 'moscow', label: 'Москва и область', coordinates: [55.8, 37.5], zoom: 9 },
{ value: 'spb', label: 'Санкт-Петербург', coordinates: [59.75, 30.5], zoom: 9 },
{ value: 'moscow', label: 'Москва и область', coordinates: [55.6, 37.5], zoom: 8 },
{ value: 'spb', label: 'Санкт-Петербург', coordinates: [59.95, 30.5], zoom: 9 },
{ value: 'center', label: 'Центральный округ', coordinates: [54.21, 37.62], zoom: 12 },
{ value: 'volga', label: 'Приволжский округ', coordinates: [57.5, 51], zoom: 6 },
{ value: 'ural', label: 'Уральский округ', coordinates: [56.84, 60.57], zoom: 12 },
{ value: 'by', label: 'Беларусь', coordinates: [53.95, 27.65], zoom: 9 },
{ value: 'kz', label: 'Казахстан', coordinates: [43.24, 76.88], zoom: 10 },
{ value: 'kg', label: 'Кыргызстан', coordinates: [42.90, 74.5], zoom: 10 },
],
en: [
{ value: 'by', label: 'Republic of Belarus', coordinates: [53.95, 27.65], zoom: 12 },
{ value: 'kz', label: 'Kazakhstan', coordinates: [43.24, 76.88], zoom: 10 },
{ value: 'kg', label: 'Republic of Kyrgyzstan', coordinates: [42.90, 74.5], zoom: 10 },
],
};
38 changes: 25 additions & 13 deletions pages/contents/integrators.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts" setup>
import { districts } from '~/common/districts';
import type { District } from "~/common/types";
import Select from '~/components/Select.vue';
const { t, locale } = useI18n();
Expand All @@ -16,18 +17,29 @@ const mapCenter = computed(() => {
: locale.value === 'ru' ? [53, 45] : [50, 52]
});
const query = reactive({ path: '/_integrators', where: [{
_locale: locale.value, district: { $contains: district.value }
}], sort: [{ title: 1 }, { priority: 1 }] });
const query = reactive({
path: '/_integrators',
where: [
{
district: { $contains: district.value },
_locale: locale.value
}
],
sort: [
{ title: 1 },
{ priority: 1 },
]
});
const { data, refresh } = await useAsyncData('integrators', () => queryContent(query.path).where({ _locale: locale.value, district: { $contains: district.value } }).find());
const { data, refresh } = await useAsyncData('integrators', () => queryContent(query.path).where({ _locale: locale.value }).find());
const actualDistricts = ref();
const filterChanged = () => {
query.where = [{
_locale: locale.value, district: { $contains: district.value }
}]
refresh();
};
watch(data, async (value) => {
const districtsInList = [...new Set(value?.map(item => item.district).flat())];
actualDistricts.value = districts[locale.value].filter((district) => districtsInList.includes(district.value));
},
{ once: true, immediate: true }
);
const onChangeMapItems = (items: string[]) => {
visibleItems.value = items;
Expand All @@ -38,18 +50,18 @@ const onChangeMapItems = (items: string[]) => {
<Map
:items="data"
:center="mapCenter"
:zoom="district ? districts[locale].find(item => item.value === district)?.zoom as number : 4"
:zoom="district ? actualDistricts.find((item: District) => item.value === district)?.zoom as number : 4"
@visibleItemsChange="onChangeMapItems"
/>

<Select
class="partners-filter"
v-model="district"
:options="districts[locale]"
optionLabel="label"
optionValue="value"
:options="actualDistricts"
:placeholder="t('chooseArea')"
:change-callback="filterChanged"
:change-callback="refresh"
/>

<ContentList :query="query">
Expand Down

0 comments on commit b278cae

Please sign in to comment.