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

Create admin page with ability to control featured communities #309

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5e5fd99
chore: Format
carina-akaia Jul 20, 2023
0803e08
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Aug 1, 2023
6b5d095
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Aug 7, 2023
7a82065
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Aug 9, 2023
a0f340f
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Aug 11, 2023
d7a2a1b
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Aug 24, 2023
d4df7fd
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Sep 15, 2023
6dc15b5
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Oct 13, 2023
ff072f3
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Oct 16, 2023
2d24951
wip: Create admin page
carina-akaia Oct 16, 2023
ba5b11a
wip: Add navigation link to the admin page
carina-akaia Oct 16, 2023
6927299
wip
carina-akaia Oct 16, 2023
700058d
wip
carina-akaia Oct 18, 2023
1062edc
wip
carina-akaia Oct 18, 2023
e8871cb
wip
carina-akaia Oct 18, 2023
1000607
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Oct 18, 2023
2747128
wip
carina-akaia Oct 19, 2023
0e4bce5
Merge branch 'main' of https://github.com/near/neardevhub-widgets int…
carina-akaia Oct 19, 2023
1866a1a
Apply permission control logic
carina-akaia Oct 19, 2023
c8d7cf2
Apply permission control logic
carina-akaia Oct 19, 2023
e8547fa
Apply post-QA amendments
carina-akaia Oct 20, 2023
7c6b814
Merge branch 'main' of https://github.com/near/neardevhub-widgets int…
carina-akaia Oct 23, 2023
eeb9719
chore: Format
carina-akaia Oct 24, 2023
49496e7
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Oct 24, 2023
c18561d
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Oct 26, 2023
2223b40
Merge branch 'main' into feature/275-featured-communities
elliotBraem Oct 30, 2023
2f6b36c
move changes to devhub directory
Tguntenaar Oct 31, 2023
62d0db1
fix: remove theori.near from account.context
Tguntenaar Oct 31, 2023
f5acf5d
Merge pull request #6 from Tguntenaar/feature/275-refactored
carina-akaia Oct 31, 2023
16f9a7d
wip
carina-akaia Oct 31, 2023
b66ed9e
wip: Create API binding for `set_featured_communities`
carina-akaia Oct 31, 2023
20ee610
Merge branch 'main' of https://github.com/near/neardevhub-widgets int…
carina-akaia Oct 31, 2023
63c8abf
fix: Turn `useQuery` subscription back on
carina-akaia Oct 31, 2023
1381029
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Oct 31, 2023
0105f4d
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Nov 2, 2023
77145c6
Merge branch 'main' of https://github.com/near/neardevhub-widgets int…
carina-akaia Nov 7, 2023
1fcfae0
Target `devhub.near` account with bos-loader
carina-akaia Nov 7, 2023
395ff08
wip: Declare admin route
carina-akaia Nov 7, 2023
0216f97
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Nov 8, 2023
4954fee
Merge branch 'main' of https://github.com/near/neardevhub-widgets int…
carina-akaia Nov 9, 2023
699846c
Merge branch 'main' of https://github.com/near/neardevhub-widgets
carina-akaia Nov 9, 2023
2853f75
Fix widget account id for bos-loader
carina-akaia Nov 9, 2023
fb5dd92
Merge branch 'main' of https://github.com/near/neardevhub-widgets int…
carina-akaia Nov 13, 2023
410f5ec
Merge branch 'main' of https://github.com/near/neardevhub-widgets int…
carina-akaia Nov 15, 2023
d516433
Merge branches 'feature/275-featured-communities' and 'main' of https…
carina-akaia Nov 16, 2023
7afdd4b
Merge branch 'main' of https://github.com/near/neardevhub-widgets int…
carina-akaia Nov 16, 2023
9165063
Apply design amendments
carina-akaia Nov 16, 2023
c99ef8e
Rollback irrelevant changes
carina-akaia Nov 16, 2023
004af4d
Rollback irrelevant changes
carina-akaia Nov 16, 2023
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
8 changes: 8 additions & 0 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ function Page() {
/>
);
}
case "admin": {
return (
<Widget
src={"${REPL_DEVHUB}/widget/devhub.page.admin"}
props={passProps}
/>
);
}

default: {
// TODO: 404 page
Expand Down
6 changes: 5 additions & 1 deletion src/core/adapter/devhub-contract.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function getFeaturedCommunities() {
);
}

const setFeaturedCommunities = ({ handles }) =>
Near.call(devHubAccountId, "set_featured_communities", { handles });

