/* 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) .map(([key, value]) => `${key}=${value}`) .join("&"); return `/#/${nearDevGovGigsWidgetsAccountId}/widget/gigs-board.pages.${widgetName}${ linkPropsQuery ? "?" : "" }${linkPropsQuery}`; } const WrapperWidget = ({ children, id }) => { // This function handles the state change for the children widgets const handleStateChange = (key, value) => { // Use the unique identifier to create a unique storage key const storageKey = `${id}_${key}`; // Update the local storage with the new state localStorage.setItem(storageKey, JSON.stringify(value)); }; // This function initializes the state of the children widgets const initState = (key, defaultValue) => { // Use the unique identifier to create a unique storage key const storageKey = `${id}_${key}`; let storedValue = localStorage.getItem(storageKey); if (storedValue) { try { return JSON.parse(storedValue); } catch (e) { console.error("Error parsing JSON from storage", e); } } return defaultValue; }; // Render the children widgets and pass the state management functions as props return React.Children.map(children, (child) => child && typeof child === "object" ? React.cloneElement(child, { handleStateChange, initState }) : child ); }; /* END_INCLUDE: "common.jsx" */ const accountId = context.accountId; const likesByUsers = props.likesByUsers || {}; const limit = props.limit ?? 3; let likes = Object.keys(likesByUsers).reverse(); const graphLikes = []; const nonGraph = []; const graph = (accountId && Social.keys(`${accountId}/graph/follow/*`, "final")[accountId].graph .follow) || {}; likes.forEach((accountId) => { if (accountId in graph) { graphLikes.push(accountId); } else { nonGraph.push(accountId); } }); let faces = [...graphLikes, ...nonGraph]; if (faces.length < limit + 3) { limit = faces.length; } const renderFaces = faces.splice(0, limit); const Faces = styled.span` .face { display: inline-block; position: relative; margin: -0.1em; height: 1.5em; width: 1.5em; min-width: 1.5em; vertical-align: top; img { object-fit: cover; border-radius: 50%; width: 100%; height: 100%; } } `; const Others = styled.span` &:hover { color: white !important; } `; const numLikes = likes.length - limit; return ( <> <Faces className="ms-1"> {renderFaces.map((accountId, i) => ( <a key={i} href={`#/mob.near/widget/ProfilePage?accountId=${accountId}`} className="text-decoration-none d-inline-block" > <Widget src="mob.near/widget/Profile.OverlayTrigger" props={{ accountId, children: ( <Widget src="mob.near/widget/ProfileImage" props={{ metadata, accountId, widgetName, style: { zIndex: 10 - i }, className: "face", tooltip: false, imageStyle: {}, imageClassName: "", }} /> ), }} /> </a> ))} </Faces> {numLikes > 0 ? ( <OverlayTrigger placement="auto" overlay={ <Tooltip> <div className="text-truncate text-start" style={{ maxWidth: "16em" }} > {faces.slice(0, 10).map((accountId, i) => ( <Fragment key={i}> <Widget src="mob.near/widget/ProfileLine" props={{ accountId, link: false }} /> <br /> </Fragment> ))} {faces.length > 10 ? "..." : ""} </div> </Tooltip> } > <span className="ms-1"> and {numLikes} other{numLikes === 1 ? "" : "s"} </span> </OverlayTrigger> ) : ( "" )} </> );