✨ Enhance reactivity and null safety in file state management with computed properties and conditional checks
This commit is contained in:
@@ -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 activeFilesState = computed(() => props.filesState || internalFilesState);
|
||||||
|
|
||||||
const selectedFile = computed(() => activeFilesState.value.selectedFile);
|
const selectedFile = computed({
|
||||||
const fileContent = computed(() => activeFilesState.value.fileContent);
|
get: () => activeFilesState.value?.selectedFile?.value,
|
||||||
const fileLines = computed(() => activeFilesState.value.fileLines);
|
set: (val) => {
|
||||||
const uniqueFiles = computed(() => activeFilesState.value.uniqueFiles);
|
if (activeFilesState.value?.selectedFile) {
|
||||||
const isLoading = computed(() => activeFilesState.value.isLoading);
|
activeFilesState.value.selectedFile.value = val;
|
||||||
const fileError = computed(() => activeFilesState.value.fileError);
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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) =>
|
const formatFileName = (...args) =>
|
||||||
activeFilesState.value.formatFileName(...args);
|
activeFilesState.value?.formatFileName?.(...args);
|
||||||
const getFileType = (...args) => activeFilesState.value.getFileType(...args);
|
const getFileType = (...args) => activeFilesState.value?.getFileType?.(...args);
|
||||||
|
|
||||||
const selectedFileMeta = computed(() => {
|
const selectedFileMeta = computed(() => {
|
||||||
if (!selectedFile.value.value) return null;
|
if (!selectedFile.value) return null;
|
||||||
return uniqueFiles.value.value.find(
|
return uniqueFiles.value.find(
|
||||||
file => getFileType(file.filename) === selectedFile.value.value
|
file => getFileType(file.filename) === selectedFile.value
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
if (activeFilesState.value?.loadStatus) {
|
||||||
activeFilesState.value.loadStatus();
|
activeFilesState.value.loadStatus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user