Skip to content

Commit

Permalink
add ability for FAQ to have card display names, sort by those if supp…
Browse files Browse the repository at this point in the history
…lied
  • Loading branch information
seiyria committed Dec 19, 2024
1 parent 07cbe39 commit 08d98ad
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions interfaces/faq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export interface ICardFAQEntry {

export interface ICardFAQ {
card: string;
cardDisplay?: string;
faq: ICardFAQEntry[];
}
8 changes: 5 additions & 3 deletions src/app/_shared/pipes/faq.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class FaqPipe implements PipeTransform {
private cardsService = inject(CardsService);

transform(value: string, ...args: (string | undefined)[]): string {
const [productId] = args;
const [productId, cardDisplay] = args;
if (!productId) return value ?? '';

const ruleRegex = /\$rule:([\d.]+)\$/gm;
Expand All @@ -20,7 +20,9 @@ export class FaqPipe implements PipeTransform {
const rulesUrl = this.metaService.getRulesByProductId(productId);
if (!rulesUrl) return p1;

return `<a href="${rulesUrl}/#${p1}" target="_blank">${p1}</a>`;
return `<a href="${rulesUrl}/#${p1}" target="_blank">${
cardDisplay || p1
}</a>`;
});

const linkRegex = /\$link:([\w'"\-& ]+)\$/gm;
Expand All @@ -32,7 +34,7 @@ export class FaqPipe implements PipeTransform {

return `<a href="card/${encodeURIComponent(
foundCard.id
)}" target="_blank">${foundCard.name}</a>`;
)}" target="_blank">${cardDisplay || foundCard.name}</a>`;
});

value = value.replace('\n', '<br>');
Expand Down
2 changes: 1 addition & 1 deletion src/app/faq.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class FAQService {
Object.keys(faqData[productId]).forEach((locale) => {
baseFAQs[productId][locale] = sortBy(
faqData[productId][locale],
'card'
(cardFAQ) => cardFAQ.cardDisplay || cardFAQ.card
);

faqData[productId][locale].forEach((cardFAQ) => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/faq/faq.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ion-item-group>
<ion-item-divider>
<ion-label [id]="entry.card | cardid">
<span [innerHTML]="'$link:' + entry.card + '$' | faq:productId()"></span>
<span [innerHTML]="'$link:' + entry.card + '$' | faq:productId():entry.cardDisplay"></span>
</ion-label>
</ion-item-divider>

Expand Down

0 comments on commit 08d98ad

Please sign in to comment.