mirror of
https://github.com/TeamPiped/Piped.git
synced 2026-06-02 12:54:34 +00:00
52 lines
1.4 KiB
Vue
52 lines
1.4 KiB
Vue
<template>
|
|
<label v-t="'actions.sort_by'" for="ddlSortBy" />
|
|
<select
|
|
id="ddlSortBy"
|
|
v-model="selectedSort"
|
|
class="h-8 grow rounded-md bg-gray-300 px-2.5 text-gray-600 dark:bg-dark-400 dark:text-gray-400"
|
|
>
|
|
<option v-for="(value, key) in options" :key="key" v-t="`actions.${key}`" :value="value" />
|
|
</select>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, watch } from "vue";
|
|
|
|
const options = {
|
|
most_recent: "descending",
|
|
least_recent: "ascending",
|
|
channel_name_asc: "channel_ascending",
|
|
channel_name_desc: "channel_descending",
|
|
};
|
|
|
|
const selectedSort = ref("descending");
|
|
|
|
const props = defineProps({
|
|
byKey: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
});
|
|
|
|
const emit = defineEmits(["apply"]);
|
|
|
|
watch(selectedSort, value => {
|
|
switch (value) {
|
|
case "ascending":
|
|
emit("apply", (a, b) => a[props.byKey] - b[props.byKey]);
|
|
break;
|
|
case "descending":
|
|
emit("apply", (a, b) => b[props.byKey] - a[props.byKey]);
|
|
break;
|
|
case "channel_ascending":
|
|
emit("apply", (a, b) => a.uploaderName.localeCompare(b.uploaderName));
|
|
break;
|
|
case "channel_descending":
|
|
emit("apply", (a, b) => b.uploaderName.localeCompare(a.uploaderName));
|
|
break;
|
|
default:
|
|
console.error("Unexpected sort value");
|
|
}
|
|
});
|
|
</script>
|