feat(dataset): mock data fetching to v2 dataset and add codes

This commit is contained in:
Daniel Klein 2024-09-12 08:43:01 +02:00
parent e699a2acfe
commit 22d11fa9fa
9 changed files with 16331 additions and 4 deletions

View file

@ -1,7 +1,15 @@
import type { Category, Project, ProjectShallow } from '~/types' import type { Category, Project, ProjectShallow } from '~/types'
import type { Asset } from '~/types/asset'
import type { Ecosystem } from '~/types/ecosystem'
import type { Feature } from '~/types/feature'
import type { Usecase } from '~/types/usecase'
export const useData = defineStore('data', () => { export const useData = defineStore('data', () => {
const categories = useState<Category[]>('categories') const categories = useState<Category[]>('categories')
const usecases = useState<Usecase[]>('usecases')
const features = useState<Feature[]>('features')
const assets = useState<Asset[]>('assets')
const ecosystems = useState<Ecosystem[]>('ecosystems')
const projects = useState<Project[]>('projects') const projects = useState<Project[]>('projects')
const selectedCategoryId = useState(() => 'all') const selectedCategoryId = useState(() => 'all')
const filter = reactive({ const filter = reactive({
@ -25,14 +33,47 @@ export const useData = defineStore('data', () => {
const data = await $fetch<{ const data = await $fetch<{
categories: Category[] categories: Category[]
projects: Project[] projects: Project[]
usecases: Usecase[]
ecosystems: Ecosystem[]
assets: Asset[]
features: Feature[]
}>('/api/data') }>('/api/data')
projects.value = data.projects.filter(p => p.name) projects.value = data.projects.map(project => ({
...project,
ratings: {
openess: {
documentation: 'Link',
funding: 0,
github: 'Link',
socials: '',
team: 1,
whitepaper: '',
},
technology: {
mainnet: true,
opensource: true,
assets: false,
audits: 0,
no_pgradability: true,
},
privacy: {
no_kyc: true,
no_compliance: true,
default_privacy: false,
policy: 'Link',
},
},
})).filter(p => p.name)
categories.value = data.categories.map((c) => { categories.value = data.categories.map((c) => {
c.projectsCount = projects.value.filter(p => c.projectsCount = projects.value.filter(p =>
p.categories?.includes(c.id), p.categories?.includes(c.id),
).length ).length
return c return c
}).filter(c => c.projectsCount > 0) }).filter(c => c.projectsCount > 0)
usecases.value = data.usecases
ecosystems.value = data.ecosystems
assets.value = data.assets
features.value = data.features
} }
catch (e) { catch (e) {
console.error(e) console.error(e)
@ -72,6 +113,30 @@ export const useData = defineStore('data', () => {
support: availableSupport(), support: availableSupport(),
image: project.logos?.[0]?.url ?? '', image: project.logos?.[0]?.url ?? '',
anonymity: true, anonymity: true,
categories: project.categories,
ratings: {
openess: {
documentation: 'Link',
funding: 0,
github: 'Link',
socials: '',
team: 1,
whitepaper: '',
},
technology: {
mainnet: true,
opensource: true,
assets: false,
audits: 0,
no_pgradability: true,
},
privacy: {
no_kyc: true,
no_compliance: true,
default_privacy: false,
policy: 'Link',
},
},
} }
} }
const shallowProjects = computed(() => projects.value.map(project => projectToShallow(project))) const shallowProjects = computed(() => projects.value.map(project => projectToShallow(project)))
@ -114,10 +179,25 @@ export const useData = defineStore('data', () => {
else else
return 0 return 0
}) })
return filteredShallowProjects return filteredShallowProjects
}) })
const groupedProjectsPerCategory = computed(() => {
const groupedProjects = categories.value.map((category) => {
// Find all projects that include this category
const projectsInCategory = filteredProjects.value.filter(project =>
project.categories.includes(category.id),
)
return {
title: category.name,
projects: projectsInCategory,
}
}).sort((a, b) => b.projects.length - a.projects.length)
return groupedProjects
})
const filteredProjectsCount = computed(() => filteredProjects.value.length) const filteredProjectsCount = computed(() => filteredProjects.value.length)
return { return {
@ -125,8 +205,13 @@ export const useData = defineStore('data', () => {
filter, filter,
switcher, switcher,
categories, categories,
usecases,
features,
ecosystems,
assets,
projects, projects,
shallowProjects, shallowProjects,
groupedProjectsPerCategory,
filteredProjectsCount, filteredProjectsCount,
fetchData, fetchData,
getProjectById, getProjectById,

View file

@ -1,3 +1,4 @@
export default defineEventHandler(() => { export default defineEventHandler(async () => {
return $fetch('https://explorer-data.web3privacy.info/') // return $fetch('https://explorer-data.web3privacy.info/')
return await useStorage('assets:server').getItem('data.json')
}) })

16189
server/assets/data.json Normal file

File diff suppressed because it is too large Load diff

4
types/asset.ts Normal file
View file

@ -0,0 +1,4 @@
export interface Asset {
id: string
name: string
}

View file

@ -2,4 +2,5 @@ export interface Category {
id: string id: string
name: string name: string
projectsCount: number projectsCount: number
usecases?: string[]
} }

5
types/ecosystem.ts Normal file
View file

@ -0,0 +1,5 @@
export interface Ecosystem {
id: string
name: string
icon: string
}

4
types/feature.ts Normal file
View file

@ -0,0 +1,4 @@
export interface Feature {
id: string
name: string
}

View file

@ -121,6 +121,11 @@ export interface Project {
url?: string url?: string
[k: string]: unknown [k: string]: unknown
}[] }[]
ratings: {
openess: OpenessRating
technology: TechnologyRating
privacy: PrivacyRating
}
} }
export interface ProjectShallow { export interface ProjectShallow {
@ -129,6 +134,7 @@ export interface ProjectShallow {
title1: string title1: string
description: string description: string
percentage: number percentage: number
categories: string[]
forum?: string | undefined forum?: string | undefined
github?: string | undefined github?: string | undefined
website?: string | undefined website?: string | undefined
@ -142,8 +148,36 @@ export interface ProjectShallow {
audits?: Audit[] | undefined audits?: Audit[] | undefined
support?: number | undefined support?: number | undefined
anonymity?: boolean | undefined anonymity?: boolean | undefined
ratings: {
openess: OpenessRating
technology: TechnologyRating
privacy: PrivacyRating
}
} }
export interface ProjectIndexable extends Project { export interface ProjectIndexable extends Project {
[key: string]: unknown [key: string]: unknown
} }
export interface OpenessRating {
documentation: string
github: string
socials: string
whitepaper: string
team: number
funding: number
}
export interface TechnologyRating {
mainnet: boolean
opensource: boolean
assets: boolean
no_pgradability: boolean
audits: number
}
export interface PrivacyRating {
policy: string
no_kyc: boolean
no_compliance: boolean
default_privacy: boolean
}

4
types/usecase.ts Normal file
View file

@ -0,0 +1,4 @@
export interface Usecase {
id: string
name: string
}