mirror of
https://github.com/modrinth/code.git
synced 2026-07-31 13:16:38 +00:00
* feat: card alignment + fix modals * feat: change admon title in restore alert modal * fix: lint * feat: backups queue api into api-client * feat: impl backup queue api endpoints into frontend * feat: ack fix * feat: bulk actions * feat: bulk delete impl * fix: lint * fix: align error states * fix: transition group * feat: ready for qa * fix: lint * feat: qa * feat: stacked admonitions component * fix: issues with stacking * feat: hook up admonition stacking + fix app csp for staging kyros nodes * fix: logs.vue * qa: close stack on admonitions click * fix: all problems with stacked admonitions * qa: admonition cleanup and copy overhaul draft * fix: qa issues padding * fix: padding bug * feat: qa * fix: intercom in app csp bug * fix: positioning intercom * feat: loading overlay on top of console + admon consistency changes * feat: scroll indicator fade in backup delete modal + admon timestamp fix * feat: move action bar behind modal * fix: lint + i18n * fix: server ping spam on filter (cache but clear on unmount) * fix: 1 admon fade in flicker issue * chore: temp staging undo * qa: changes * fix: lint * chore: revert staging to use staging * fix: scoping
75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
import type { Archon } from '@modrinth/api-client'
|
|
import type { ComputedRef, Ref } from 'vue'
|
|
import { computed, ref, watch } from 'vue'
|
|
|
|
type BackupQueueBackup = Archon.BackupsQueue.v1.BackupQueueBackup
|
|
|
|
export function useBackupsSelection(
|
|
visibleBackups: Ref<BackupQueueBackup[]>,
|
|
displayOrderedBackups: ComputedRef<BackupQueueBackup[]>,
|
|
) {
|
|
const selectedIds = ref<Set<string>>(new Set())
|
|
|
|
watch(visibleBackups, () => {
|
|
const ids = new Set(visibleBackups.value.map((b) => b.id))
|
|
const next = new Set<string>()
|
|
for (const id of selectedIds.value) {
|
|
if (ids.has(id)) next.add(id)
|
|
}
|
|
if (next.size !== selectedIds.value.size) {
|
|
selectedIds.value = next
|
|
}
|
|
})
|
|
|
|
function toggleSelection(id: string) {
|
|
const next = new Set(selectedIds.value)
|
|
if (next.has(id)) next.delete(id)
|
|
else next.add(id)
|
|
selectedIds.value = next
|
|
}
|
|
|
|
function selectAll() {
|
|
selectedIds.value = new Set(visibleBackups.value.map((b) => b.id))
|
|
}
|
|
|
|
function deselectAll() {
|
|
selectedIds.value = new Set()
|
|
}
|
|
|
|
function toggleSelectAll() {
|
|
if (allSelected.value) deselectAll()
|
|
else selectAll()
|
|
}
|
|
|
|
const allSelected = computed(
|
|
() =>
|
|
visibleBackups.value.length > 0 &&
|
|
visibleBackups.value.every((b) => selectedIds.value.has(b.id)),
|
|
)
|
|
|
|
const someSelected = computed(() => {
|
|
const vis = visibleBackups.value
|
|
if (vis.length === 0) return false
|
|
let n = 0
|
|
for (const b of vis) {
|
|
if (selectedIds.value.has(b.id)) n++
|
|
}
|
|
return n > 0 && n < vis.length
|
|
})
|
|
|
|
const selectedBackups = computed(() =>
|
|
displayOrderedBackups.value.filter((b) => selectedIds.value.has(b.id)),
|
|
)
|
|
|
|
return {
|
|
selectedIds,
|
|
toggleSelection,
|
|
selectAll,
|
|
deselectAll,
|
|
toggleSelectAll,
|
|
allSelected,
|
|
someSelected,
|
|
selectedBackups,
|
|
}
|
|
}
|