sort
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { formatIsk, percentFormater } from '@/formaters';
|
||||
import { SortableHeader, useSort } from '@/table';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { computed } from 'vue';
|
||||
import BuySellSlider from './BuySellSlider.vue';
|
||||
@@ -16,12 +17,15 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
const threshold = useStorage('reprocess-threshold', 0);
|
||||
const useSellOrder = useStorage('reprocess-use-sell-order', false);
|
||||
|
||||
const computedResult = computed(() => {
|
||||
const { sortedArray, headerProps } = useSort(computed(() => {
|
||||
return props.result.map(r =>({
|
||||
...r,
|
||||
buy_ratio: r.buy === 0 ? 1 : (r.buy_reprocess / r.buy) - 1,
|
||||
sell_ratio: r.sell === 0 ? 1 : (r.sell_reprocess / r.sell) - 1
|
||||
})).sort((a, b) => a.name.localeCompare(b.name))
|
||||
}))
|
||||
}), {
|
||||
defaultSortKey: 'name',
|
||||
defaultSortDirection: 'asc'
|
||||
})
|
||||
|
||||
const copyToClipboard = (s: string) => navigator.clipboard.writeText(s);
|
||||
@@ -40,14 +44,14 @@ const copyToClipboard = (s: string) => navigator.clipboard.writeText(s);
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Item</th>
|
||||
<th>Market</th>
|
||||
<th>Reprocess</th>
|
||||
<th>Percent</th>
|
||||
<SortableHeader v-bind="headerProps" sortKey="name">Item</SortableHeader>
|
||||
<SortableHeader v-bind="headerProps" :sortKey="useSellOrder ? 'sell' : 'buy'">Market</SortableHeader>
|
||||
<SortableHeader v-bind="headerProps" :sortKey="useSellOrder ? 'sell_reprocess' : 'buy_reprocess'">Reprocess</SortableHeader>
|
||||
<SortableHeader v-bind="headerProps" :sortKey="useSellOrder ? 'sell_ratio' : 'buy_ratio'">Percent</SortableHeader>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="r in computedResult" :key="r.typeID" class="cursor-pointer" :class="{'bg-emerald-500': (useSellOrder ? r.sell_ratio : r.buy_ratio) >= threshold / 100 }" @click="copyToClipboard(r.name)">
|
||||
<tr v-for="r in sortedArray" :key="r.typeID" class="cursor-pointer" :class="{'bg-emerald-500': (useSellOrder ? r.sell_ratio : r.buy_ratio) >= threshold / 100 }" @click="copyToClipboard(r.name)">
|
||||
<td>{{ r.name }}</td>
|
||||
<td class="text-right">{{ formatIsk(useSellOrder ? r.sell : r.buy) }}</td>
|
||||
<td class="text-right">{{ formatIsk(useSellOrder ? r.sell_reprocess : r.buy_reprocess) }}</td>
|
||||
|
||||
Reference in New Issue
Block a user