From e53ed690df316b619afeafadb02b5dc6bfe10651 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Sun, 18 Aug 2019 18:25:35 +0100 Subject: [PATCH 1/3] feat(resources): capitalize breadcrumbs + add home Fixed linting errors Fix linting errors again --- src/components/ResourceBreadcrumb/index.tsx | 28 ++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/components/ResourceBreadcrumb/index.tsx b/src/components/ResourceBreadcrumb/index.tsx index 83dbc35..7dfa94a 100644 --- a/src/components/ResourceBreadcrumb/index.tsx +++ b/src/components/ResourceBreadcrumb/index.tsx @@ -9,8 +9,17 @@ interface IResourceBreadcrumbProps { relativePath: any } +function capitalize(str: string): string { + const split = str.split(" ") + const reconstruct = [] + for (const substr of split) { + reconstruct.push(`${substr.charAt(0).toUpperCase()}${substr.substring(1)}`) + } + return reconstruct.join(" ") +} + function Link({ item }: { item: IFileOrFolder }) { - return {item.title} + return {capitalize(item.title)} } function flatten([ @@ -30,6 +39,23 @@ export function ResourceBreadcrumb({ relativePath }: IResourceBreadcrumbProps) { return ( + + + + + + + + {breadcrumbItems.map(item => { if (item.type === "folder") { return ( From 357e2dd2d2eb72059fa4de632e5021553c000310 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Sirois Date: Sun, 18 Aug 2019 23:32:08 -0400 Subject: [PATCH 2/3] refact: favour functional approach --- src/components/ResourceBreadcrumb/index.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/ResourceBreadcrumb/index.tsx b/src/components/ResourceBreadcrumb/index.tsx index 7dfa94a..d9d3b0b 100644 --- a/src/components/ResourceBreadcrumb/index.tsx +++ b/src/components/ResourceBreadcrumb/index.tsx @@ -10,12 +10,10 @@ interface IResourceBreadcrumbProps { } function capitalize(str: string): string { - const split = str.split(" ") - const reconstruct = [] - for (const substr of split) { - reconstruct.push(`${substr.charAt(0).toUpperCase()}${substr.substring(1)}`) - } - return reconstruct.join(" ") + return str + .split(" ") + .map(word => `${word.charAt(0).toUpperCase()}${word.substring(1)}`) + .join(" ") } function Link({ item }: { item: IFileOrFolder }) { From 782141751ae44db9763d0e67b0cd793eb4137db2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Sirois Date: Sun, 18 Aug 2019 23:50:31 -0400 Subject: [PATCH 3/3] feat(resources): remove dashes in breadcrumbs --- src/components/ResourceBreadcrumb/index.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/ResourceBreadcrumb/index.tsx b/src/components/ResourceBreadcrumb/index.tsx index d9d3b0b..5637a8f 100644 --- a/src/components/ResourceBreadcrumb/index.tsx +++ b/src/components/ResourceBreadcrumb/index.tsx @@ -1,3 +1,4 @@ +import pipe from "ramda/es/pipe" import React from "react" import ChevronUp from "../../icons/chevron-up.svg" @@ -16,8 +17,19 @@ function capitalize(str: string): string { .join(" ") } +function dashToSpace(str: string): string { + return str.replace("-", " ") +} + +function humanize(str: string): string { + return pipe( + dashToSpace, + capitalize + )(str) +} + function Link({ item }: { item: IFileOrFolder }) { - return {capitalize(item.title)} + return {humanize(item.title)} } function flatten([