Spaces:
Running
Running
Jimin Huang
commited on
Commit
·
cc14f28
1
Parent(s):
b58106b
Change settings
Browse files- src/components/AssetTabs.vue +19 -22
src/components/AssetTabs.vue
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
<template>
|
| 2 |
<div class="flex gap-2 flex-wrap">
|
| 3 |
<button
|
| 4 |
-
v-for="
|
| 5 |
class="px-3 py-1 rounded-full border flex items-center gap-2"
|
| 6 |
-
:class="
|
| 7 |
-
@click="$emit('update:modelValue',
|
| 8 |
>
|
| 9 |
-
<img
|
| 10 |
-
<span>{{
|
| 11 |
</button>
|
| 12 |
</div>
|
| 13 |
</template>
|
|
@@ -16,36 +16,33 @@
|
|
| 16 |
import { computed } from 'vue'
|
| 17 |
import { dataService } from '../lib/dataService'
|
| 18 |
|
| 19 |
-
// import the logos you actually have in /src/assets (add/remove as needed)
|
| 20 |
-
import AAPL from '@/assets/AAPL.png'
|
| 21 |
-
import MSFT from '@/assets/MSFT.png'
|
| 22 |
-
import BTC from '@/assets/BTC.png'
|
| 23 |
-
import ETH from '@/assets/ETH.png'
|
| 24 |
-
import BMRN from '@/assets/BMRN.png'
|
| 25 |
-
import MRNA from '@/assets/MRNA.png'
|
| 26 |
-
import TSLA from '@/assets/TSLA.png'
|
| 27 |
-
|
| 28 |
const props = defineProps({
|
| 29 |
modelValue: { type: String, default: '' },
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
})
|
| 32 |
const emit = defineEmits(['update:modelValue'])
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
}
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
| 39 |
const rows = Array.isArray(dataService.tableRows) ? dataService.tableRows : []
|
| 40 |
-
return
|
| 41 |
})
|
| 42 |
|
|
|
|
| 43 |
const orderedAssets = computed(() => {
|
| 44 |
-
const present = new Set(
|
| 45 |
const primary = props.preferredOrder.filter(a => present.has(a))
|
| 46 |
const extras = [...present].filter(a => !props.preferredOrder.includes(a)).sort()
|
| 47 |
const list = [...primary, ...extras]
|
| 48 |
-
// keep current selection if possible, else default to first
|
| 49 |
if (!list.includes(props.modelValue) && list.length) emit('update:modelValue', list[0])
|
| 50 |
return list
|
| 51 |
})
|
|
|
|
| 1 |
<template>
|
| 2 |
<div class="flex gap-2 flex-wrap">
|
| 3 |
<button
|
| 4 |
+
v-for="code in orderedAssets" :key="code"
|
| 5 |
class="px-3 py-1 rounded-full border flex items-center gap-2"
|
| 6 |
+
:class="code===modelValue ? 'bg-black text-white' : 'bg-white'"
|
| 7 |
+
@click="$emit('update:modelValue', code)"
|
| 8 |
>
|
| 9 |
+
<img :src="iconFor(code)" alt="" class="h-4 w-4 object-contain" @error="hide($event)" />
|
| 10 |
+
<span>{{ code }}</span>
|
| 11 |
</button>
|
| 12 |
</div>
|
| 13 |
</template>
|
|
|
|
| 16 |
import { computed } from 'vue'
|
| 17 |
import { dataService } from '../lib/dataService'
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
const props = defineProps({
|
| 20 |
modelValue: { type: String, default: '' },
|
| 21 |
+
// keep whatever order you want to prefer (others will append)
|
| 22 |
+
preferredOrder: {
|
| 23 |
+
type: Array,
|
| 24 |
+
default: () => ['BTC','ETH','SOL','BNB','DOGE','XRP','AAPL','MSFT','BMRN','MRNA','TSLA']
|
| 25 |
+
}
|
| 26 |
})
|
| 27 |
const emit = defineEmits(['update:modelValue'])
|
| 28 |
|
| 29 |
+
// Same pattern as AssetsFilter.vue
|
| 30 |
+
const iconFor = (assetCode) =>
|
| 31 |
+
new URL(`../assets/images/assets_images/${assetCode}.png`, import.meta.url).href
|
| 32 |
+
const hide = (e) => { e.target.style.display = 'none' }
|
| 33 |
|
| 34 |
+
// Only assets that exist in current data
|
| 35 |
+
const available = computed(() => {
|
| 36 |
const rows = Array.isArray(dataService.tableRows) ? dataService.tableRows : []
|
| 37 |
+
return Array.from(new Set(rows.map(r => r.asset)))
|
| 38 |
})
|
| 39 |
|
| 40 |
+
// Deterministic ordering (without touching AssetsFilter.vue)
|
| 41 |
const orderedAssets = computed(() => {
|
| 42 |
+
const present = new Set(available.value)
|
| 43 |
const primary = props.preferredOrder.filter(a => present.has(a))
|
| 44 |
const extras = [...present].filter(a => !props.preferredOrder.includes(a)).sort()
|
| 45 |
const list = [...primary, ...extras]
|
|
|
|
| 46 |
if (!list.includes(props.modelValue) && list.length) emit('update:modelValue', list[0])
|
| 47 |
return list
|
| 48 |
})
|