Enhance reactivity and null safety in file state management with computed properties and conditional checks

This commit is contained in:
2026-01-29 04:27:51 +00:00
parent 6c5ed223c6
commit 835168179e

View File

@@ -43,30 +43,39 @@ const props = defineProps({
}
});
const internalFilesState = useGamemasterFiles(props.client);
const internalFilesState = props.client ? useGamemasterFiles(props.client) : null;
const activeFilesState = computed(() => props.filesState || internalFilesState);
const selectedFile = computed(() => activeFilesState.value.selectedFile);
const fileContent = computed(() => activeFilesState.value.fileContent);
const fileLines = computed(() => activeFilesState.value.fileLines);
const uniqueFiles = computed(() => activeFilesState.value.uniqueFiles);
const isLoading = computed(() => activeFilesState.value.isLoading);
const fileError = computed(() => activeFilesState.value.fileError);
const selectedFile = computed({
get: () => activeFilesState.value?.selectedFile?.value,
set: (val) => {
if (activeFilesState.value?.selectedFile) {
activeFilesState.value.selectedFile.value = val;
}
}
});
const fileContent = computed(() => activeFilesState.value?.fileContent?.value);
const fileLines = computed(() => activeFilesState.value?.fileLines?.value || []);
const uniqueFiles = computed(() => activeFilesState.value?.uniqueFiles?.value || []);
const isLoading = computed(() => activeFilesState.value?.isLoading?.value || false);
const fileError = computed(() => activeFilesState.value?.fileError?.value);
const formatSize = (...args) => activeFilesState.value.formatSize(...args);
const formatSize = (...args) => activeFilesState.value?.formatSize?.(...args);
const formatFileName = (...args) =>
activeFilesState.value.formatFileName(...args);
const getFileType = (...args) => activeFilesState.value.getFileType(...args);
activeFilesState.value?.formatFileName?.(...args);
const getFileType = (...args) => activeFilesState.value?.getFileType?.(...args);
const selectedFileMeta = computed(() => {
if (!selectedFile.value.value) return null;
return uniqueFiles.value.value.find(
file => getFileType(file.filename) === selectedFile.value.value
if (!selectedFile.value) return null;
return uniqueFiles.value.find(
file => getFileType(file.filename) === selectedFile.value
);
});
onMounted(() => {
if (activeFilesState.value?.loadStatus) {
activeFilesState.value.loadStatus();
}
});
</script>