mirror of
https://github.com/KevinMidboe/seasoned.git
synced 2026-03-10 11:29:07 +00:00
Fixes table sort for file size (#86)
* Fixed algorithm to de-humanize size string to bytes * Resolved linting issues
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, inject, defineProps } from "vue";
|
import { ref, watch, inject, defineProps } from "vue";
|
||||||
import { useStore } from "vuex";
|
import { useStore } from "vuex";
|
||||||
import Loader from "@/components/ui/Loader.vue";
|
import Loader from "@/components/ui/Loader.vue";
|
||||||
import TorrentTable from "@/components/torrent/TorrentTable.vue";
|
import TorrentTable from "@/components/torrent/TorrentTable.vue";
|
||||||
@@ -96,6 +96,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(props, newValue => newValue?.query?.length && fetchTorrents());
|
||||||
|
|
||||||
fetchTorrents();
|
fetchTorrents();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -131,12 +131,12 @@
|
|||||||
function sortSize() {
|
function sortSize() {
|
||||||
const torrentsCopy = [...torrents.value];
|
const torrentsCopy = [...torrents.value];
|
||||||
if (direction.value) {
|
if (direction.value) {
|
||||||
torrents.value = torrentsCopy.sort(
|
torrents.value = torrentsCopy.sort((a, b) =>
|
||||||
(a, b) => sortableSize(a.size) - sortableSize(b.size)
|
sortableSize(a.size) > sortableSize(b.size) ? 1 : -1
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
torrents.value = torrentsCopy.sort(
|
torrents.value = torrentsCopy.sort((a, b) =>
|
||||||
(a, b) => sortableSize(b.size) - sortableSize(a.size)
|
sortableSize(a.size) < sortableSize(b.size) ? 1 : -1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
export const sortableSize = (string: string): number => {
|
export const sortableSize = (string: string): number => {
|
||||||
const UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
const UNITS = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||||
const [numStr, unit] = string.split(" ");
|
const [numStr, unit] = string.split(" ");
|
||||||
|
|
||||||
if (UNITS.indexOf(unit) === -1) return null;
|
if (UNITS.indexOf(unit) === -1) return null;
|
||||||
|
|
||||||
const exponent = UNITS.indexOf(unit) * 3;
|
const exponent = UNITS.indexOf(unit) * 3 + 4;
|
||||||
return Number(numStr) * exponent ** 10;
|
return Math.floor(Number(numStr) * 10 ** exponent);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parseJwt = (token: string) => {
|
export const parseJwt = (token: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user