/* 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 onSearchLabel = props.onSearchLabel; const selectedLabels = props.searchQuery?.label ? [{ name: props.searchQuery.label }] : []; const labels = Near.view(nearDevGovGigsContractAccountId, "get_all_labels"); if (!labels) { return <div>Loading ...</div>; } const wrappedLabels = labels.map((label) => ({ name: label })); const onChange = (selectedLabels) => { onSearchLabel(selectedLabels[0]?.name); }; return ( <Typeahead clearButton id="basic-typeahead-single" labelKey="name" onChange={onChange} options={wrappedLabels} placeholder="Search by tag" selected={selectedLabels} /> );