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

WIP: Remove Handles from Graph #6040

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1e0b2bf
wip snip
joshuashort Dec 13, 2022
9267a8e
added netlify function for call handles, updated judge application by…
hannahtuttle Dec 14, 2022
aa6087d
cleanup judge page
joshuashort Dec 15, 2022
8578337
Disable query in manage-team
joshuashort Dec 15, 2022
70eddfc
Disable query in register-team
joshuashort Dec 15, 2022
144f876
wip get-user endpoint full list
joshuashort Dec 15, 2022
29a395d
Merge branch 'dzhawsh/user-endpoint-test' into 6039-feature-remove-ha…
joshuashort Dec 15, 2022
bef3800
testing new handles
hannahtuttle Dec 15, 2022
29d2f2e
Merge branch '6039-feature-remove-handles-from-graph' of https://gith…
hannahtuttle Dec 18, 2022
4b3c53f
Merge branch '6039-feature-remove-handles-from-graph' of https://gith…
hannahtuttle Dec 18, 2022
78757b5
updated register.tsx to use netlify handles
hannahtuttle Dec 18, 2022
25f945e
updated register team to use handles endpoint
hannahtuttle Dec 18, 2022
fddfc0f
updated manage teams, started testing the get-user function, updated …
hannahtuttle Dec 18, 2022
ce048f6
added file back in that was deleted durig the last merge
hannahtuttle Dec 19, 2022
59b669c
added formatting to json handle
hannahtuttle Dec 19, 2022
aaaaf28
removed extra space
hannahtuttle Dec 19, 2022
67f2757
[UPD] identation
Simon-Busch Jan 24, 2023
24e9d02
Merge branch 'main' into 6039-feature-remove-handles-from-graph
Simon-Busch Jan 24, 2023
afb4a6d
[UPD] refactor getHandles
Simon-Busch Jan 24, 2023
a2543c6
Merge branch 'main' into 6039-feature-remove-handles-from-graph
Simon-Busch Jan 24, 2023
94bd2e5
Merge branch 'main' into 6039-feature-remove-handles-from-graph
Simon-Busch Jan 24, 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
6 changes: 0 additions & 6 deletions _data/handles/D-squared.json

This file was deleted.

7 changes: 0 additions & 7 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ const plugins = [
name: `orgs`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/_data/handles`,
name: `handles`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
Expand Down
12 changes: 9 additions & 3 deletions netlify/functions/get-user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findUser } from "../util/user-utils";
import { findUser, getUsers } from "../util/user-utils";

exports.handler = async (event) => {
// only allow GET
Expand All @@ -12,11 +12,17 @@ exports.handler = async (event) => {

const userHandle = event.queryStringParameters.id;
try {
const user = await findUser(userHandle);
let res;
if (userHandle === undefined) {
res = getUsers();
}
else {
res = await findUser(userHandle);
}

return {
statusCode: 200,
body: JSON.stringify(user),
body: JSON.stringify(res),
};
} catch (error) {
return {
Expand Down
46 changes: 46 additions & 0 deletions netlify/functions/handles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fs, { readFileSync, readdir, readdirSync } from "fs";

//need to set up the members portion of the handles data (i think the members field is for teams)
//so my plan is to add a call to get the teams data here
const getHandles = () => {
const allHandles : {handle : string, link : string, moralisId: string, image : string, members: string[], }[] = [];
const data = readdirSync(`./_data/handles`);
data.forEach((file) => {
if(file.endsWith('.json')){
const buffer = readFileSync(`./_data/handles/${file}`);
const wardenFileData = JSON.parse(buffer.toString());
if (wardenFileData.image) {
const imagePath = wardenFileData.image.slice(2);
wardenFileData.imageUrl = `https://raw.githubusercontent.com/${process.env.GITHUB_REPO_OWNER}/${process.env.REPO}/${process.env.BRANCH_NAME}/_data/handles/${imagePath}`;
}
allHandles.push({...wardenFileData})
}
});

return allHandles;
}

