Skip to content

Commit

Permalink
Fix issue with FAQ IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Dec 22, 2024
1 parent 1990ac0 commit 5ca1eaf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/app/services/relay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,12 @@ export class RelayService {

const event = await ndk.fetchEvent(filter);
if (event) {
return JSON.parse(event.content);
// Add IDs to loaded FAQ items
const faqItems = JSON.parse(event.content);
return faqItems.map((item: any) => ({
...item,
id: crypto.randomUUID()
}));
}
return null;
} catch (error) {
Expand Down Expand Up @@ -428,7 +433,9 @@ export class RelayService {
const ndk = await this.ensureConnected();
const event = new NDKEvent(ndk);
event.kind = NDKKind.AppSpecificData;
event.content = JSON.stringify(faq);
// Only save question and answer, strip the id
const faqContent = faq.map(({ question, answer }) => ({ question, answer }));
event.content = JSON.stringify(faqContent);
event.tags = [['d', 'angor:faq']];
await event.publish();
} catch (error) {
Expand Down Expand Up @@ -564,7 +571,10 @@ export class RelayService {
}

if (data.faq) {
const faqContent = data.faq.map(({ id, ...item }: FaqItem) => item); // Remove internal id properties
const faqContent = data.faq.map(({ question, answer }: FaqItem) => ({
question,
answer
}));

const ndkEvent = new NDKEvent();
ndkEvent.kind = NDKKind.AppSpecificData;
Expand Down

0 comments on commit 5ca1eaf

Please sign in to comment.