explorer-app/components/Project/Create/Categories/Funding.vue

116 lines
2.5 KiB
Vue
Raw Normal View History

2024-09-12 18:03:06 +02:00
<script setup lang="ts">
import type { Project } from '~/types'
const props = defineProps<{
project?: Partial<Project>
}>()
type Fundings = {
name: string
link: string
}
function useFundings(project?: Partial<Project>) {
2024-10-01 13:52:19 +02:00
const fundings = ref(Array.isArray(project?.funding) ? project.funding : (project?.funding ? [project.funding] : []))
2024-09-12 18:03:06 +02:00
const newFunding = reactive<Fundings>({
name: '',
link: '',
})
function addFunding() {
fundings.value.push({ ...newFunding })
newFunding.name = ''
newFunding.link = ''
}
function removeFunding(index: number) {
fundings.value.splice(index, 1)
}
return {
fundings,
newFunding,
addFunding,
removeFunding,
}
}
const { fundings, newFunding, addFunding, removeFunding } = useFundings(props.project)
const { saveProject } = useProject()
function save() {
saveProject({
funding: fundings.value,
})
}
defineExpose({
save,
})
</script>
<template>
<div>
<ProjectCreateComponentsCategoryDivider
w-full
title="FUNDING"
/>
<ProjectCreateComponentsItem
v-for="funding in fundings"
2024-10-01 13:52:19 +02:00
:key="funding?.name"
2024-09-30 14:29:56 +02:00
@remove="() => removeFunding(fundings?.indexOf(funding))"
2024-09-12 18:03:06 +02:00
>
<template #label>
<div
flex
gap-2px
>
<span
class="text-app-black text-14px font-700"
lg="text-16px"
2024-10-01 13:52:19 +02:00
> {{ funding?.name }}
2024-09-12 18:03:06 +02:00
</span>
</div>
</template>
<template #desc>
<NuxtLink
2024-10-01 13:52:19 +02:00
:to="funding?.link"
2024-09-12 18:03:06 +02:00
hover:text-app-black
class="text-app-black/50 text-16px hidden"
lg="block"
>Link
</NuxtLink>
</template>
</ProjectCreateComponentsItem>
<ProjectCreateComponentsItemAdd
button-label="ADD FUNDING"
@add="addFunding()"
>
<template #content>
<div
flex
flex-col
gap-16px
lg="gap-24px"
>
<ProjectCreateComponentsInput
v-model="newFunding.name"
lg="w-50%"
label="Name"
placeholder="Investor's name"
hint="Name of entity investing into project"
/>
<ProjectCreateComponentsInput
v-model="newFunding.link"
lg="w-50%"
label="Link confirming investment"
placeholder="Add URL"
hint="Link to Article, PR or other sources confirming funding information"
/>
</div>
</template>
</ProjectCreateComponentsItemAdd>
</div>
</template>