-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathStationSelector.vue
More file actions
101 lines (91 loc) · 2.52 KB
/
StationSelector.vue
File metadata and controls
101 lines (91 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<template>
<VSelect
:key="allStations.length"
v-model="selectedStation"
:loading="session.loading"
class="station-selector"
eager
:variant="app.isMobile ? 'filled' : 'solo'"
density="default"
hide-details
:bg-color="props.bgColor"
item-value="canisterId"
:items="allStations"
>
<template #item="{ props: itemProps, item }">
<VListItem
v-bind="itemProps"
:title="computedStationName({ canisterId: Principal.fromText(item.raw.canisterId) })"
:subtitle="item.raw.canisterId"
/>
</template>
<template #selection="{ item }">
<VListItem
v-if="allStations.length"
:title="computedStationName({ canisterId: Principal.fromText(item.raw.canisterId) })"
:prepend-icon="mdiWallet"
/>
<VListItem v-else :title="noneSelectedText" :prepend-icon="mdiWallet" />
</template>
<template #append-item>
<AddStationListItem />
</template>
</VSelect>
</template>
<script lang="ts" setup>
import { Principal } from '@icp-sdk/core/principal';
import { mdiWallet } from '@mdi/js';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useAppStore } from '~/stores/app.store';
import { useSessionStore } from '~/stores/session.store';
import { computedStationName } from '~/utils/app.utils';
import AddStationListItem from './add-station/AddStationListItem.vue';
import { VListItem, VSelect } from 'vuetify/components';
const props = withDefaults(
defineProps<{
bgColor?: string;
}>(),
{
bgColor: 'surface',
},
);
const session = useSessionStore();
const app = useAppStore();
const i18n = useI18n();
const allStations = computed(() => session.data.stations);
const noneSelectedText = computed(() => i18n.t('stations.no_stations'));
const selectedStation = computed({
get(): string | null {
return session.data.selected.canisterId ? session.data.selected.canisterId : null;
},
set(newStationId: string | null) {
if (!newStationId) {
session.disconnectStation();
return;
}
session.connectStation(Principal.fromText(newStationId));
},
});
</script>
<style lang="scss">
.station-selector {
.v-field__input {
padding-top: calc(var(--ds-bdu) / 2);
padding-bottom: calc(var(--ds-bdu) / 2);
}
.v-select__selection {
.v-list-item__prepend {
.v-list-item__spacer {
width: calc(var(--ds-bdu) * 2);
}
}
> .v-list-item {
padding-left: 0;
}
.v-list-item__content {
text-overflow: ellipsis;
}
}
}
</style>