forked from snapshot-labs/snapshot-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModalPlugins.vue
105 lines (97 loc) · 2.76 KB
/
ModalPlugins.vue
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
102
103
104
105
<script setup lang="ts">
import { ref, watch, toRefs } from 'vue';
import { PluginIndex } from '@/helpers/interfaces';
import { usePlugins } from '@/composables';
const props = defineProps<{ open: boolean; plugin: PluginIndex }>();
const emit = defineEmits(['add', 'close']);
const { open } = toRefs(props);
const searchInput = ref('');
const input = ref({});
const isValid = ref(true);
const selectedPlugin = ref<PluginIndex | null>(null);
const {
filterPlugins,
pluginIndex,
loadingPluginsSpacesCount,
getPluginsSpacesCount
} = usePlugins();
function handleSubmit() {
const key = selectedPlugin.value?.key;
emit('add', { input: input.value, key });
emit('close');
}
function selectPlugin(plugin) {
selectedPlugin.value = plugin;
input.value = selectedPlugin.value?.defaults?.space ?? {};
}
watch(open, () => {
if (props.open) getPluginsSpacesCount();
if (Object.keys(props.plugin).length > 0) {
const key = Object.keys(props.plugin)[0];
input.value = props.plugin[key];
selectedPlugin.value =
Object.values(pluginIndex).find(p => p.key === key) ?? null;
} else {
input.value = {};
selectedPlugin.value = null;
}
});
</script>
<template>
<BaseModal :open="open" @close="$emit('close')">
<template #header>
<h3>
{{
selectedPlugin?.key
? $t('settings.editPlugin')
: $t('settings.addPlugin')
}}
</h3>
</template>
<BaseSearch
v-if="!selectedPlugin?.key"
v-model="searchInput"
:placeholder="$t('searchPlaceholder')"
modal
/>
<div class="my-4 mx-0 min-h-[300px] md:mx-4">
<BaseBlock
v-if="selectedPlugin?.key"
slim
class="mb-4 rounded-md p-4 text-skin-link"
>
<h4 class="mb-3 text-center" v-text="selectedPlugin.name" />
<TextareaJson
v-model="input"
v-model:is-valid="isValid"
:placeholder="$t('settings.pluginParameters')"
class="input text-left"
/>
</BaseBlock>
<div v-if="!selectedPlugin?.key">
<LoadingRow v-if="loadingPluginsSpacesCount" block />
<div v-else class="space-y-3">
<BasePluginItem
v-for="(pluginItem, i) in filterPlugins(searchInput)"
:key="i"
:plugin="pluginItem"
@click="selectPlugin(pluginItem)"
/>
<BaseNoResults
v-if="Object.keys(filterPlugins(searchInput)).length < 1"
/>
</div>
</div>
</div>
<template v-if="selectedPlugin?.key" #footer>
<BaseButton
:disabled="!isValid"
class="w-full"
primary
@click="handleSubmit"
>
{{ Object.keys(plugin).length ? $t('save') : $t('add') }}
</BaseButton>
</template>
</BaseModal>
</template>