mirror of
https://github.com/modrinth/code.git
synced 2026-09-03 13:36:48 +00:00
fix: guard preload content
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { Archon } from '@modrinth/api-client'
|
||||
import { ChevronRightIcon } from '@modrinth/assets'
|
||||
import { useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
import { computed, nextTick, ref } from 'vue'
|
||||
|
||||
import type { TabbedModalTab } from '#ui/components'
|
||||
@@ -57,16 +57,6 @@ const currentUserRole = ref<string | null>(null)
|
||||
|
||||
const isApp = ref(true)
|
||||
|
||||
// Preload
|
||||
useQuery({
|
||||
queryKey: computed(() => ['content', 'list', 'v1', currentServerId]),
|
||||
queryFn: () =>
|
||||
client.archon.content_v1.getAddons(currentServerId, worldId.value!, {
|
||||
from_modpack: false,
|
||||
}),
|
||||
enabled: computed(() => !!worldId.value),
|
||||
})
|
||||
|
||||
const serverSettingsTabComponentMap = {
|
||||
general: ServerSettingsGeneralPage,
|
||||
network: ServerSettingsNetworkPage,
|
||||
|
||||
@@ -119,9 +119,8 @@ import { injectNotificationManager } from '#ui/providers/web-notifications'
|
||||
import { getFileExtensionIcon } from '#ui/utils/auto-icons'
|
||||
import { commonMessages } from '#ui/utils/common-messages'
|
||||
import {
|
||||
canOpenInFileEditor,
|
||||
getFileExtension,
|
||||
isEditableFile as isEditableFileExt,
|
||||
isImageFile,
|
||||
} from '#ui/utils/file-extensions'
|
||||
|
||||
import {
|
||||
@@ -303,8 +302,7 @@ const formattedCreationDate = computed(() => {
|
||||
|
||||
const isEditableFile = computed(() => {
|
||||
if (props.type === 'file') {
|
||||
const ext = fileExtension.value
|
||||
return !props.name.includes('.') || isEditableFileExt(ext) || isImageFile(ext)
|
||||
return canOpenInFileEditor(props.name)
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
@@ -226,7 +226,7 @@ import { useVirtualScroll } from '#ui/composables/virtual-scroll'
|
||||
import { injectFilePicker } from '#ui/providers/file-picker'
|
||||
import { injectNotificationManager } from '#ui/providers/web-notifications'
|
||||
import { commonMessages } from '#ui/utils/common-messages'
|
||||
import { getFileExtension } from '#ui/utils/file-extensions'
|
||||
import { canOpenInFileEditor, getFileExtension } from '#ui/utils/file-extensions'
|
||||
|
||||
import FileEditor from './components/editor/FileEditor.vue'
|
||||
import FileContextMenu from './components/FileContextMenu.vue'
|
||||
@@ -655,7 +655,9 @@ function handleItemHover(item: { type: string; path: string; name: string }) {
|
||||
}, 150)
|
||||
} else {
|
||||
prefetchTimeout = setTimeout(() => {
|
||||
ctx.prefetchFile?.(item.path)
|
||||
if (canOpenInFileEditor(item.name)) {
|
||||
ctx.prefetchFile?.(item.path)
|
||||
}
|
||||
}, 150)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
injectNotificationManager,
|
||||
} from '#ui/providers'
|
||||
import { commonMessages } from '#ui/utils/common-messages'
|
||||
import { canOpenInFileEditor } from '#ui/utils/file-extensions'
|
||||
|
||||
const props = defineProps<{
|
||||
showDebugInfo?: boolean
|
||||
@@ -199,6 +200,7 @@ function prefetchDirectory(path: string) {
|
||||
function prefetchFile(path: string) {
|
||||
const id = worldId.value
|
||||
if (!id) return
|
||||
if (!canOpenInFileEditor(path.split('/').pop() ?? path)) return
|
||||
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ['file-content', id, path],
|
||||
|
||||
@@ -89,6 +89,14 @@ export function isEditableFile(ext: string): boolean {
|
||||
return isCodeFile(ext) || isTextFile(ext)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file can be opened in the file editor.
|
||||
*/
|
||||
export function canOpenInFileEditor(filename: string): boolean {
|
||||
const extension = getFileExtension(filename)
|
||||
return !filename.includes('.') || isEditableFile(extension) || isImageFile(extension)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ace editor language mode for a file extension
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user