Skip to content

Commit ff2a95e

Browse files
authored
Merge pull request #69 from HackDavis/feat/server-connection
Projects connected to db
2 parents bf85a16 + 4ce18e1 commit ff2a95e

File tree

5 files changed

+60
-55
lines changed

5 files changed

+60
-55
lines changed

app/(api)/_actions/submissions/getSubmission.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function getSubmission(judge_id: string, team_id: string) {
1212
}
1313

1414
export async function getManySubmissions(query: object = {}) {
15-
const submissionRes = await GetManySubmissions(parseAndReplace(query));
15+
const newQuery = await parseAndReplace(query);
16+
const submissionRes = await GetManySubmissions(newQuery);
1617
return submissionRes.json();
1718
}

app/(api)/_actions/teams/getTeams.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use server';
2+
3+
import { GetManyTeams, GetTeam } from '@datalib/teams/getTeam';
4+
import parseAndReplace from '@utils/request/parseAndReplace';
5+
6+
export async function getTeam(id: string) {
7+
const teamRes = await GetTeam(id);
8+
return teamRes.json();
9+
}
10+
11+
export async function getManyTeams(query: object = {}) {
12+
const newQuery = await parseAndReplace(query);
13+
const teamRes = await GetManyTeams(newQuery);
14+
return teamRes.json();
15+
}

app/(pages)/_hooks/useSubmissions.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useState, useEffect } from 'react';
44
import { useAuth } from './useAuth';
55
import { getManySubmissions } from '@actions/submissions/getSubmission';
6+
import { getManyTeams } from '@actions/teams/getTeams';
67

78
export function useSubmissions(): any {
89
const { user, loading: authLoading } = useAuth();
@@ -17,7 +18,23 @@ export function useSubmissions(): any {
1718
},
1819
},
1920
});
20-
setSubmssions(submissions);
21+
if (submissions.ok) {
22+
const team_ids = submissions.body.map(
23+
(body: { team_id: string }) => body.team_id
24+
);
25+
const teams = await getManyTeams({
26+
_id: {
27+
$in: {
28+
'*convertIds': {
29+
ids: team_ids,
30+
},
31+
},
32+
},
33+
});
34+
setSubmssions(teams);
35+
} else {
36+
setSubmssions(submissions);
37+
}
2138
setLoading(false);
2239
};
2340
if (!authLoading && user) {

app/(pages)/judges/projects/_components/ProjectsList.tsx

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,39 @@
11
'use client';
22

3+
import { useSubmissions } from '@hooks/useSubmissions';
34
import ProjectsCard from './ProjectsCard';
45
import styles from './ProjectsCard.module.scss';
56

7+
interface Team {
8+
number: number;
9+
name: string;
10+
tracks: string[];
11+
}
12+
613
export default function ProjectsList({ activeTab }: { activeTab: number }) {
7-
const scoredProjects = [
8-
{
9-
num: 1,
10-
name: 'sc haptic hand',
11-
categories: ['not sure', 'something else', 'another category'],
12-
},
13-
{
14-
num: 70,
15-
name: 'sc haptic hand',
16-
categories: ['not sure', 'something else'],
17-
},
18-
];
14+
const { loading, submissions } = useSubmissions();
15+
if (loading) {
16+
return 'loading...';
17+
}
18+
const teams = submissions.ok ? submissions.body : [];
1919

20-
const unjudgedProjects = [
21-
{
22-
num: 75,
23-
name: 'unj haptic hand',
24-
categories: ['not sure', 'something else'],
25-
},
26-
{
27-
num: 75,
28-
name: 'unj haptic hand',
29-
categories: ['not', 'something', 'one more', 'another 1'],
30-
},
31-
{
32-
num: 175,
33-
name: 'unj haptic hand',
34-
categories: ['not sure', 'something else'],
35-
},
36-
{
37-
num: 75,
38-
name: 'unj haptic hand',
39-
categories: ['not sure', 'something else'],
40-
},
41-
{
42-
num: 75,
43-
name: 'unj haptic hand',
44-
categories: ['not', 'something', 'one more', 'another 1'],
45-
},
46-
{
47-
num: 75,
48-
name: 'unj haptic hand',
49-
categories: ['not sure', 'something else'],
50-
},
51-
];
20+
const scoredProjects = teams.filter((team: { scores?: string[] }) =>
21+
team.scores ? true : false
22+
);
23+
24+
const unjudgedProjects = teams.filter((team: { scores?: string[] }) =>
25+
team.scores ? false : true
26+
);
5227

5328
const renderScoredProjects = () => {
5429
return (
5530
<div className={styles.container}>
56-
{scoredProjects.map((project, index) => (
31+
{scoredProjects.map((project: Team, index: number) => (
5732
<ProjectsCard
5833
key={index}
59-
num={project.num}
34+
num={project.number}
6035
name={project.name}
61-
categories={project.categories}
36+
categories={project.tracks}
6237
/>
6338
))}
6439
</div>
@@ -67,12 +42,12 @@ export default function ProjectsList({ activeTab }: { activeTab: number }) {
6742
const renderuUnjudgedProjects = () => {
6843
return (
6944
<div className={styles.container}>
70-
{unjudgedProjects.map((project, index) => (
45+
{unjudgedProjects.map((project: Team, index: number) => (
7146
<ProjectsCard
7247
key={index}
73-
num={project.num}
48+
num={project.number}
7449
name={project.name}
75-
categories={project.categories}
50+
categories={project.tracks}
7651
/>
7752
))}
7853
</div>

app/(pages)/judges/projects/page.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import { useState } from 'react';
44
import ProjectsHeader from './_components/ProjectsHeader';
55
import ProjectsList from './_components/ProjectsList';
6-
import { useSubmissions } from '@hooks/useSubmissions';
76
// import SearchBar from './_components/SearchBar';
87

98
export default function Judges() {
109
const [activeTab, setActiveTab] = useState(0);
11-
const { loading, submissions } = useSubmissions();
1210
return (
1311
<div>
14-
{!loading && JSON.stringify(submissions)}
1512
<ProjectsHeader activeTab={activeTab} setActiveTab={setActiveTab} />
1613
{/* <SearchBar /> */}
1714
<ProjectsList activeTab={activeTab} />

0 commit comments

Comments
 (0)