feat: add title extraction
This commit is contained in:
@@ -5,11 +5,12 @@ import TaskForm from './TaskForm.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
initialSteps?: Stepable[]
|
||||
initialTitle?: string
|
||||
}>()
|
||||
|
||||
const id = createUuid()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<task-form :id="id" :initial-steps="props.initialSteps" />
|
||||
<task-form :id="id" :initial-steps="props.initialSteps" :initial-title="props.initialTitle" />
|
||||
</template>
|
||||
|
||||
@@ -15,6 +15,7 @@ const props = defineProps<{
|
||||
id: string
|
||||
initialTask?: Taskable
|
||||
initialSteps?: Stepable[]
|
||||
initialTitle?: string
|
||||
}>()
|
||||
const id = computed(() => props.id)
|
||||
const hasTasks = computed(() => store.tasks.length > 0)
|
||||
@@ -29,7 +30,7 @@ const steps = ref<Stepable[]>(
|
||||
: exampleSteps
|
||||
)
|
||||
|
||||
const title = ref(props.initialTask?.title ?? '')
|
||||
const title = ref(props.initialTitle ?? props.initialTask?.title ?? '')
|
||||
const link = ref(props.initialTask?.link ?? '')
|
||||
|
||||
const totalEstimation = computed(() =>
|
||||
|
||||
@@ -16,20 +16,34 @@ const resetTasks = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const extractTitleFromPaste = (
|
||||
text: string
|
||||
): { title: string | null; content: string } => {
|
||||
const match = text.match(/^(#{1,6})\s+(.+?)\n+([\s\S]*)$/)
|
||||
if (match) {
|
||||
return { title: match[2].trim(), content: match[3] }
|
||||
}
|
||||
return { title: null, content: text }
|
||||
}
|
||||
|
||||
const handlePaste = (event: ClipboardEvent) => {
|
||||
const clipboardText = event.clipboardData?.getData('text')
|
||||
if (!clipboardText) {
|
||||
return
|
||||
}
|
||||
|
||||
const steps = adaptTextareaToSteps(clipboardText)
|
||||
const { title, content } = extractTitleFromPaste(clipboardText)
|
||||
const steps = adaptTextareaToSteps(content)
|
||||
if (steps.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
router.push({
|
||||
name: 'new-task',
|
||||
state: { initialSteps: JSON.stringify(steps) }
|
||||
state: {
|
||||
initialTitle: title,
|
||||
initialSteps: JSON.stringify(steps)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@ const rawInitialSteps = history.state?.initialSteps as string | undefined
|
||||
const initialSteps = rawInitialSteps
|
||||
? (JSON.parse(rawInitialSteps) as Stepable[])
|
||||
: undefined
|
||||
const initialTitle = history.state?.initialTitle as string | undefined
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="new-task">
|
||||
<NewTaskForm :initial-steps="initialSteps" />
|
||||
<NewTaskForm :initial-steps="initialSteps" :initial-title="initialTitle" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user