Skip to content

Commit 850cd7e

Browse files
committed
fix(app): handle item prefix as string
1 parent 18c698d commit 850cd7e

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/app/src/components/shared/item/ItemCardForm.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,21 @@ const schema = computed(() => z.object({
6565
extension: z.enum([...CONTENT_EXTENSIONS, ...MEDIA_EXTENSIONS] as [string, ...string[]]).nullish(),
6666
prefix: z.preprocess(
6767
val => val === '' ? null : val,
68-
z.number().int().positive().nullish(),
68+
z.string()
69+
.regex(/^\d+$/, 'Prefix be a string containing only digits')
70+
.refine(
71+
(prefix: string | null | undefined) => {
72+
if (prefix === null || prefix === undefined) {
73+
return true
74+
}
75+
76+
const num = Number(prefix)
77+
78+
return Number.isInteger(num) && num >= 0
79+
},
80+
'Prefix must be a positive integer',
81+
)
82+
.nullish(),
6983
),
7084
}).refine(() => {
7185
const siblings = props.parentItem.children?.filter(child => !child.hide) || []
@@ -87,7 +101,7 @@ const schema = computed(() => z.object({
87101
type Schema = {
88102
name: string
89103
extension: string | null | undefined
90-
prefix: number | null | undefined
104+
prefix: string | null | undefined
91105
}
92106
const state = reactive<Schema>({
93107
name: originalName.value,
@@ -267,11 +281,11 @@ async function onSubmit() {
267281
<span />
268282
</template>
269283
<UInput
270-
v-model.number="state.prefix"
271-
type="number"
284+
v-model="state.prefix"
285+
type="text"
286+
pattern="[0-9]*"
272287
variant="soft"
273288
placeholder=""
274-
min="1"
275289
class="h-5"
276290
size="xs"
277291
:disabled="isLoading"

src/app/src/types/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface TreeItem {
1515
name: string
1616
fsPath: string // can be used as id
1717
type: 'file' | 'directory' | 'root'
18-
prefix: number | null
18+
prefix: string | null
1919
collections: string[]
2020
status?: TreeStatus
2121
routePath?: string

src/app/src/utils/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ export const FILE_ICONS = {
5050
...AUDIO_EXTENSIONS.reduce((acc, ext) => ({ ...acc, [ext]: 'i-lucide-file-audio' }), {}),
5151
}
5252

53-
export function parseName(name: string): { name: string, prefix: number | null, extension: string | null } {
53+
export function parseName(name: string): { name: string, prefix: string | null, extension: string | null } {
5454
const prefixMatch = name.match(/^(\d+)\./)
5555
const extensionMatch = name.match(/\.(\w+)$/)
5656
return {
57-
prefix: prefixMatch ? Number.parseInt(prefixMatch[1], 10) : null,
57+
prefix: prefixMatch ? prefixMatch[1] : null,
5858
extension: extensionMatch ? extensionMatch[1] : null,
5959
name: name.replace(/^\d+\./, ''),
6060
}

0 commit comments

Comments
 (0)