exports.handler = async (event) => {
// only allow GET
if (event.httpMethod !== "GET") {
return {
statusCode: 405,
body: "Method not allowed",
headers: { Allow: "GET" },
};
}

try {
// handle
const allHandles = getHandles();
return {
statusCode: 200,
body: JSON.stringify(allHandles),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ error: error.toString(), details: error.stack }),
};
}
};
47 changes: 46 additions & 1 deletion netlify/util/user-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from "fs";
import { readFileSync, readdirSync } from "fs";
import Moralis from "moralis-v1/node";
import fetch from "node-fetch";
import uniq from "lodash/uniq";
Expand Down Expand Up @@ -43,6 +43,51 @@ export async function findUser(userHandle) {
}
}

export async function getUsers() {
const allHandles : {handle : string, link : string, moralisId: string, image : string}[] = [];
const data = readdirSync(`./_data/handles`);
// just return the objects?
// without members
data.forEach((file) => {
if(file.endsWith('.json')){
const buffer = readFileSync(`./_data/handles/${file}`);
const wardenFileData = JSON.parse(buffer.toString());
if (wardenFileData.image) {
const imagePath = wardenFileData.image.slice(2);
wardenFileData.imageUrl = `https://raw.githubusercontent.com/${process.env.GITHUB_REPO_OWNER}/${process.env.REPO}/${process.env.BRANCH_NAME}/_data/handles/${imagePath}`;
}
if(!wardenFileData.members){
allHandles.push({...wardenFileData})
}
}
});
return allHandles;
}

export async function getTeams() {
// just return the objects?
// with members
const teamHandles : {handle : string, link : string, moralisId: string, image : string}[] = [];
const data = readdirSync(`./_data/handles`);
// just return the objects?
// without members
data.forEach((file) => {
if(file.endsWith('.json')){
const buffer = readFileSync(`./_data/handles/${file}`);
const wardenFileData = JSON.parse(buffer.toString());
if (wardenFileData.image) {
const imagePath = wardenFileData.image.slice(2);
wardenFileData.imageUrl = `https://raw.githubusercontent.com/${process.env.GITHUB_REPO_OWNER}/${process.env.REPO}/${process.env.BRANCH_NAME}/_data/handles/${imagePath}`;
}
if(wardenFileData.members){
teamHandles.push({...wardenFileData})
}
}
});

return teamHandles;
}

export async function getUserTeams(username: string): Promise<string[]> {
let teamHandles: string[] = [];

Expand Down
215 changes: 91 additions & 124 deletions src/pages/judge-application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState } from "react";
import { StaticQuery, graphql } from "gatsby";

import Widgets from "../components/reporter/widgets/Widgets";
import useUser from "../hooks/UserContext";
Expand Down Expand Up @@ -87,26 +86,6 @@ const FormStatus = {
Error: "error",
};

const wardenListQuery = graphql`
query WardenList {
allHandlesJson(sort: { fields: handle, order: ASC }) {
edges {
node {
id
handle
image {
childImageSharp {
resize(width: 80) {
src
}
}
}
}
}
}
}
`;

