Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update book meeting link and normalize tab links #586

Merged
merged 19 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/core/lib/stringUtils.jsx
Original file line number Diff line number Diff line change
@@ -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 };
4 changes: 2 additions & 2 deletions src/devhub/components/island/participate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
Expand All @@ -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,
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/devhub/components/island/support.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ 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 ↗",
},
},
{
heading: <>Get Funding</>,
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 ↗",
},
},
Expand Down
15 changes: 4 additions & 11 deletions src/devhub/entity/post/PostEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { normalize } =
VM.require("${REPL_DEVHUB}/widget/core.lib.stringUtils") || (() => {});

const cleanDescription = (description) => {
return description
? description.replace(
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
13 changes: 9 additions & 4 deletions src/devhub/page/community/index.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { normalize } =
VM.require("${REPL_DEVHUB}/widget/core.lib.stringUtils") || (() => {});

const Button = styled.button`
height: 40px;
font-size: 14px;
Expand Down Expand Up @@ -46,6 +49,8 @@ if (!tab) {
tab = "Activity";
}

tab = normalize(tab);

const [isLinkCopied, setLinkCopied] = useState(false);

const tabs = [
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(" ")}
>
<span>{title}</span>
Expand Down
4 changes: 2 additions & 2 deletions src/devhub/page/contribute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
15 changes: 4 additions & 11 deletions src/devhub/page/create.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { normalize } =
VM.require("${REPL_DEVHUB}/widget/core.lib.stringUtils") || (() => {});

const CenteredMessage = styled.div`
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -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,
Expand All @@ -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)];

Expand Down