-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b00ec8
commit 1ce1a2d
Showing
5 changed files
with
76 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { className, title, icon, href, onClick } = props; | ||
|
||
const buttonStyle = { | ||
backgroundColor: "#0C7283", | ||
color: "#f3f3f3", | ||
}; | ||
|
||
return ( | ||
<div class="d-flex flex-row-reverse" className={props.className}> | ||
{props.href ? ( | ||
<a class="btn btn-light" style={buttonStyle} href={props.href}> | ||
<i | ||
class="bi" | ||
className={props.icon ? props.icon : "bi-plus-circle-fill"} | ||
></i> | ||
{props.title} | ||
</a> | ||
) : ( | ||
<button class="btn btn-light" style={buttonStyle} onClick={props.onClick}> | ||
<i | ||
class="bi" | ||
className={props.icon ? props.icon : "bi-plus-circle-fill"} | ||
></i> | ||
{props.title || "Post"} | ||
</button> | ||
)} | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,49 @@ | ||
// const { nearDevGovGigsWidgetsAccountId } = props; | ||
/* INCLUDE: "common.jsx" */ | ||
const nearDevGovGigsContractAccountId = | ||
props.nearDevGovGigsContractAccountId || | ||
(context.widgetSrc ?? "devgovgigs.near").split("/", 1)[0]; | ||
|
||
const nearDevGovGigsWidgetsAccountId = | ||
props.nearDevGovGigsWidgetsAccountId || | ||
(context.widgetSrc ?? "devgovgigs.near").split("/", 1)[0]; | ||
|
||
function widget(widgetName, widgetProps, key) { | ||
widgetProps = { | ||
...widgetProps, | ||
nearDevGovGigsContractAccountId: props.nearDevGovGigsContractAccountId, | ||
nearDevGovGigsWidgetsAccountId: props.nearDevGovGigsWidgetsAccountId, | ||
referral: props.referral, | ||
}; | ||
|
||
return ( | ||
<Widget | ||
src={`${nearDevGovGigsWidgetsAccountId}/widget/gigs-board.${widgetName}`} | ||
props={widgetProps} | ||
key={key} | ||
/> | ||
); | ||
} | ||
|
||
function href(widgetName, linkProps) { | ||
linkProps = { ...linkProps }; | ||
|
||
if (props.nearDevGovGigsContractAccountId) { | ||
linkProps.nearDevGovGigsContractAccountId = | ||
props.nearDevGovGigsContractAccountId; | ||
} | ||
|
||
if (props.nearDevGovGigsWidgetsAccountId) { | ||
linkProps.nearDevGovGigsWidgetsAccountId = | ||
props.nearDevGovGigsWidgetsAccountId; | ||
} | ||
|
||
if (props.referral) { | ||
linkProps.referral = props.referral; | ||
} | ||
|
||
const linkPropsQuery = Object.entries(linkProps) | ||
.filter(([_key, nullable]) => (nullable ?? null) !== null) | ||
.map(([key, value]) => `${key}=${value}`) | ||
.join("&"); | ||
|
||
return `/#/${nearDevGovGigsWidgetsAccountId}/widget/gigs-board.pages.${widgetName}${ | ||
linkPropsQuery ? "?" : "" | ||
}${linkPropsQuery}`; | ||
} | ||
/* END_INCLUDE: "common.jsx" */ | ||
|
||
const FeedPage = ({ author, recency, tag }) => { | ||
State.init({ | ||
initial: { author, tag }, | ||
author, | ||
tag, | ||
}); | ||
|
||
// When rerendered with different props, State will be preserved, so we need to update the state when we detect that the props have changed. | ||
if (tag !== state.initial.tag || author !== state.initial.author) { | ||
State.update((lastKnownState) => ({ | ||
...lastKnownState, | ||
initial: { author, tag }, | ||
author, | ||
tag, | ||
})); | ||
} | ||
|
||
const onTagSearch = (tag) => { | ||
State.update((lastKnownState) => ({ ...lastKnownState, tag })); | ||
}; | ||
// State.init({ | ||
// initial: { author, tag }, | ||
// author, | ||
// tag, | ||
// }); | ||
|
||
const [author, setAuthor] = useState(props.author || ""); | ||
const [tag, setTag] = useState(props.tag || ""); | ||
|
||
// // When rerendered with different props, State will be preserved, so we need to update the state when we detect that the props have changed. | ||
// if (tag !== state.initial.tag || author !== state.initial.author) { | ||
// State.update((lastKnownState) => ({ | ||
// ...lastKnownState, | ||
// initial: { author, tag }, | ||
// author, | ||
// tag, | ||
// })); | ||
// } | ||
|
||
const onTagSearch = (tag) => { | ||
setTag(tag); | ||
}; | ||
|
||
const onAuthorSearch = (author) => { | ||
State.update((lastKnownState) => ({ ...lastKnownState, author })); | ||
}; | ||
return ( | ||
<Widget | ||
src={`${nearDevGovGigsWidgetsAccountId}/widget/DevHub.entity.post.Panel`} | ||
props={{ | ||
author: state.author, | ||
authorQuery: { author: state.author }, | ||
children: widget("components.layout.Controls", { | ||
title: "Post", | ||
href: href("Create"), | ||
}), | ||
onAuthorSearch, | ||
onTagSearch, | ||
recency, | ||
tag: state.tag, | ||
tagQuery: { tag: state.tag }, | ||
transactionHashes: props.transactionHashes, | ||
}} | ||
/> | ||
); | ||
const onAuthorSearch = (author) => { | ||
setAuthor(author); | ||
}; | ||
|
||
return FeedPage(props); | ||
return ( | ||
<Widget | ||
src={`${nearDevGovGigsWidgetsAccountId}/widget/DevHub.entity.post.Panel`} | ||
props={{ | ||
author: author, | ||
authorQuery: { author }, | ||
children: ( | ||
<Widget | ||
src={`${nearDevGovGigsWidgetsAccountId}/widget/DevHub.components.molecule.PostControls`} | ||
props={{ title: "Post", link: "Create" }} | ||
/> | ||
), | ||
onAuthorSearch, | ||
onTagSearch, | ||
recency, | ||
tag: tag, | ||
tagQuery: { tag }, | ||
transactionHashes: props.transactionHashes, | ||
}} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters