fix: account for null values

This commit is contained in:
0xdevant 2024-07-22 15:36:53 +08:00
parent e424df1139
commit 950b4164a0
No known key found for this signature in database
GPG key ID: 3B0072B3F5B415CB

View file

@ -13,7 +13,6 @@ const availableSupport = computed(() => {
return 0 return 0
}) })
/** /**
* From data points * From data points
- product readiness - product readiness
@ -22,52 +21,53 @@ const availableSupport = computed(() => {
- team: anon / public - team: anon / public
- audit: yes / no - audit: yes / no
*/ */
const calculateScore = computed(() => { const calculateScore: number = computed(() => {
const criterias: { value: string, key?: string }[] = [ const criterias: { value: string; key?: string }[] = [
{ value: 'product_readiness' }, { value: 'product_readiness' },
{ value: "github", key: 'links' }, { value: 'github', key: 'links' },
{ value: "docs", key: 'links' }, { value: 'docs', key: 'links' },
{ value: 'team' }, { value: 'team' },
{ value: 'audits' } { value: 'audits' },
]; ]
let matched = 0; let matched = 0
for (let i = 0; i < criterias.length; i++) { for (let i = 0; i < criterias.length; i++) {
let value; let value
if (criterias[i].key) { if (criterias[i].key) {
if(props.project[criterias[i].key] === null || props.project[criterias[i].key] === undefined) continue; if (props.project[criterias[i].key] === null || props.project[criterias[i].key] === undefined)
value = props.project[criterias[i].key][criterias[i].value]; continue
// console.log(props.project[criterias[i].key] == null); value = props.project[criterias[i].key][criterias[i].value]
} else { }
value = props.project[criterias[i].value]; else {
if (props.project[criterias[i].value] === null || props.project[criterias[i].value] === undefined)
continue
value = props.project[criterias[i].value]
} }
// console.log(value); // console.log(value);
// console.log(Object.keys(props.project["team"]).length);
if (fulfilled(value)) { if (fulfilled(value))
matched++; matched++
// console.log('matched', matched); // console.log('matched', matched);
}
} }
return 100 / criterias.length * matched; return 100 / criterias.length * matched
}) })
function fulfilled(value: any): boolean { function fulfilled(value: any): boolean {
const type = typeof value; const type = typeof value
switch (type) { switch (type) {
case 'string': case 'string':
if (value !== '') return true; if (value !== '')
break; return true
case 'array': break
if (value.length > 0) return true;
break;
case 'object': case 'object':
if (Object.keys(value).length > 0) return true; if (Object.keys(value).length > 0)
break; return true
break
default: default:
return false; return false
break;
} }
} }
@ -76,13 +76,17 @@ const logo = props.project?.logos?.at(0)?.url
<template> <template>
<div lg:flex lg:gap-32px> <div lg:flex lg:gap-32px>
<NuxtImg lg:max-w-320px lg:max-h-320px shrink :src="logo ?? '/no-image-1-1.svg'" <NuxtImg
class="bg-app-bg-grey object-cover max-w-full h-full vertical-align[middle] block border-0 w-full h-[300px]" /> lg:max-w-320px lg:max-h-320px shrink :src="logo ?? '/no-image-1-1.svg'"
class="bg-app-bg-grey object-cover max-w-full h-full vertical-align[middle] block border-0 w-full h-[300px]"
/>
<div grow> <div grow>
<div flex flex-col justify-between gap-32px lg:flex-row lg:items-center> <div flex flex-col justify-between gap-32px lg:flex-row lg:items-center>
<div mt-24px> <div mt-24px>
<NuxtLink :to="project.links?.web" target="_blank" flex items-center gap-12px hover:underline <NuxtLink
underline-offset-3> :to="project.links?.web" target="_blank" flex items-center gap-12px hover:underline
underline-offset-3
>
<h1 text="24px sm:32px app-white" leading-32px font-700> <h1 text="24px sm:32px app-white" leading-32px font-700>
{{ project.name }} {{ project.name }}
</h1> </h1>
@ -92,8 +96,10 @@ const logo = props.project?.logos?.at(0)?.url
{{ project.project_type ?? '---' }} {{ project.project_type ?? '---' }}
</h2> </h2>
</div> </div>
<div border-2px class="border-app-black bg-app-white text-app-black" flex items-center justify-center px-32px <div
py-16px text-32px font-700 leading-40px cursor-pointer> border-2px class="border-app-black bg-app-white text-app-black" flex items-center justify-center px-32px
py-16px text-32px font-700 leading-40px cursor-pointer
>
{{ calculateScore }} {{ calculateScore }}
</div> </div>
</div> </div>
@ -104,8 +110,10 @@ const logo = props.project?.logos?.at(0)?.url
</template> </template>
{{ project.links?.github ? 'YES' : 'NO' }} {{ project.links?.github ? 'YES' : 'NO' }}
</ProjectInfoItem> </ProjectInfoItem>
<ProjectInfoItem :check-undefined="project.project_status?.version" title="Product readyness" bold <ProjectInfoItem
text-size="18px"> :check-undefined="project.project_status?.version" title="Product readyness" bold
text-size="18px"
>
<template #prefix> <template #prefix>
<UnoIcon i-web-cube /> <UnoIcon i-web-cube />
</template> </template>
@ -137,8 +145,10 @@ const logo = props.project?.logos?.at(0)?.url
</ProjectInfoItem> </ProjectInfoItem>
</div> </div>
<div grid grid-cols-2 gap-16px my-32px lg:grid-cols-4> <div grid grid-cols-2 gap-16px my-32px lg:grid-cols-4>
<ProjectInfoItem :check-undefined="project.blockchain_features?.network" tooltip-link="/" title="Ecosystem" <ProjectInfoItem
bold> :check-undefined="project.blockchain_features?.network" tooltip-link="/" title="Ecosystem"
bold
>
{{ project.blockchain_features?.network }} {{ project.blockchain_features?.network }}
</ProjectInfoItem> </ProjectInfoItem>
<ProjectInfoItem invisible title="Last update" bold> <ProjectInfoItem invisible title="Last update" bold>