diff --git a/components/Project/Create/Categories/Assets.vue b/components/Project/Create/Categories/Assets.vue index 54b5379..230d26e 100644 --- a/components/Project/Create/Categories/Assets.vue +++ b/components/Project/Create/Categories/Assets.vue @@ -44,7 +44,7 @@ function useTokens(project?: Partial) { const { tokens, newToken, addToken, removeToken } = useTokens(props.project) const assetsUsed = ref(Array.isArray(props.project?.assets_used) ? props.project?.assets_used.map(a => a.toLowerCase()) : []) -const { useProject, assetsData } = useData() +const { assetsData } = useData() const { saveProject } = useProject() function save() { diff --git a/components/Project/Create/Categories/BasicInfo.vue b/components/Project/Create/Categories/BasicInfo.vue index 8702104..2ea3d8c 100644 --- a/components/Project/Create/Categories/BasicInfo.vue +++ b/components/Project/Create/Categories/BasicInfo.vue @@ -6,7 +6,7 @@ const props = defineProps<{ project?: Partial }>() -const { useProject, categoriesData, usecasesData, ecosystemsData } = useData() +const { categoriesData, usecasesData, ecosystemsData } = useData() const { saveProject } = useProject() const validationSchema = yup.object().shape({ @@ -31,8 +31,8 @@ const isDead = ref(props.project?.sunset || false) resetForm({ values: { - categories: props.project?.categories?.map(c => c.toLowerCase()) || [], - usecases: props.project?.usecases?.map(u => u.toLowerCase()) || [], + categories: Array.isArray(props.project?.categories) ? props.project?.categories?.map(c => c.toLowerCase()) : [], + usecases: Array.isArray(props.project?.usecases) ? props.project?.usecases?.map(u => u.toLowerCase()) : [], ecosystems: Array.isArray(props.project?.ecosystem) ? props.project?.ecosystem?.map(e => e.toLowerCase()) : [], description: props.project?.description || '', }, @@ -55,7 +55,7 @@ function save() { usecases: usecases.value, ecosystem: ecosystems.value, description: description.value, - product_launch_day: new Date(year.value, month.value, day.value).toISOString(), + product_launch_day: (year.value && month.value && day.value) ? new Date(year.value, month.value, day.value).toISOString() : undefined, sunset: isDead.value, }) } diff --git a/components/Project/Create/Categories/Funding.vue b/components/Project/Create/Categories/Funding.vue index 767fe14..fecbbfb 100644 --- a/components/Project/Create/Categories/Funding.vue +++ b/components/Project/Create/Categories/Funding.vue @@ -37,7 +37,6 @@ function useFundings(project?: Partial) { const { fundings, newFunding, addFunding, removeFunding } = useFundings(props.project) -const { useProject } = useData() const { saveProject } = useProject() function save() { diff --git a/components/Project/Create/Categories/History.vue b/components/Project/Create/Categories/History.vue index 39468c5..41e1280 100644 --- a/components/Project/Create/Categories/History.vue +++ b/components/Project/Create/Categories/History.vue @@ -72,7 +72,6 @@ function formatDate(date: string) { return `${day}/${month}/${year}` } -const { useProject } = useData() const { saveProject } = useProject() function save() { diff --git a/components/Project/Create/Categories/Links.vue b/components/Project/Create/Categories/Links.vue index ab92538..f07b252 100644 --- a/components/Project/Create/Categories/Links.vue +++ b/components/Project/Create/Categories/Links.vue @@ -19,7 +19,6 @@ const telegram = ref(props.project?.links?.telegram || '') const lens = ref(props.project?.links?.lens || '') const farcaster = ref(props.project?.links?.farcaster || '') -const { useProject } = useData() const { saveProject } = useProject() function save() { diff --git a/components/Project/Create/Categories/Privacy.vue b/components/Project/Create/Categories/Privacy.vue index caaf771..b5f841c 100644 --- a/components/Project/Create/Categories/Privacy.vue +++ b/components/Project/Create/Categories/Privacy.vue @@ -13,7 +13,7 @@ const signRequirements = ref(Array.isArray(props.project?.tracebility?.sign_in_t const trackedData = ref(props.project?.tracebility?.tracked_data || '') const dataUsage = ref(props.project?.privacy_policy?.data_usage || '') -const { useProject, signInRequirmentsData } = useData() +const { signInRequirmentsData } = useData() const { saveProject } = useProject() function save() { diff --git a/components/Project/Create/Categories/Security.vue b/components/Project/Create/Categories/Security.vue index 5dcc74b..ff573ca 100644 --- a/components/Project/Create/Categories/Security.vue +++ b/components/Project/Create/Categories/Security.vue @@ -73,7 +73,6 @@ const thirdPartyDep = ref(props.project?.third_party_dependency || '') const socialTrust = ref(props.project?.social_trust || '') const spof = ref(props.project?.technical_spof || '') -const { useProject } = useData() const { saveProject } = useProject() function save() { diff --git a/components/Project/Create/Categories/Team.vue b/components/Project/Create/Categories/Team.vue index 593739e..ba3f51d 100644 --- a/components/Project/Create/Categories/Team.vue +++ b/components/Project/Create/Categories/Team.vue @@ -39,7 +39,6 @@ function useMembers(project?: Partial) { const { members, newMember, addMember, removeMember } = useMembers(props.project) -const { useProject } = useData() const { saveProject } = useProject() function save() { diff --git a/components/Project/Create/Categories/Technology.vue b/components/Project/Create/Categories/Technology.vue index 5956d1a..3595ff2 100644 --- a/components/Project/Create/Categories/Technology.vue +++ b/components/Project/Create/Categories/Technology.vue @@ -13,7 +13,7 @@ const encryption = ref(props.project?.blockchain_features?.encryption || '') const peerToPeer = ref(props.project?.blockchain_features?.p2p) const decentralizedStorage = ref(props.project?.storage?.decentralized) -const { useProject, projectPhaseData, assetCustodyData } = useData() +const { projectPhaseData, assetCustodyData } = useData() const { saveProject } = useProject() function save() { diff --git a/composables/useData.ts b/composables/useData.ts index 10250c6..6fbef88 100644 --- a/composables/useData.ts +++ b/composables/useData.ts @@ -1,4 +1,3 @@ -import { Buffer } from 'buffer' import type { Category, Project, ProjectShallow } from '~/types' export const useData = defineStore('data', () => { @@ -146,73 +145,6 @@ export const useData = defineStore('data', () => { const filteredProjectsCount = computed(() => filteredProjects.value.length) - function useProject() { - const project = ref>() - const projectImage = ref() - const isPublishing = ref(false) - - function setProject(id: string) { - project.value = getProjectById(id, { shallow: false }) as Project - } - - function clearProject() { - project.value = undefined - } - - function saveProject(data: Partial) { - project.value = { - ...project.value, - ...data, - } - } - - function saveProjectImage(image: File) { - projectImage.value = image - } - - async function publishProject() { - isPublishing.value = true - try { - const imageArrayBuffer = await projectImage.value?.arrayBuffer() - let imageBuffer: Buffer | undefined - let base64Image: string | undefined - - if (imageArrayBuffer) { - imageBuffer = Buffer.from(imageArrayBuffer) - const base64String = imageBuffer.toString('base64') - base64Image = base64String - } - - await $fetch(`/api/data`, { - method: 'POST', - body: { - project: project.value, - image: { - type: projectImage.value?.type, - data: base64Image, - }, - }, - }) - } - catch (e) { - console.error(e) - } - finally { - isPublishing.value = false - } - } - - return { - project, - isPublishing, - setProject, - clearProject, - saveProject, - saveProjectImage, - publishProject, - } - } - return { selectedCategoryId, filter, @@ -234,6 +166,5 @@ export const useData = defineStore('data', () => { getProjectsByCategory, filteredProjects, projectToShallow, - useProject, } }) diff --git a/composables/useProject.ts b/composables/useProject.ts new file mode 100644 index 0000000..2b55d47 --- /dev/null +++ b/composables/useProject.ts @@ -0,0 +1,71 @@ +import { Buffer } from 'buffer' +import type { Project } from '~/types' + +export const useProject = defineStore('project', () => { + const project = ref>() + const projectImage = ref() + const isPublishing = ref(false) + + const { getProjectById } = useData() + + function setProject(id: string) { + project.value = getProjectById(id, { shallow: false }) as Project + } + + function clearProject() { + project.value = undefined + } + + function saveProject(data: Partial) { + project.value = { + ...project.value, + ...data, + } + } + + function saveProjectImage(image: File) { + projectImage.value = image + } + + async function publishProject() { + isPublishing.value = true + try { + const imageArrayBuffer = await projectImage.value?.arrayBuffer() + let imageBuffer: Buffer | undefined + let base64Image: string | undefined + + if (imageArrayBuffer) { + imageBuffer = Buffer.from(imageArrayBuffer) + const base64String = imageBuffer.toString('base64') + base64Image = base64String + } + + await $fetch(`/api/data`, { + method: 'POST', + body: { + project: project.value, + image: { + type: projectImage.value?.type, + data: base64Image, + }, + }, + }) + } + catch (e) { + console.error(e) + } + finally { + isPublishing.value = false + } + } + + return { + project, + isPublishing, + setProject, + clearProject, + saveProject, + saveProjectImage, + publishProject, + } +}) diff --git a/pages/project/[id]/edit.vue b/pages/project/[id]/edit.vue index e500895..2043a4d 100644 --- a/pages/project/[id]/edit.vue +++ b/pages/project/[id]/edit.vue @@ -1,4 +1,5 @@