Skip to content

Commit

Permalink
fix: build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bzavhorodskyi committed Feb 7, 2024
1 parent de1cdb7 commit b51d9b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/utils/helpers/navigation/getCategoriesUnderLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ export const getCategoriesUnderLanguage = (
currentLang: keyof Locales,
currentPageType?: NavigationEntry["type"]
) => {
const categories: { [key: string]: CategoryEntry } = {};
const categories: { [key in keyof Partial<Locales>]: CategoryEntry } = {};
const breadcrumbs: NavigationData["breadcrumbs"] = [];
const childLinks: NavigationData["childLinks"] = [];

// when we don`t have data for this locale we return default empty objects/arrays
if (!data.length) {
return {
categories: { [currentLang]: { children: [] as CategoryEntry[] } },
breadcrumbs: [],
childLinks: [],
};
}

data.forEach((item) => {
const {
title,
Expand Down Expand Up @@ -78,7 +87,7 @@ export const getCategoriesUnderLanguage = (
//if current item has the current language key in the URL we
// should store this value under current language
if (url.includes(`${CONTENT_PATH}`) && usedTitle) {
categories[currentLang].children?.push({
categories[currentLang]!.children?.push({
...item,
description,
type,
Expand All @@ -93,9 +102,8 @@ export const getCategoriesUnderLanguage = (
});
}
});
console.log(categories, "categories");

categories[currentLang].children = getCategoryChildrens({
categories[currentLang]!.children = getCategoryChildrens({
categories,
currentLang,
currentPage,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers/navigation/getCategoryChildrens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getCategoryChildrens = ({
const currentPageFixed = getCurrentPage(currentPage);
const splittedCurrentPage = currentPageFixed.split("/");

return categories[currentLang].children.map((child) => {
return categories[currentLang]?.children.map((child) => {
let isCollapsed = false;

parts.forEach((part) => {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/helpers/navigation/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Locales } from "@i18n/locales";

export type NavItemTypes = "category";

export interface CategoryEntry {
Expand Down Expand Up @@ -38,7 +40,7 @@ export interface ChildLink {
}

export interface NavigationData {
languageTree: { [key: string]: CategoryEntry };
languageTree: { [key in keyof Partial<Locales>]: CategoryEntry };
breadcrumbs: {
title: string;
url: string;
Expand Down

0 comments on commit b51d9b5

Please sign in to comment.