const JudgeApplication = () => {
const [state, setState] = useState(initialState);
const [status, setStatus] = useState("unsubmitted");
Expand Down Expand Up @@ -168,113 +147,101 @@ const JudgeApplication = () => {
};

return (
<StaticQuery
query={wardenListQuery}
render={(data) => {
const wardens = data.allHandlesJson.edges.map(({ node }) => {
return { value: node.handle, image: node.image };
});
fields[0].options = wardens;

return (
<ProtectedPage
bodyClass="judge-application"
pageTitle="Judge Application | Code4rena"
>
<div className="wrapper-main">
{(status === FormStatus.Unsubmitted ||
status === FormStatus.Submitting) && (
<>
<h1 className="page-header">Judge Application</h1>
<form>
<Widgets
fields={fields}
onChange={handleChange}
fieldState={state}
/>{" "}
{status === FormStatus.Error && (
<div
className="error-message"
role="alert"
aria-atomic="true"
>
<p>
An error occurred; please try again. If you continue
to receive this error, let us know in{" "}
<a href="https://discord.gg/code4rena">Discord</a>.
All fields are required.
</p>
</div>
)}
<button
className="button cta-button"
type="button"
onClick={handleSubmit}
>
{status === FormStatus.Submitting
? "Submitting..."
: "Apply to be a Judge"}
</button>
</form>
</>
)}

{status === FormStatus.Submitted && (
<div className="thank-you">
<h1>Thanks for applying!</h1>
<p>
<strong>Here's what happens next:</strong>
</p>
<ol>
<li>
Judge applications are reviewed by the C4 judge selection
committee, which includes top leaderboard wardens and past
judges. The committee will review your application and
give you a "yes" or "not yet".
</li>
<li>
The review process begins after the application window
closes, and we expect it to take about a week, depending
on the number of applications the committee receives.
</li>
<li>
You'll be contacted via DM to let you know if your
application has been successful this time around.
</li>
<li>
If you're accepted as a judge, an organizer will onboard
you and get you set up to judge your first contest!
</li>
</ol>
<ProtectedPage
bodyClass="judge-application"
pageTitle="Judge Application | Code4rena"
>
<div className="wrapper-main">
{(status === FormStatus.Unsubmitted ||
status === FormStatus.Submitting) && (
<>
<h1 className="page-header">Judge Application</h1>
<form>
<Widgets
fields={fields}
onChange={handleChange}
fieldState={state}
/>{" "}
{status === FormStatus.Error && (
<div
className="error-message"
role="alert"
aria-atomic="true"
>
<p>
In the meantime, if you have questions, feel free to reach
out to us in the C4 Discord, or have a closer look at the{" "}
<a href="https://docs.code4rena.com/roles/judges/how-to-judge-a-contest">
How to judge a contest
</a>{" "}
section in the Code4rena docs.
An error occurred; please try again. If you continue
to receive this error, let us know in{" "}
<a href="https://discord.gg/code4rena">Discord</a>.
All fields are required.
</p>
</div>
)}
{status === FormStatus.Error && (
<div className="centered-text">
<h1>Whoops!</h1>
<p>An error occurred while processing your application.</p>
{errorMessage && <p>{errorMessage}</p>}
<button
className="button cta-button"
type="button"
onClick={() => setStatus(FormStatus.Unsubmitted)}
>
Try again
</button>
</div>
)}
</div>
</ProtectedPage>
);
}}
/>
<button
className="button cta-button"
type="button"
onClick={handleSubmit}
>
{status === FormStatus.Submitting
? "Submitting..."
: "Apply to be a Judge"}
</button>
</form>
</>
)}

{status === FormStatus.Submitted && (
<div className="thank-you">
<h1>Thanks for applying!</h1>
<p>
<strong>Here's what happens next:</strong>
</p>
<ol>
<li>
Judge applications are reviewed by the C4 judge selection
committee, which includes top leaderboard wardens and past
judges. The committee will review your application and
give you a "yes" or "not yet".
</li>
<li>
The review process begins after the application window
closes, and we expect it to take about a week, depending
on the number of applications the committee receives.
</li>
<li>
You'll be contacted via DM to let you know if your
application has been successful this time around.
</li>
<li>
If you're accepted as a judge, an organizer will onboard
you and get you set up to judge your first contest!
</li>
</ol>
<p>
In the meantime, if you have questions, feel free to reach
out to us in the C4 Discord, or have a closer look at the{" "}
<a href="https://docs.code4rena.com/roles/judges/how-to-judge-a-contest">
How to judge a contest
</a>{" "}
section in the Code4rena docs.
</p>
</div>
)}
{status === FormStatus.Error && (
<div className="centered-text">
<h1>Whoops!</h1>
<p>An error occurred while processing your application.</p>
{errorMessage && <p>{errorMessage}</p>}
<button
className="button cta-button"
type="button"
onClick={() => setStatus(FormStatus.Unsubmitted)}
>
Try again
</button>
</div>
)}
</div>
</ProtectedPage>
);
};

Expand Down
Loading