omnisealbench / frontend /src /Descriptions.ts
Mark Duppenthaler
Add fallback path handling for SPA and start descriptions
d411f8a
import API from './API'
class Descriptions {
private static instance: Descriptions | null = null
private descriptions: Record<string, any> = {}
private modelDescriptions: Record<string, any> = {}
private loaded: boolean = false
private loadingPromise: Promise<void> | null = null
private constructor() {}
static getInstance(): Descriptions {
if (!Descriptions.instance) {
Descriptions.instance = new Descriptions()
}
return Descriptions.instance
}
async load(): Promise<void> {
if (this.loaded) return
if (this.loadingPromise) return this.loadingPromise
this.loadingPromise = API.fetchDescriptions().then((data) => {
this.descriptions = data.descriptions || {}
this.modelDescriptions = data.model_descriptions || {}
this.loaded = true
})
return this.loadingPromise
}
getFullName(name: string): string | undefined {
return this.descriptions[name]?.full_name
}
getDescription(name: string): string | undefined {
return this.descriptions[name]?.description
}
getUrl(name: string): string | undefined {
return this.descriptions[name]?.link
}
getModelDescription(name: string): string | undefined {
return this.modelDescriptions[name]?.description
}
getModelFullName(name: string): string | undefined {
return this.modelDescriptions[name]?.full_name
}
getModelPaperUrl(name: string): string | undefined {
return this.modelDescriptions[name]?.paper_link
}
getModelGithubUrl(name: string): string | undefined {
return this.modelDescriptions[name]?.github_link
}
}
export default Descriptions