diff --git a/src/core/lib/stringUtils.jsx b/src/core/lib/stringUtils.jsx new file mode 100644 index 000000000..9b490e171 --- /dev/null +++ b/src/core/lib/stringUtils.jsx @@ -0,0 +1,18 @@ +/** + * Transform input into a consistent and standardized format + * + * @param {string} text - The input to normalize. + * @returns {string} - normalized input + */ + +const normalize = (text) => + text + .replaceAll(/[- \.]/g, "_") + .replaceAll(/[^\w]+/g, "") + .replaceAll(/_+/g, "-") + .replace(/^-+/, "") + .replace(/-+$/, "") + .toLowerCase() + .trim("-"); + +return { normalize }; diff --git a/src/devhub/components/island/participate.jsx b/src/devhub/components/island/participate.jsx index e6c17ae48..53cecb78e 100644 --- a/src/devhub/components/island/participate.jsx +++ b/src/devhub/components/island/participate.jsx @@ -47,7 +47,7 @@ const Links = [ }, { title: "Host an Event", - href: "/devhub.near/widget/app?page=community&handle=hacks&tab=Wiki%202", + href: "/devhub.near/widget/app?page=community&handle=hacks&tab=wiki-202", count: 3, }, ], @@ -61,7 +61,7 @@ const Links = [ }, { title: "Join the Fellowship", - href: "/devhub.near/widget/app?page=community&handle=fellowship&tab=Wiki%201", + href: "/devhub.near/widget/app?page=community&handle=fellowship&tab=wiki-201", count: 5, }, { diff --git a/src/devhub/components/island/support.jsx b/src/devhub/components/island/support.jsx index bb9d71883..7a5e66fb5 100644 --- a/src/devhub/components/island/support.jsx +++ b/src/devhub/components/island/support.jsx @@ -23,8 +23,8 @@ const Items = [ ), cta: { - href: "/devhub.near/widget/app?page=community&handle=education&tab=Wiki%202", - title: "Book a meeting ↗", + href: "/devhub.near/widget/app?page=community&handle=devrel&tab=office-hours-support", + title: "Join ↗", }, }, { @@ -32,7 +32,7 @@ const Items = [ description: "Explore funding opportunities from DevHub to fuel your vision", cta: { - href: "/devhub.near/widget/app?page=community&handle=developer-dao&tab=Funding", + href: "/devhub.near/widget/app?page=community&handle=developer-dao&tab=funding", title: "Learn more ↗", }, }, diff --git a/src/devhub/entity/post/PostEditor.jsx b/src/devhub/entity/post/PostEditor.jsx index b2de4e2e5..7360ff085 100644 --- a/src/devhub/entity/post/PostEditor.jsx +++ b/src/devhub/entity/post/PostEditor.jsx @@ -1,3 +1,6 @@ +const { normalize } = + VM.require("${REPL_DEVHUB}/widget/core.lib.stringUtils") || (() => {}); + const cleanDescription = (description) => { return description ? description.replace( @@ -266,16 +269,6 @@ const onSubmit = () => { } }; -const normalizeLabel = (label) => - label - .replaceAll(/[- \.]/g, "_") - .replaceAll(/[^\w]+/g, "") - .replaceAll(/_+/g, "-") - .replace(/^-+/, "") - .replace(/-+$/, "") - .toLowerCase() - .trim("-"); - const checkLabel = (label) => { Near.asyncView("${REPL_DEVHUB_CONTRACT}", "is_allowed_to_use_labels", { editor: context.accountId, @@ -297,7 +290,7 @@ const checkLabel = (label) => { const setLabels = (labels) => { labels = labels.map((o) => { - o.name = normalizeLabel(o.name); + o.name = normalize(o.name); return o; }); if (labels.length < state.labels.length) { diff --git a/src/devhub/page/community/index.jsx b/src/devhub/page/community/index.jsx index c4667d364..b83ee27a4 100644 --- a/src/devhub/page/community/index.jsx +++ b/src/devhub/page/community/index.jsx @@ -1,3 +1,6 @@ +const { normalize } = + VM.require("${REPL_DEVHUB}/widget/core.lib.stringUtils") || (() => {}); + const Button = styled.button` height: 40px; font-size: 14px; @@ -46,6 +49,8 @@ if (!tab) { tab = "Activity"; } +tab = normalize(tab); + const [isLinkCopied, setLinkCopied] = useState(false); const tabs = [ @@ -85,7 +90,7 @@ const onShareClick = () => ) .then(setLinkCopied(true)); -let currentTab = tabs.find((it) => it.title === tab); +let currentTab = tabs.find((it) => normalize(it.title) === tab); const CommunityName = styled.span` color: #151515; @@ -284,13 +289,13 @@ return ( params: { page: "community", handle: community.handle, - tab: title, + tab: normalize(title), }, })} - aria-current={tab === title && "page"} + aria-current={tab === normalize(title) && "page"} className={[ "d-inline-flex gap-2", - tab === title ? "nav-link active" : "nav-link", + tab === normalize(title) ? "nav-link active" : "nav-link", ].join(" ")} > {title} diff --git a/src/devhub/page/contribute.jsx b/src/devhub/page/contribute.jsx index bc7a102dd..6e1be1322 100644 --- a/src/devhub/page/contribute.jsx +++ b/src/devhub/page/contribute.jsx @@ -66,7 +66,7 @@ const actions = [ description: "We are always on the lookout for events that align with our mission and provide value to the NEAR ecosystem. If you are organizing such an event, we would love to hear from you! Below is a guide on how to submit a sponsorship proposal to us.", ctaAction: "Learn More →", - ctaLink: "/devhub.near/widget/app?page=community&handle=hacks&tab=Wiki%202", + ctaLink: "/devhub.near/widget/app?page=community&handle=hacks&tab=wiki-202", }, { title: "Improve NEAR Docs", @@ -81,7 +81,7 @@ const actions = [ "As the NEAR ecosystem grows rapidly, there is an increasing need to improve developer productivity. The DevDAO NEAR Platform Fellowship Program aims to solve this issue by providing guidance to new contributors from experienced developers.", ctaAction: "Learn More →", ctaLink: - "/devhub.near/widget/app?page=community&handle=fellowship&tab=Wiki 1", + "/devhub.near/widget/app?page=community&handle=fellowship&tab=wiki-1", }, { title: "Join NEAR Campus", diff --git a/src/devhub/page/create.jsx b/src/devhub/page/create.jsx index 5a78e3412..1ff3d0c13 100644 --- a/src/devhub/page/create.jsx +++ b/src/devhub/page/create.jsx @@ -1,3 +1,6 @@ +const { normalize } = + VM.require("${REPL_DEVHUB}/widget/core.lib.stringUtils") || (() => {}); + const CenteredMessage = styled.div` display: flex; flex-direction: column; @@ -194,16 +197,6 @@ const onSolutionClick = () => { State.update({ postType: "Solution" }); }; -const normalizeLabel = (label) => - label - .replaceAll(/[- \.]/g, "_") - .replaceAll(/[^\w]+/g, "") - .replaceAll(/_+/g, "-") - .replace(/^-+/, "") - .replace(/-+$/, "") - .toLowerCase() - .trim("-"); - const checkLabel = (label) => { Near.asyncView("${REPL_DEVHUB_CONTRACT}", "is_allowed_to_use_labels", { editor: context.accountId, @@ -225,7 +218,7 @@ const checkLabel = (label) => { const setLabels = (labels) => { const normalizedLabels = labels.map((o) => - o.customOption ? normalizeLabel(o.label) : normalizeLabel(o) + o.customOption ? normalize(o.label) : normalize(o) ); const uniqueLabels = [...new Set(normalizedLabels)];