function getAccountCommunityPermissions({ account_id, community_handle }) {
return (
Near.view("${REPL_DEVHUB_CONTRACT}", "get_account_community_permissions", {
Expand Down Expand Up @@ -205,7 +208,7 @@ function useQuery(name, params) {
})),

JSON.stringify({ name, params }),
{ subscribe: false } // NOTE: I'm turning off subscribe to stop the constant re-rendering
{ subscribe: true }
);

return cacheState === null ? initialState : cacheState;
Expand All @@ -217,6 +220,7 @@ return {
createCommunity,
getCommunity,
getFeaturedCommunities,
setFeaturedCommunities,
getAccountCommunityPermissions,
updateCommunity,
deleteCommunity,
Expand Down
27 changes: 27 additions & 0 deletions src/devhub/components/atom/Spinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const Spinner = ({ classNames, isHidden }) => (
<div
className={[
"d-flex justify-content-center align-items-center gap-4 w-100 h-100",
classNames?.root ?? "",
isHidden ? "d-none" : "",
].join(" ")}
>
<div className="spinner-grow text-info" role="status" />

<div
className="spinner-grow text-info"
role="status"
style={{ animationDelay: "0.3s" }}
>
<span className="visually-hidden">Loading...</span>
</div>

<div
className="spinner-grow text-info"
role="status"
style={{ animationDelay: "0.6s" }}
/>
</div>
);

return Spinner(props);
14 changes: 8 additions & 6 deletions src/devhub/entity/community/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CommunityCard = ({
format,
isBannerEnabled,
metadata,
actions,
...otherProps
}) => {
const renderFormat =
Expand Down Expand Up @@ -46,9 +47,8 @@ const CommunityCard = ({
`;

const formatSmall = (
<Link
<div
{...otherProps}
to={link}
className={[
"d-flex p-0 p-lg-3",
"rounded-2 border border-2",
Expand All @@ -60,13 +60,14 @@ const CommunityCard = ({
: "#ffffff",
}}
>
<div
className="d-flex align-items-center gap-3 rounded-4 w-100 h-100"
<Link
className="d-flex align-items-center gap-3 rounded-4 w-100 h-100 text-dark text-decoration-none"
style={{
background: "rgba(255, 255, 255, 0.9)",
backdropFilter: "blur(4px)",
padding: "3rem 1rem",
}}
to={link}
>
<Logo
alt="Community logo"
Expand All @@ -87,8 +88,9 @@ const CommunityCard = ({
{metadata.description}
</CommunityDescription>
</div>
</div>
</Link>
</Link>
{actions}
</div>
);

const formatMedium = (
Expand Down
105 changes: 105 additions & 0 deletions src/devhub/page/admin.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const { useQuery, hasModerator, setFeaturedCommunities } = VM.require(
"${REPL_DEVHUB}/widget/core.adapter.devhub-contract"
);

const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url");

if (!useQuery || !hasModerator || !href) {
return <p>Loading modules...</p>;
}

const AdministrationSettings = {
communities: {
maxFeatured: 5,
},
};

const CommunityFeaturingSchema = {
handle: {
label: "Pinned handle",
inputProps: { min: 3, max: 40, required: true },
},
};

const featuredCommunities = useQuery("featured_communities");
carina-akaia marked this conversation as resolved.
Show resolved Hide resolved
const featuredCommunityList = featuredCommunities.data ?? [];
const isDevHubModerator = hasModerator({
account_id: context.accountId,
});

const noPermissionBanner = (
<div
className="d-flex flex-column justify-content-center align-items-center"
style={{ height: 384 }}
>
<h2 className="alert alert-danger">
Your account does not have administration permissions.
</h2>
</div>
);

if (!isDevHubModerator) {
return noPermissionBanner;
}

const featuredCommunityHandles = featuredCommunityList.map(
({ handle }) => handle
);

const replaceFeaturedCommunity =
({ handle: targetHandle }) =>
({ handle: replacementHandle }) =>
setFeaturedCommunities({
handles: featuredCommunityHandles.map((handle) =>
handle === targetHandle ? replacementHandle : handle
),
});

return (
<div className="d-flex flex-column gap-4 p-4">
<Widget
src={"${REPL_DEVHUB}/widget/devhub.components.atom.Spinner"}
props={{
isHidden: !featuredCommunities.isLoading,
}}
/>
carina-akaia marked this conversation as resolved.
Show resolved Hide resolved

{!featuredCommunities.isLoading && (
<>
<h3>Featured communities</h3>

<div className="d-flex flex-wrap align-content-start gap-4">
{featuredCommunityList.map((community) => (
<Widget
src={"${REPL_DEVHUB}/widget/devhub.entity.community.Card"}
props={{
actions: (
<div className="d-flex justify-content-center align-items-center">
<Widget
src={
"${REPL_DEVHUB}/widget/devhub.components.organism.Configurator"
}
props={{
externalState: community,
isActive: true,
isUnlocked: true,
cancelLabel: "Reset",
onSubmit: replaceFeaturedCommunity(community),
submitLabel: "Replace",
schema: CommunityFeaturingSchema,
}}
/>
</div>
),

format: "small",
metadata: community,
target: "_blank",
}}
/>
))}
</div>
</>
)}
</div>
);