From 7b9242da2bcc3fed1d43a799ac44c1910dbe7624 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Thu, 7 Dec 2023 15:42:14 +0530 Subject: [PATCH 1/7] fix solution action --- src/devhub/entity/post/PostEditor.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/devhub/entity/post/PostEditor.jsx b/src/devhub/entity/post/PostEditor.jsx index cff6067ea..4e55daefd 100644 --- a/src/devhub/entity/post/PostEditor.jsx +++ b/src/devhub/entity/post/PostEditor.jsx @@ -1,3 +1,10 @@ +const cleanDescription = (description) => { + return description ? description.replace( + /###### Requested amount: .+?\n###### Requested sponsor: @[^\s]+\n/g, + "" + ) : description +}; + initState({ seekingFunding: props.seekingFunding ?? false, author_id: context.accountId, @@ -89,13 +96,6 @@ const labels = labelStrings.map((s) => { return { name: s }; }); -const cleanDescription = (description) => { - return description.replace( - /###### Requested amount: .+?\n###### Requested sponsor: @[^\s]+\n/g, - "" - ); -}; - if (!state.draftStateApplied && props.draftState) { State.update({ ...props.draftState, draftStateApplied: true }); } From 33bf2d164a15f0eba79e640f5b6d4692450ffb23 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Thu, 21 Dec 2023 20:37:02 +0530 Subject: [PATCH 2/7] update meeting link --- src/devhub/components/island/support.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devhub/components/island/support.jsx b/src/devhub/components/island/support.jsx index bb9d71883..71a6afe78 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%20hours%20/%20Support", + title: "Join ↗", }, }, { From 4bef0241b796c1736505bcbf0b2f2ec4f0ea371d Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Fri, 29 Dec 2023 20:15:47 +0530 Subject: [PATCH 3/7] suggestive changes --- src/core/lib/struct.jsx | 19 ++++++++++++++++++- src/devhub/page/community/index.jsx | 10 +++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/core/lib/struct.jsx b/src/core/lib/struct.jsx index a7ab9be47..7d1980e0e 100644 --- a/src/core/lib/struct.jsx +++ b/src/core/lib/struct.jsx @@ -78,4 +78,21 @@ const pick = (sourceObject, keysToPick) => { const typeMatch = (input) => input !== null && typeof input === "object" && !Array.isArray(input); -return { deepFieldUpdate, isEqual, pick, toOrdered, typeMatch }; +/** + * Transform input into a consistent and standardized format + * + * @param {string} label - The input to normalize. + * @returns {string} - normalized input + */ + +const normalizeLabel = (label) => + label + .replaceAll(/[- \.]/g, "_") + .replaceAll(/[^\w]+/g, "") + .replaceAll(/_+/g, "-") + .replace(/^-+/, "") + .replace(/-+$/, "") + .toLowerCase() + .trim("-"); + +return { deepFieldUpdate, isEqual, pick, toOrdered, typeMatch, normalizeLabel }; diff --git a/src/devhub/page/community/index.jsx b/src/devhub/page/community/index.jsx index c4667d364..263dec494 100644 --- a/src/devhub/page/community/index.jsx +++ b/src/devhub/page/community/index.jsx @@ -1,3 +1,9 @@ +const Struct = VM.require("${REPL_DEVHUB}/widget/core.lib.struct"); + +if (!Struct) { + return "Loading..."; +} + const Button = styled.button` height: 40px; font-size: 14px; @@ -46,6 +52,8 @@ if (!tab) { tab = "Activity"; } +tab = Struct.normalizeLabel(tab); + const [isLinkCopied, setLinkCopied] = useState(false); const tabs = [ @@ -85,7 +93,7 @@ const onShareClick = () => ) .then(setLinkCopied(true)); -let currentTab = tabs.find((it) => it.title === tab); +let currentTab = tabs.find((it) => Struct.normalizeLabel(it.title) === tab); const CommunityName = styled.span` color: #151515; From f5f148a1b5e7e5bfaf46e9b7236a723978b0ca98 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Fri, 29 Dec 2023 20:30:46 +0530 Subject: [PATCH 4/7] update links --- src/devhub/components/island/participate.jsx | 4 ++-- src/devhub/components/island/support.jsx | 4 ++-- src/devhub/page/contribute.jsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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 71a6afe78..7a5e66fb5 100644 --- a/src/devhub/components/island/support.jsx +++ b/src/devhub/components/island/support.jsx @@ -23,7 +23,7 @@ const Items = [ ), cta: { - href: "/devhub.near/widget/app?page=community&handle=devrel&tab=Office%20hours%20/%20Support", + 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/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", From de1d862bcb5813d9cc34338ae4a90a33fd159268 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Fri, 29 Dec 2023 22:23:52 +0530 Subject: [PATCH 5/7] refactor code --- src/core/lib/stringUtils.jsx | 18 ++++++++++++++++++ src/core/lib/struct.jsx | 19 +------------------ src/devhub/entity/post/PostEditor.jsx | 15 ++++----------- src/devhub/page/community/index.jsx | 13 +++++-------- src/devhub/page/create.jsx | 15 ++++----------- 5 files changed, 32 insertions(+), 48 deletions(-) create mode 100644 src/core/lib/stringUtils.jsx 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/core/lib/struct.jsx b/src/core/lib/struct.jsx index 7d1980e0e..a7ab9be47 100644 --- a/src/core/lib/struct.jsx +++ b/src/core/lib/struct.jsx @@ -78,21 +78,4 @@ const pick = (sourceObject, keysToPick) => { const typeMatch = (input) => input !== null && typeof input === "object" && !Array.isArray(input); -/** - * Transform input into a consistent and standardized format - * - * @param {string} label - The input to normalize. - * @returns {string} - normalized input - */ - -const normalizeLabel = (label) => - label - .replaceAll(/[- \.]/g, "_") - .replaceAll(/[^\w]+/g, "") - .replaceAll(/_+/g, "-") - .replace(/^-+/, "") - .replace(/-+$/, "") - .toLowerCase() - .trim("-"); - -return { deepFieldUpdate, isEqual, pick, toOrdered, typeMatch, normalizeLabel }; +return { deepFieldUpdate, isEqual, pick, toOrdered, typeMatch }; diff --git a/src/devhub/entity/post/PostEditor.jsx b/src/devhub/entity/post/PostEditor.jsx index c03168076..7c5959f34 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( @@ -233,16 +236,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, @@ -264,7 +257,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 263dec494..1de52902b 100644 --- a/src/devhub/page/community/index.jsx +++ b/src/devhub/page/community/index.jsx @@ -1,8 +1,5 @@ -const Struct = VM.require("${REPL_DEVHUB}/widget/core.lib.struct"); - -if (!Struct) { - return "Loading..."; -} +const { normalize } = + VM.require("${REPL_DEVHUB}/widget/core.lib.stringUtils") || (() => {}); const Button = styled.button` height: 40px; @@ -52,7 +49,7 @@ if (!tab) { tab = "Activity"; } -tab = Struct.normalizeLabel(tab); +tab = normalize(tab); const [isLinkCopied, setLinkCopied] = useState(false); @@ -93,7 +90,7 @@ const onShareClick = () => ) .then(setLinkCopied(true)); -let currentTab = tabs.find((it) => Struct.normalizeLabel(it.title) === tab); +let currentTab = tabs.find((it) => normalize(it.title) === tab); const CommunityName = styled.span` color: #151515; @@ -298,7 +295,7 @@ return ( aria-current={tab === 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/create.jsx b/src/devhub/page/create.jsx index 54ecdb65e..e7c10f0d1 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") || (() => {}); + State.init({ seekingFunding: false, author_id: context.accountId, @@ -210,16 +213,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, @@ -241,7 +234,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) { From 9db5b81f59b5d6e9aa45c690b067e63e09ee800a Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Fri, 29 Dec 2023 22:37:36 +0530 Subject: [PATCH 6/7] suggestive changes --- src/devhub/page/community/index.jsx | 4 ++-- src/devhub/page/create.jsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devhub/page/community/index.jsx b/src/devhub/page/community/index.jsx index 1de52902b..b83ee27a4 100644 --- a/src/devhub/page/community/index.jsx +++ b/src/devhub/page/community/index.jsx @@ -289,10 +289,10 @@ 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 === normalize(title) ? "nav-link active" : "nav-link", diff --git a/src/devhub/page/create.jsx b/src/devhub/page/create.jsx index b1a4437ab..06d11aa1d 100644 --- a/src/devhub/page/create.jsx +++ b/src/devhub/page/create.jsx @@ -1,6 +1,6 @@ const { normalize } = VM.require("${REPL_DEVHUB}/widget/core.lib.stringUtils") || (() => {}); - + const CenteredMessage = styled.div` display: flex; flex-direction: column; From d1e168be452f57d69fa98fb082fa6ecbe498f7e5 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Wed, 3 Jan 2024 14:56:31 +0530 Subject: [PATCH 7/7] fix failing tests --- src/devhub/page/create.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devhub/page/create.jsx b/src/devhub/page/create.jsx index 06d11aa1d..1ff3d0c13 100644 --- a/src/devhub/page/create.jsx +++ b/src/devhub/page/create.jsx @@ -218,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)];