Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function anchor() {
position: trackLayout.position
})
}
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
if (trackStore.lastSelectedTrackId) {
trackStore.selectedTracks = [trackStore.lastSelectedTrackId]
}
Expand All @@ -57,7 +57,7 @@ function unanchor() {
for (const id of trackStore.selectedTracks) {
anchorStore.removeAnchor(id)
}
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
if (trackStore.lastSelectedTrackId) {
trackStore.selectedTracks = [trackStore.lastSelectedTrackId]
}
Expand Down
2 changes: 1 addition & 1 deletion src/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
// @ts-nocheck
// biome-ignore lint: disable
// oxlint-disable
Expand Down
2 changes: 1 addition & 1 deletion src/components/AlbumList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const infiniteScrollRef = useTemplateRef<InstanceType<typeof VInfiniteScroll>>('

async function SelectItem(id: string) {
await albumsStore.FetchAlbumTracks(id)
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}

function reset() {
Expand Down
6 changes: 3 additions & 3 deletions src/components/CassetteActionsBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const selectedSortType = computed({

function addCassette() {
cassetteStore.addCassette()
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}

function removeSource(sourceId: string) {
Expand All @@ -27,7 +27,7 @@ function removeSource(sourceId: string) {
removedTracks.forEach(trackId => {
anchorStore.removeAnchor(trackId)
})
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}

const sources = computed(() => {
Expand Down Expand Up @@ -63,7 +63,7 @@ const menuBadgeContent = computed(() => trackStore.unavailableTrackIds.length >
<!-- Remove items -->
<v-select :items="sources" item-value="id" item-title="name" label="Sources" chips multiple density="compact"
variant="outlined" hide-details v-model="projectStore.selectedSources"
@update:modelValue="layoutStore.calculateLayout" :disabled="!projectStore.hasSources">
@update:modelValue="layoutStore.calculateLayoutDebounced" :disabled="!projectStore.hasSources">
<template v-slot:item="{ props: itemProps, item }">
<v-list-item v-bind="itemProps" :title="item.raw.name">
<template v-slot:prepend="{ isSelected, select }">
Expand Down
2 changes: 1 addition & 1 deletion src/components/PlaylistList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const infiniteScrollRef = useTemplateRef<InstanceType<typeof VInfiniteScroll>>('

async function SelectItem(id: string) {
await playlistStore.FetchPlaylistTracks(id)
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}

function reset() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/UnavailableCassetteItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const track = computed(() => tracksStore.GetTrackById(props.trackId))

function makeTrackAvailable() {
tracksStore.MarkTrackAsAvailable(props.trackId)
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/components/UnavailableTracksList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function clearUnavailableTracks() {
for (const trackId of tracksStore.unavailableTrackIds) {
tracksStore.MarkTrackAsAvailable(trackId)
}
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}
</script>

Expand Down
8 changes: 4 additions & 4 deletions src/components/cassette/Cassette.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ const topAlert = computed(() => {
function removeCassette() {
cassetteStore.removeCassette(props.cassetteId)
anchorsStore.removeAnchoresByCassetteId(props.cassetteId)
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}

function addSide() {
if (cassette.value == undefined) return
cassetteStore.updateSidesCount(props.cassetteId, cassette.value.sidesCount + 1)
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}

function removeSide() {
if (cassette.value == undefined) return
if (cassette.value.sidesCount <= 1) return
cassetteStore.updateSidesCount(props.cassetteId, cassette.value.sidesCount - 1)
anchorsStore.removeAnchorsByTapeSide(props.cassetteId, cassette.value.sidesCount)
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}

const capacityMinutes = computed<number>({
Expand All @@ -49,7 +49,7 @@ const capacityMinutes = computed<number>({
set(mins: number) {
if (!cassette.value) return
cassetteStore.updateCapacity(cassette.value.id, mins * 60000)
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/components/cassette/CassetteItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function toggleAnchor(anchored: boolean) {
})
}

layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()

const trackSelected = tracksStore.selectedTracks.includes(props.trackId)
tracksStore.ClearSelectedTracks()
Expand Down
2 changes: 1 addition & 1 deletion src/components/cassette/CassetteSide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function onChanged(event: DragChangeEvent<string>) {
}
}

layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
tracksCache.value = []
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ onMounted(() => {
source: item.source
}))
tracks.forEach((track) => trackStore.AddTrack(track))
layoutStore.calculateLayout()
layoutStore.calculateLayoutDebounced()
})
projectStore.addSource({
type: 'playlist',
Expand Down
6 changes: 3 additions & 3 deletions src/stores/cassette.alert.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const shorterCassetteRule: AlertRule<ShorterCassettePayload> = {
fn: () => {
const layoutStore = useLayoutStore();
cassette.capacityMs = payload!.suggestedCapacityMs;
layoutStore.calculateLayout();
layoutStore.calculateLayoutDebounced();
},
message: `Set capacity to ${payload!.label}`,
}),
Expand Down Expand Up @@ -121,7 +121,7 @@ const expandCassetteRule: AlertRule<ExpandCassettePayload> = {
fn: () => {
const layoutStore = useLayoutStore();
cassette.capacityMs = payload!.suggestedCapacityMs;
layoutStore.calculateLayout();
layoutStore.calculateLayoutDebounced();
},
message: `Expand to ${payload!.label}`,
}),
Expand Down Expand Up @@ -169,7 +169,7 @@ const needsNewCassetteRule: AlertRule<AddCassettePayload> = {
const layoutStore = useLayoutStore();

cassetteStore.addCassette();
layoutStore.calculateLayout();
layoutStore.calculateLayoutDebounced();
},
message: "Add another cassette",
}),
Expand Down
7 changes: 6 additions & 1 deletion src/stores/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTracksStore } from "./tracks";
import { useAnchorsStore } from "./anchor";
import { TapeSide } from "@/sorting/tapeSideLayout";
import { useProjectStore } from "./project";
import { debounce } from "lodash";

export const useLayoutStore = defineStore('layout', {
state: () => ({
Expand Down Expand Up @@ -55,12 +56,13 @@ export const useLayoutStore = defineStore('layout', {
throw new Error(`Unknown sorter type: ${type}`);
}
this.selectedSortType = type;
this.calculateLayout();
this.calculateLayoutDebounced();
},
getAvailableSorters() {
return trackSorterRegistry.list();
},
calculateLayout() {
console.log("Calculating layout...") // --- IGNORE ---
const cassetteStore = useCassettesStore()
const trackStore = useTracksStore()
const anchorsStore = useAnchorsStore()
Expand Down Expand Up @@ -92,6 +94,9 @@ export const useLayoutStore = defineStore('layout', {
this._calculate_ordered_tracks(sides)
this._calculate_track_locations(sides)
},
calculateLayoutDebounced: debounce(function (this: any) {
this.calculateLayout()
}, 2),
_calculate_ordered_tracks(sides: TapeSide[]) {
sides.forEach(side => {
this.orderedTracks.push(...side.toArray())
Expand Down