remember pairlist collapsed state

This commit is contained in:
Tako 2023-06-13 13:00:45 +00:00
parent 69a2825822
commit e136127e4c
4 changed files with 13 additions and 21 deletions

View File

@ -26,22 +26,22 @@
@click="pairlistStore.removeFromConfig(index)" @click="pairlistStore.removeFromConfig(index)"
/> />
<i-mdi-chevron-down <i-mdi-chevron-down
v-if="!showParameters" v-if="!pairlist.showParameters"
:class="hasParameters && !showParameters ? 'visible' : 'invisible'" :class="hasParameters && !pairlist.showParameters ? 'visible' : 'invisible'"
role="button" role="button"
class="fs-4" class="fs-4"
@click="toggleVisible" @click="toggleVisible"
/> />
<i-mdi-chevron-up <i-mdi-chevron-up
v-if="showParameters" v-if="pairlist.showParameters"
:class="hasParameters && showParameters ? 'visible' : 'invisible'" :class="hasParameters && pairlist.showParameters ? 'visible' : 'invisible'"
role="button" role="button"
class="fs-4" class="fs-4"
@click="toggleVisible" @click="toggleVisible"
/> />
</div> </div>
</template> </template>
<b-collapse v-model="showParameters"> <b-collapse v-model="pairlist.showParameters">
<b-card-body> <b-card-body>
<PairlistConfigParameter <PairlistConfigParameter
v-for="(parameter, key) in pairlist.params" v-for="(parameter, key) in pairlist.params"
@ -58,7 +58,7 @@
import PairlistConfigParameter from '@/components/ftbot/PairlistConfigParameter.vue'; import PairlistConfigParameter from '@/components/ftbot/PairlistConfigParameter.vue';
import { usePairlistConfigStore } from '@/stores/pairlistConfig'; import { usePairlistConfigStore } from '@/stores/pairlistConfig';
import { Pairlist } from '@/types'; import { Pairlist } from '@/types';
import { computed, ref } from 'vue'; import { computed } from 'vue';
const pairlistStore = usePairlistConfigStore(); const pairlistStore = usePairlistConfigStore();
@ -66,15 +66,13 @@ defineProps<{
index: number; index: number;
}>(); }>();
const showParameters = ref(false);
const pairlist = defineModel<Pairlist>({ required: true }); const pairlist = defineModel<Pairlist>({ required: true });
const hasParameters = computed(() => Object.keys(pairlist.value.params).length > 0); const hasParameters = computed(() => Object.keys(pairlist.value.params).length > 0);
function toggleVisible() { function toggleVisible() {
if (hasParameters.value) { if (hasParameters.value) {
showParameters.value = !showParameters.value; pairlist.value.showParameters = !pairlist.value.showParameters;
} }
} }
</script> </script>

View File

@ -58,7 +58,7 @@
:class="{ empty: configEmpty }" :class="{ empty: configEmpty }"
> >
<PairlistConfigItem <PairlistConfigItem
v-for="(pairlist, i) in pairlistsComp" v-for="(pairlist, i) in pairlistStore.config.pairlists"
:key="pairlist.id" :key="pairlist.id"
v-model="pairlistStore.config.pairlists[i]" v-model="pairlistStore.config.pairlists[i]"
:index="i" :index="i"
@ -103,17 +103,6 @@ const pairlistConfigsEl = ref<HTMLElement | null>(null);
const availablePairlistsEl = ref<HTMLElement | null>(null); const availablePairlistsEl = ref<HTMLElement | null>(null);
const selectedView = ref<'Config' | 'Results'>('Config'); const selectedView = ref<'Config' | 'Results'>('Config');
// v-for updates with sorting, deleting and adding items seem to get wonky without unique keys for every item
const pairlistsComp = computed(() =>
pairlistStore.config.pairlists.map((p) => {
if (p.id) {
return p;
} else {
return { id: Date.now().toString(36) + Math.random().toString(36).substring(2), ...p };
}
}),
);
const configEmpty = computed(() => { const configEmpty = computed(() => {
return pairlistStore.config.pairlists.length == 0; return pairlistStore.config.pairlists.length == 0;
}); });

View File

@ -62,6 +62,10 @@ export const usePairlistConfigStore = defineStore(
function addToConfig(pairlist: Pairlist, index: number) { function addToConfig(pairlist: Pairlist, index: number) {
pairlist = structuredClone(toRaw(pairlist)); pairlist = structuredClone(toRaw(pairlist));
pairlist.showParameters = false;
if (!pairlist.id) {
pairlist.id = Date.now().toString(36) + Math.random().toString(36).substring(2);
}
for (const param in pairlist.params) { for (const param in pairlist.params) {
pairlist.params[param].value = isNotUndefined(pairlist.params[param].default) pairlist.params[param].value = isNotUndefined(pairlist.params[param].default)
? pairlist.params[param].default ? pairlist.params[param].default

View File

@ -15,6 +15,7 @@ export interface Pairlist {
is_pairlist_generator: boolean; is_pairlist_generator: boolean;
name: string; name: string;
description: string; description: string;
showParameters: boolean;
params: Record<string, PairlistParameter>; params: Record<string, PairlistParameter>;
} }