46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { ref } from 'vue';
|
|
|
|
interface PendingUpload {
|
|
jobId: string;
|
|
type: 'candidate' | 'score' | 'result' | 'period';
|
|
periodId: string;
|
|
}
|
|
|
|
export const useUploadProgressStore = defineStore('uploadProgress', () => {
|
|
const pendingUploads = ref<PendingUpload[]>([]);
|
|
|
|
function addUpload(jobId: string, periodId: string, uploadType: 'candidate' | 'score' | 'result' | 'period') {
|
|
pendingUploads.value.push({
|
|
jobId,
|
|
type: uploadType,
|
|
periodId
|
|
});
|
|
}
|
|
|
|
function removeUpload(jobId: string) {
|
|
const index = pendingUploads.value.findIndex(u => u.jobId === jobId);
|
|
if (index !== -1) {
|
|
pendingUploads.value.splice(index, 1);
|
|
}
|
|
}
|
|
|
|
function removeByPeriodAndType(periodId: string, uploadType: string) {
|
|
const index = pendingUploads.value.findIndex(
|
|
u => u.periodId === periodId && u.type === uploadType
|
|
);
|
|
if (index !== -1) {
|
|
pendingUploads.value.splice(index, 1);
|
|
}
|
|
}
|
|
|
|
function isUploading(periodId: string, uploadType: string): boolean {
|
|
return pendingUploads.value.some(
|
|
u => u.periodId === periodId && u.type === uploadType
|
|
);
|
|
}
|
|
|
|
return { pendingUploads, addUpload, removeUpload, removeByPeriodAndType, isUploading };
|
|
}, {
|
|
persist: true
|
|
});
|