Skip to content

Commit

Permalink
refactor so that consolidated prefix is within the getLanguageFileNam…
Browse files Browse the repository at this point in the history
…e function
  • Loading branch information
barrymun committed Jan 24, 2025
1 parent 4d05b77 commit c0b3bff
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/hooks/useCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export const useCategories = () => {
[language.name, subLanguage]
);

const { data, loading, error } = useFetch<CategoryType[]>(
`/consolidated/${fileName}`
);
const { data, loading, error } = useFetch<CategoryType[]>(fileName);

const fetchedCategories = useMemo(() => {
return data ? data.map((item) => item.name) : [];
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/useSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export const useSnippets = () => {
[language.name, subLanguage]
);

const { data, loading, error } = useFetch<CategoryType[]>(
`/consolidated/${fileName}`
);
const { data, loading, error } = useFetch<CategoryType[]>(fileName);

const fetchedSnippets = useMemo(() => {
if (!data) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/languageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export function getLanguageFileName(
subLanguage: LanguageType["subLanguages"][number]["name"]
) {
return slugify(subLanguage) !== defaultSlugifiedSubLanguageName
? `${slugify(language)}--${slugify(subLanguage)}.json`
: `${slugify(language)}.json`;
? `/consolidated/${slugify(language)}--${slugify(subLanguage)}.json`
: `/consolidated/${slugify(language)}.json`;
}
4 changes: 2 additions & 2 deletions tests/languageUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ describe(getLanguageDisplayLogo.name, () => {
describe(getLanguageFileName.name, () => {
it("should return a concatenation of the language and subLanguage if subLanguage is not the default", () => {
const result = getLanguageFileName("JAVASCRIPT", "React");
expect(result).toBe("javascript--react.json");
expect(result).toBe("/consolidated/javascript--react.json");
});

it("should return the language name only if subLanguage is the default", () => {
const result = getLanguageFileName(
"JAVASCRIPT",
defaultSlugifiedSubLanguageName
);
expect(result).toBe("javascript.json");
expect(result).toBe("/consolidated/javascript.json");
});
});

0 comments on commit c0b3bff

Please sign in to comment.