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