1

I'm trying to read a user's address from their profile with useLDflex() or useLDflexValue().

When I run this:

const address = useLDflex(`[${webId}].vcard_hasAddress`)?.toString() || 'loading...';
console.log('address: ', address);

Console shows:

address:  https://<username>.solidcommunity.net/profile/card#id1234567890,false,

I can go to the URL in my browser and is shows the address object but how do I directly access the contents of the address object in my code? I presume there is a function to resolve the address URL and return the contents but can't find it.

Thank you. Any links to reading material on this topic would also be appreciated.

user3320795
  • 523
  • 2
  • 6
  • 17
  • 1
    I'm not too familiar with/a big fan of LDflex, but I think you might be able to pass e.g. `[address].vcard_locality` to another `useLDflex`, or maybe even directly use `[${webId}].vcard_hasAddress.vcard_locality`? – Vincent Mar 07 '21 at 10:25
  • That worked for `region` and `locality` but not `country-name`. Working: `const region = useLDflexValue(`[${webId}].vcard_hasAddress.vcard_region`)?.toString() || 'loading...';` Can't figure out `country-name`. – user3320795 Mar 08 '21 at 01:39
  • That sounds like it might be a bug in LDflex not supporting properties with dashes in them - might want to report it there. – Vincent Mar 08 '21 at 13:50

1 Answers1

1

The vcard:hasAddress predicate of a Solid Profile points to an address resource that then has further properties like vcard:country-name and vcard:locality.

With ldflex you are able to use a dot notation to "chain" your query. So this will get you the address locality:

[${webId}].vcard_hasAddress.vcard_locality

Instead of dot notation you can also access the properties with square brackets. This will also work with properties, that contain dashes, like country-name:

[${webId}].vcard_hasAddress['vcard:country-name']

Give it a try on the LDFlex playground with my WebID.

If the address is stored in a different document you need to first query the address and then do another query for the address properties:

1. [${webId}].vcard_hasAddress
2. [${address}].vcard_locality
aveltens
  • 323
  • 2
  • 10