-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(front): controller architecture in ResultCard
- Loading branch information
1 parent
a9a68d9
commit 95fcc39
Showing
2 changed files
with
36 additions
and
21 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/front/src/routes/(home)/components/ResultCard.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import HtmlSanitizer from "jitbit-html-sanitizer"; | ||
import { isStartOfSiret } from "$lib/helpers/validatorHelper"; | ||
import { siretToSiren } from "$lib/helpers/sirenHelper"; | ||
import trackerService from "$lib/services/tracker.service"; | ||
|
||
export class ResultCardController { | ||
public url: string; | ||
public htmlName: string; | ||
public htmlRna: string; | ||
public htmlSiren: string; | ||
|
||
constructor(association, rawSearchValue: string) { | ||
const name = association.name || "-"; | ||
const rna = association.rna || "INCONNU"; | ||
const siren = association.siren || "INCONNU"; | ||
this.url = `/association/${association.rna || association.siren}`; | ||
|
||
let searchValue = HtmlSanitizer.SanitizeHtml(rawSearchValue.trim()); | ||
if (isStartOfSiret(rawSearchValue)) { | ||
searchValue = siretToSiren(rawSearchValue); | ||
} | ||
|
||
const searchValueRegex = new RegExp(searchValue, "ig"); | ||
const upperSearchedValue = searchValue.toUpperCase(); | ||
|
||
this.htmlName = name.replace(searchValueRegex, `<span class="dsfr-black-bold">${upperSearchedValue}</span>`); | ||
this.htmlRna = rna.replace(searchValueRegex, `<span class="dsfr-black-bold">${upperSearchedValue}</span>`); | ||
this.htmlSiren = siren.replace(searchValueRegex, `<span class="dsfr-black-bold">${upperSearchedValue}</span>`); | ||
} | ||
} |
27 changes: 6 additions & 21 deletions
27
packages/front/src/routes/(home)/components/ResultCard.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters