Skip to content

Commit 8cb6148

Browse files
committed
feat: introduce isSkillCredential utility to filter skill credentials in ClaimsPageClient and update related logic
1 parent daf1544 commit 8cb6148

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

app/claims/ClaimsPageClient.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ const withResolversPolyfill = <T,>() => {
189189
return { promise, resolve, reject }
190190
}
191191

192+
const isSkillCredential = (claim: any): boolean => {
193+
return (
194+
claim &&
195+
claim.credentialSubject &&
196+
claim.credentialSubject.achievement &&
197+
Array.isArray(claim.credentialSubject.achievement) &&
198+
claim.credentialSubject.achievement.length > 0 &&
199+
claim.credentialSubject.achievement[0] &&
200+
claim.credentialSubject.achievement[0].name
201+
)
202+
}
203+
192204
const ClaimsPageClient: React.FC = () => {
193205
const [claims, setClaims] = useState<any[]>([])
194206
const [loading, setLoading] = useState(true)
@@ -316,7 +328,7 @@ const ClaimsPageClient: React.FC = () => {
316328
console.log('🚀 ~ getAllClaims ~ parsedVCs:', parsedVCs)
317329
if (Array.isArray(parsedVCs) && parsedVCs.length > 0) {
318330
console.log('Returning cached VCs from localStorage')
319-
claimsData = parsedVCs
331+
claimsData = parsedVCs.filter(isSkillCredential)
320332
}
321333
} catch (error) {
322334
console.error('Error parsing cached VCs from localStorage:', error)
@@ -333,10 +345,13 @@ const ClaimsPageClient: React.FC = () => {
333345
try {
334346
const content = JSON.parse(file?.data?.body)
335347
if (content && '@context' in content) {
336-
vcs.push({
348+
const credential = {
337349
...content,
338350
id: file
339-
})
351+
}
352+
if (isSkillCredential(credential)) {
353+
vcs.push(credential)
354+
}
340355
}
341356
} catch (error) {
342357
console.error(`Error processing file ${file}:`, error)
@@ -349,7 +364,8 @@ const ClaimsPageClient: React.FC = () => {
349364
console.error('Error fetching claims from drive:', error)
350365
const fallback = localStorage.getItem('vcs')
351366
if (fallback) {
352-
return JSON.parse(fallback)
367+
const parsed = JSON.parse(fallback)
368+
return Array.isArray(parsed) ? parsed.filter(isSkillCredential) : []
353369
}
354370
return []
355371
}
@@ -463,7 +479,7 @@ const ClaimsPageClient: React.FC = () => {
463479
</Box>
464480
) : (
465481
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
466-
{claims.map(claim => (
482+
{claims.filter(isSkillCredential).map(claim => (
467483
<Paper
468484
key={claim.id}
469485
onClick={() => handleCardClick(claim.id)}

app/recommendations/[id]/page.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useStepContext } from '../../credentialForm/form/StepContext'
88
import useGoogleDrive from '../../hooks/useGoogleDrive'
99
import { useParams } from 'next/navigation'
1010
import Form from './RecommandationForm/Form'
11+
import { getFileViaFirebase } from '../../firebase/storage'
1112

1213
const CredentialData = () => {
1314
const { activeStep, setActiveStep } = useStepContext()
@@ -32,12 +33,15 @@ const CredentialData = () => {
3233
}
3334

3435
try {
35-
const content = await storage?.retrieve(id)
36-
const credentialSubject = content?.data?.credentialSubject
36+
let vcData = await getFileViaFirebase(id)
37+
vcData = JSON.parse(vcData.body)
38+
39+
const credentialSubject = vcData?.credentialSubject
40+
3741
if (credentialSubject?.name) {
3842
setFullName(credentialSubject.name)
3943
} else {
40-
setFullName('User')
44+
setFullName('the credential holder')
4145
}
4246

4347
await fetchFileMetadata(id)

0 commit comments

Comments
 (0)