This commit is contained in:
Misode
2024-05-10 23:15:41 +02:00
parent bf36ecd3e0
commit 44b97e357f
8 changed files with 57 additions and 43 deletions

View File

@@ -2,12 +2,12 @@ import type { DataModel } from '@mcschema/core'
import { useCallback, useMemo, useRef, useState } from 'preact/hooks'
import { Analytics } from '../../Analytics.js'
import config from '../../Config.js'
import { Store } from '../../Store.js'
import { writeZip } from '../../Utils.js'
import { DRAFT_PROJECT, disectFilePath, getFilePath, useLocale, useProject, useVersion } from '../../contexts/index.js'
import { disectFilePath, DRAFT_PROJECT, getFilePath, useLocale, useProject, useVersion } from '../../contexts/index.js'
import { useFocus } from '../../hooks/useFocus.js'
import type { VersionId } from '../../services/index.js'
import { stringifySource } from '../../services/index.js'
import { Store } from '../../Store.js'
import { writeZip } from '../../Utils.js'
import { Btn } from '../Btn.js'
import { BtnMenu } from '../BtnMenu.js'
import { Octicon } from '../Octicon.jsx'
@@ -44,20 +44,20 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
id: id.replaceAll('\u2215', '/'),
}
}
return disectFilePath(entry)
}, [treeViewMode])
return disectFilePath(entry, version)
}, [treeViewMode, version])
const entries = useMemo(() => project.files.flatMap(f => {
const path = getFilePath(f)
const path = getFilePath(f, version)
if (!path) return []
if (f.type === 'pack_mcmeta') return 'pack.mcmeta'
if (treeViewMode === 'resources') {
return [`${f.type.replaceAll('/', '\u2215')}/${f.id.replaceAll('/', '\u2215')}`]
}
return [path]
}), [treeViewMode, ...project.files])
}), [treeViewMode, version, ...project.files])
const selected = useMemo(() => file && getFilePath(file), [file])
const selected = useMemo(() => file && getFilePath(file, version), [file, version])
const selectFile = useCallback((entry: string) => {
const file = disectEntry(entry)
@@ -72,7 +72,7 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
if (!download.current) return
let hasPack = false
const entries = project.files.flatMap(file => {
const path = getFilePath(file)
const path = getFilePath(file, version)
if (path === undefined) return []
if (path === 'pack.mcmeta') hasPack = true
return [[path, stringifySource(file.data)]] as [string, string][]
@@ -126,7 +126,7 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
}
const file = disectEntry(entry)
return <div class={`entry ${file && getFilePath(file) === selected ? 'active' : ''} ${focused ? 'focused' : ''}`} onClick={() => selectFile(entry)} onContextMenu={onContextMenu} >
return <div class={`entry ${file && getFilePath(file, version) === selected ? 'active' : ''} ${focused ? 'focused' : ''}`} onClick={() => selectFile(entry)} onContextMenu={onContextMenu} >
{Octicon.file}
<span>{entry.split('/').at(-1)}</span>
{focused && <div class="entry-menu">