diff --git a/src/app/ContestSite/Components/THUAI6/StreamNative.tsx b/src/app/ContestSite/Components/THUAI6/StreamNative.tsx index 3e4938a26..8c5bca6d7 100644 --- a/src/app/ContestSite/Components/THUAI6/StreamNative.tsx +++ b/src/app/ContestSite/Components/THUAI6/StreamNative.tsx @@ -24,7 +24,7 @@ const THUAI6: React.FC = ({ url }) => { const [student4Loc, setStudent4Loc] = useState({ x: 0, y: 0 }); const [trickerLoc, setTrickerLoc] = useState({ x: 0, y: 0 }); useEffect(() => { - const client = new AvailableServiceClient(url + ":8879"); + const client = new AvailableServiceClient(url); const request = new Message2Server.IDMsg(); request.setPlayerId(99); client.tryConnection( diff --git a/src/app/ContestSite/IntroPage.tsx b/src/app/ContestSite/IntroPage.tsx index c0f5e3fc2..581cec010 100644 --- a/src/app/ContestSite/IntroPage.tsx +++ b/src/app/ContestSite/IntroPage.tsx @@ -25,7 +25,6 @@ const IntroPage: React.FC = ({ mode, user }) => { contest_id: Contest_id, }, }); - console.log(totalTeamNumData); const { data: totalMemberNumData } = graphql.useGetTotalMemberNumSuspenseQuery({ variables: { diff --git a/src/app/ContestSite/PlaybackPage.tsx b/src/app/ContestSite/PlaybackPage.tsx index dad9faa5e..26fe80822 100644 --- a/src/app/ContestSite/PlaybackPage.tsx +++ b/src/app/ContestSite/PlaybackPage.tsx @@ -19,6 +19,15 @@ import { Suspense } from "react"; import styled from "styled-components"; import { ContestProps } from "."; import ReactRouterPrompt from "react-router-prompt"; +import NotImplemented from "./Components/NotImplemented"; + +const Container = styled.div` + height: calc(100vh - 72px); + width: 100%; + display: flex; + align-items: center; + justify-content: center; +`; const PlaybackPage: React.FC = ({ mode, user }) => { const url = useUrl(); @@ -26,6 +35,32 @@ const PlaybackPage: React.FC = ({ mode, user }) => { const room_id = url.query.get("room"); const playback_speed = url.query.get("speed"); + const { data: contestNameData, error: contestNameError } = + graphql.useGetContestNameSuspenseQuery({ + variables: { + contest_id: Contest_id, + }, + }); + useEffect(() => { + if (contestNameError) { + message.error("获取比赛信息失败"); + console.log(contestNameError.message); + } + }); + + const { data: contestSwitchData, error: contestSwitchError } = + graphql.useGetContestSwitchSubscription({ + variables: { + contest_id: Contest_id, + }, + }); + useEffect(() => { + if (contestSwitchError) { + message.error("获取比赛状态失败"); + console.log(contestSwitchError.message); + } + }); + const { data: scoreteamListData, //loading: scoreteamListLoading, @@ -42,23 +77,10 @@ const PlaybackPage: React.FC = ({ mode, user }) => { } }); - const getWebGLPath = (contest: string | null) => { - // TODO: 这里应该改成数据库查询 - const sharedUrl = process.env.REACT_APP_STATIC_URL! + "/public/WebGL/"; - let projectUrl = sharedUrl + "THUAI6/"; - let projectName = "THUAI6_WebGL"; - if (contest === "19cece8f-3cfa-4098-9cbe-cbf2b5f50ebe") { - projectUrl = sharedUrl + "Jump/"; - projectName = "JumpJump-Build"; - } - if (contest === "b4e3f620-49f7-4883-ba0f-81cbfdcf6196") { - projectUrl = sharedUrl + "THUAI7/"; - projectName = "interface_localExecutable"; - } - return { projectUrl, projectName }; - }; - - const { projectUrl, projectName } = getWebGLPath(Contest_id); + const projectUrl = + process.env.REACT_APP_STATIC_URL! + + `/public/WebGL/${contestNameData?.contest_by_pk?.name ?? "Jump"}/`; + const projectName = "Playback"; const handleCacheControl = (url: string) => { if (url.match(/\.data/) || url.match(/\.wasm/) || url.match(/\.bundle/)) { @@ -159,14 +181,6 @@ const PlaybackPage: React.FC = ({ mode, user }) => { } }; - const Container = styled.div` - height: calc(100vh - 72px); - width: 100%; - display: flex; - align-items: center; - justify-content: center; - `; - const Loading = () => { return ( @@ -175,7 +189,7 @@ const PlaybackPage: React.FC = ({ mode, user }) => { ); }; - return ( + return contestSwitchData?.contest_by_pk?.playback_switch ? ( {isLoaded === false && ( @@ -209,7 +223,7 @@ const PlaybackPage: React.FC = ({ mode, user }) => { requestFullscreen(true); }} /> - {Contest_id === "19cece8f-3cfa-4098-9cbe-cbf2b5f50ebe" && ( + {contestNameData?.contest_by_pk?.name === "THUAI6" && ( = ({ mode, user }) => { )} + ) : ( + + + ); }; diff --git a/src/app/ContestSite/PlaygroundPage.tsx b/src/app/ContestSite/PlaygroundPage.tsx index 67fe71458..58abd8af3 100644 --- a/src/app/ContestSite/PlaygroundPage.tsx +++ b/src/app/ContestSite/PlaygroundPage.tsx @@ -1,21 +1,68 @@ -import React from "react"; +import React, { useEffect } from "react"; import { ContestProps } from "."; import { useUrl } from "@/api/hooks/url"; -import NotImplementedPage from "./Components/NotImplemented"; +import * as graphql from "@/generated/graphql"; +import NotImplemented from "./Components/NotImplemented"; +import { message } from "antd"; +import styled from "styled-components"; + +const Container = styled.div` + height: calc(100vh - 72px); + width: 100%; + display: flex; + align-items: center; + justify-content: center; +`; const PlaygroundPage: React.FC = ({ mode, user }) => { const url = useUrl(); const contest = url.query.get("contest"); - if (contest === "b4e3f620-49f7-4883-ba0f-81cbfdcf6196") { - return ( -
-

Playground for THUAI7, not implemented yet.

-
- ); - } else { - return ; - } + const { data: contestNameData, error: contestNameError } = + graphql.useGetContestNameSuspenseQuery({ + variables: { + contest_id: contest, + }, + }); + useEffect(() => { + if (contestNameError) { + message.error("获取比赛信息失败"); + console.log(contestNameError.message); + } + }); + + const { data: contestSwitchData, error: contestSwitchError } = + graphql.useGetContestSwitchSubscription({ + variables: { + contest_id: contest, + }, + }); + useEffect(() => { + if (contestSwitchError) { + message.error("获取比赛状态失败"); + console.log(contestSwitchError.message); + } + }); + + const projectUrl = + process.env.REACT_APP_STATIC_URL! + + `/public/WebGL/${contestNameData?.contest_by_pk?.name ?? "Jump"}/`; + const projectName = "Playground"; + + return contestSwitchData?.contest_by_pk?.playground_switch ? ( + // TODO: Copy from PlaybackPage.tsx +
+

Playground for THUAI7, not implemented yet.

+
+

Project URL: {projectUrl}

+
+

Project Name: {projectName}

+
+ ) : ( + + + + ); }; export default PlaygroundPage; diff --git a/src/app/ContestSite/StreamPage.tsx b/src/app/ContestSite/StreamPage.tsx index ff7e77bc3..295c1b8e7 100644 --- a/src/app/ContestSite/StreamPage.tsx +++ b/src/app/ContestSite/StreamPage.tsx @@ -1,22 +1,75 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import React from "react"; import { useUrl } from "../../api/hooks/url"; import { ContestProps } from "."; import THUAI6 from "./Components/THUAI6/StreamNative"; +import * as graphql from "@/generated/graphql"; +import { message } from "antd"; +import styled from "styled-components"; +import NotImplemented from "./Components/NotImplemented"; export interface StreamProps { url: string; } +const Container = styled.div` + height: calc(100vh - 72px); + width: 100%; + display: flex; + align-items: center; + justify-content: center; +`; + const StreamPage: React.FC = ({ mode, user }) => { const url = useUrl(); - const Contest_id = url.query.get("contest"); - const [streamUrl, setStreamUrl] = useState("https://api.eesast.com"); + const contest = url.query.get("contest"); + + const { data: contestNameData, error: contestNameError } = + graphql.useGetContestNameSuspenseQuery({ + variables: { + contest_id: contest, + }, + }); + useEffect(() => { + if (contestNameError) { + message.error("获取比赛信息失败"); + console.log(contestNameError.message); + } + }); + + const { data: contestSwitchData, error: contestSwitchError } = + graphql.useGetContestSwitchSubscription({ + variables: { + contest_id: contest, + }, + }); + useEffect(() => { + if (contestSwitchError) { + message.error("获取比赛状态失败"); + console.log(contestSwitchError.message); + } + }); + + const [streamUrl, setStreamUrl] = useState( + "https://api.eesast.com:8879", + ); if (url.query.get("url") !== null) { setStreamUrl("http://" + url.query.get("url")); } - if (Contest_id === "211b9ac2-f004-489d-bd71-4bdde335b597") - return ; + + const Stream = (props: StreamProps) => { + if (contestNameData?.contest_by_pk?.name === "THUAI6") + return ; + else return ; + }; + + return contestSwitchData?.contest_by_pk?.stream_switch ? ( + + ) : ( + + + + ); }; export default StreamPage; diff --git a/src/generated/graphql.tsx b/src/generated/graphql.tsx index 0c63e6ee6..77ef43ebc 100644 --- a/src/generated/graphql.tsx +++ b/src/generated/graphql.tsx @@ -6209,10 +6209,6 @@ export type Mutation_Root = { delete_share_course?: Maybe; /** delete single row from the table: "share_course" */ delete_share_course_by_pk?: Maybe; - /** delete data from the table: "test" */ - delete_test?: Maybe; - /** delete single row from the table: "test" */ - delete_test_by_pk?: Maybe; /** delete data from the table: "users" */ delete_users?: Maybe; /** delete single row from the table: "users" */ @@ -6349,10 +6345,6 @@ export type Mutation_Root = { insert_share_course?: Maybe; /** insert a single row into the table: "share_course" */ insert_share_course_one?: Maybe; - /** insert data into the table: "test" */ - insert_test?: Maybe; - /** insert a single row into the table: "test" */ - insert_test_one?: Maybe; /** insert data into the table: "users" */ insert_users?: Maybe; /** insert a single row into the table: "users" */ @@ -6489,10 +6481,6 @@ export type Mutation_Root = { update_share_course?: Maybe; /** update single row of the table: "share_course" */ update_share_course_by_pk?: Maybe; - /** update data of the table: "test" */ - update_test?: Maybe; - /** update single row of the table: "test" */ - update_test_by_pk?: Maybe; /** update data of the table: "users" */ update_users?: Maybe; /** update single row of the table: "users" */ @@ -6897,18 +6885,6 @@ export type Mutation_RootDelete_Share_Course_By_PkArgs = { }; -/** mutation root */ -export type Mutation_RootDelete_TestArgs = { - where: Test_Bool_Exp; -}; - - -/** mutation root */ -export type Mutation_RootDelete_Test_By_PkArgs = { - id: Scalars['Int']['input']; -}; - - /** mutation root */ export type Mutation_RootDelete_UsersArgs = { where: Users_Bool_Exp; @@ -7381,20 +7357,6 @@ export type Mutation_RootInsert_Share_Course_OneArgs = { }; -/** mutation root */ -export type Mutation_RootInsert_TestArgs = { - objects: Array; - on_conflict?: InputMaybe; -}; - - -/** mutation root */ -export type Mutation_RootInsert_Test_OneArgs = { - object: Test_Insert_Input; - on_conflict?: InputMaybe; -}; - - /** mutation root */ export type Mutation_RootInsert_UsersArgs = { objects: Array; @@ -7899,22 +7861,6 @@ export type Mutation_RootUpdate_Share_Course_By_PkArgs = { }; -/** mutation root */ -export type Mutation_RootUpdate_TestArgs = { - _inc?: InputMaybe; - _set?: InputMaybe; - where: Test_Bool_Exp; -}; - - -/** mutation root */ -export type Mutation_RootUpdate_Test_By_PkArgs = { - _inc?: InputMaybe; - _set?: InputMaybe; - pk_columns: Test_Pk_Columns_Input; -}; - - /** mutation root */ export type Mutation_RootUpdate_UsersArgs = { _set?: InputMaybe; @@ -9514,12 +9460,6 @@ export type Query_Root = { share_course_aggregate: Share_Course_Aggregate; /** fetch data from the table: "share_course" using primary key columns */ share_course_by_pk?: Maybe; - /** fetch data from the table: "test" */ - test: Array; - /** fetch aggregated fields from the table: "test" */ - test_aggregate: Test_Aggregate; - /** fetch data from the table: "test" using primary key columns */ - test_by_pk?: Maybe; /** fetch data from the table: "users" */ users: Array; /** fetch aggregated fields from the table: "users" */ @@ -10280,29 +10220,6 @@ export type Query_RootShare_Course_By_PkArgs = { }; -export type Query_RootTestArgs = { - distinct_on?: InputMaybe>; - limit?: InputMaybe; - offset?: InputMaybe; - order_by?: InputMaybe>; - where?: InputMaybe; -}; - - -export type Query_RootTest_AggregateArgs = { - distinct_on?: InputMaybe>; - limit?: InputMaybe; - offset?: InputMaybe; - order_by?: InputMaybe>; - where?: InputMaybe; -}; - - -export type Query_RootTest_By_PkArgs = { - id: Scalars['Int']['input']; -}; - - export type Query_RootUsersArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; @@ -11298,12 +11215,6 @@ export type Subscription_Root = { share_course_aggregate: Share_Course_Aggregate; /** fetch data from the table: "share_course" using primary key columns */ share_course_by_pk?: Maybe; - /** fetch data from the table: "test" */ - test: Array; - /** fetch aggregated fields from the table: "test" */ - test_aggregate: Test_Aggregate; - /** fetch data from the table: "test" using primary key columns */ - test_by_pk?: Maybe; /** fetch data from the table: "users" */ users: Array; /** fetch aggregated fields from the table: "users" */ @@ -12064,29 +11975,6 @@ export type Subscription_RootShare_Course_By_PkArgs = { }; -export type Subscription_RootTestArgs = { - distinct_on?: InputMaybe>; - limit?: InputMaybe; - offset?: InputMaybe; - order_by?: InputMaybe>; - where?: InputMaybe; -}; - - -export type Subscription_RootTest_AggregateArgs = { - distinct_on?: InputMaybe>; - limit?: InputMaybe; - offset?: InputMaybe; - order_by?: InputMaybe>; - where?: InputMaybe; -}; - - -export type Subscription_RootTest_By_PkArgs = { - id: Scalars['Int']['input']; -}; - - export type Subscription_RootUsersArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; @@ -12132,202 +12020,6 @@ export type Subscription_RootWeekly_By_PkArgs = { id: Scalars['Int']['input']; }; -/** columns and relationships of "test" */ -export type Test = { - __typename?: 'test'; - date?: Maybe; - id: Scalars['Int']['output']; - title: Scalars['String']['output']; - url: Scalars['String']['output']; -}; - -/** aggregated selection of "test" */ -export type Test_Aggregate = { - __typename?: 'test_aggregate'; - aggregate?: Maybe; - nodes: Array; -}; - -/** aggregate fields of "test" */ -export type Test_Aggregate_Fields = { - __typename?: 'test_aggregate_fields'; - avg?: Maybe; - count: Scalars['Int']['output']; - max?: Maybe; - min?: Maybe; - stddev?: Maybe; - stddev_pop?: Maybe; - stddev_samp?: Maybe; - sum?: Maybe; - var_pop?: Maybe; - var_samp?: Maybe; - variance?: Maybe; -}; - - -/** aggregate fields of "test" */ -export type Test_Aggregate_FieldsCountArgs = { - columns?: InputMaybe>; - distinct?: InputMaybe; -}; - -/** aggregate avg on columns */ -export type Test_Avg_Fields = { - __typename?: 'test_avg_fields'; - id?: Maybe; -}; - -/** Boolean expression to filter rows from the table "test". All fields are combined with a logical 'AND'. */ -export type Test_Bool_Exp = { - _and?: InputMaybe>; - _not?: InputMaybe; - _or?: InputMaybe>; - date?: InputMaybe; - id?: InputMaybe; - title?: InputMaybe; - url?: InputMaybe; -}; - -/** unique or primary key constraints on table "test" */ -export enum Test_Constraint { - /** unique or primary key constraint on columns "id" */ - TestPkey = 'test_pkey' -} - -/** input type for incrementing numeric columns in table "test" */ -export type Test_Inc_Input = { - id?: InputMaybe; -}; - -/** input type for inserting data into table "test" */ -export type Test_Insert_Input = { - date?: InputMaybe; - id?: InputMaybe; - title?: InputMaybe; - url?: InputMaybe; -}; - -/** aggregate max on columns */ -export type Test_Max_Fields = { - __typename?: 'test_max_fields'; - date?: Maybe; - id?: Maybe; - title?: Maybe; - url?: Maybe; -}; - -/** aggregate min on columns */ -export type Test_Min_Fields = { - __typename?: 'test_min_fields'; - date?: Maybe; - id?: Maybe; - title?: Maybe; - url?: Maybe; -}; - -/** response of any mutation on the table "test" */ -export type Test_Mutation_Response = { - __typename?: 'test_mutation_response'; - /** number of rows affected by the mutation */ - affected_rows: Scalars['Int']['output']; - /** data from the rows affected by the mutation */ - returning: Array; -}; - -/** on_conflict condition type for table "test" */ -export type Test_On_Conflict = { - constraint: Test_Constraint; - update_columns?: Array; - where?: InputMaybe; -}; - -/** Ordering options when selecting data from "test". */ -export type Test_Order_By = { - date?: InputMaybe; - id?: InputMaybe; - title?: InputMaybe; - url?: InputMaybe; -}; - -/** primary key columns input for table: test */ -export type Test_Pk_Columns_Input = { - id: Scalars['Int']['input']; -}; - -/** select columns of table "test" */ -export enum Test_Select_Column { - /** column name */ - Date = 'date', - /** column name */ - Id = 'id', - /** column name */ - Title = 'title', - /** column name */ - Url = 'url' -} - -/** input type for updating data in table "test" */ -export type Test_Set_Input = { - date?: InputMaybe; - id?: InputMaybe; - title?: InputMaybe; - url?: InputMaybe; -}; - -/** aggregate stddev on columns */ -export type Test_Stddev_Fields = { - __typename?: 'test_stddev_fields'; - id?: Maybe; -}; - -/** aggregate stddev_pop on columns */ -export type Test_Stddev_Pop_Fields = { - __typename?: 'test_stddev_pop_fields'; - id?: Maybe; -}; - -/** aggregate stddev_samp on columns */ -export type Test_Stddev_Samp_Fields = { - __typename?: 'test_stddev_samp_fields'; - id?: Maybe; -}; - -/** aggregate sum on columns */ -export type Test_Sum_Fields = { - __typename?: 'test_sum_fields'; - id?: Maybe; -}; - -/** update columns of table "test" */ -export enum Test_Update_Column { - /** column name */ - Date = 'date', - /** column name */ - Id = 'id', - /** column name */ - Title = 'title', - /** column name */ - Url = 'url' -} - -/** aggregate var_pop on columns */ -export type Test_Var_Pop_Fields = { - __typename?: 'test_var_pop_fields'; - id?: Maybe; -}; - -/** aggregate var_samp on columns */ -export type Test_Var_Samp_Fields = { - __typename?: 'test_var_samp_fields'; - id?: Maybe; -}; - -/** aggregate variance on columns */ -export type Test_Variance_Fields = { - __typename?: 'test_variance_fields'; - id?: Maybe; -}; - /** Boolean expression to compare columns of type "timestamptz". All fields are combined with logical 'AND'. */ export type Timestamptz_Comparison_Exp = { _eq?: InputMaybe; @@ -13035,6 +12727,13 @@ export type GetContestInfoQueryVariables = Exact<{ export type GetContestInfoQuery = { __typename?: 'query_root', contest_by_pk?: { __typename?: 'contest', contest_name: string, name: string, description?: string | null, start_date: any, end_date: any, status: string } | null }; +export type GetContestNameQueryVariables = Exact<{ + contest_id: Scalars['uuid']['input']; +}>; + + +export type GetContestNameQuery = { __typename?: 'query_root', contest_by_pk?: { __typename?: 'contest', name: string } | null }; + export type GetContestSwitchSubscriptionVariables = Exact<{ contest_id: Scalars['uuid']['input']; }>; @@ -14155,6 +13854,46 @@ export type GetContestInfoQueryHookResult = ReturnType; export type GetContestInfoSuspenseQueryHookResult = ReturnType; export type GetContestInfoQueryResult = Apollo.QueryResult; +export const GetContestNameDocument = gql` + query GetContestName($contest_id: uuid!) { + contest_by_pk(id: $contest_id) { + name + } +} + `; + +/** + * __useGetContestNameQuery__ + * + * To run a query within a React component, call `useGetContestNameQuery` and pass it any options that fit your needs. + * When your component renders, `useGetContestNameQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useGetContestNameQuery({ + * variables: { + * contest_id: // value for 'contest_id' + * }, + * }); + */ +export function useGetContestNameQuery(baseOptions: Apollo.QueryHookOptions & ({ variables: GetContestNameQueryVariables; skip?: boolean; } | { skip: boolean; }) ) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(GetContestNameDocument, options); + } +export function useGetContestNameLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(GetContestNameDocument, options); + } +export function useGetContestNameSuspenseQuery(baseOptions?: Apollo.SuspenseQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useSuspenseQuery(GetContestNameDocument, options); + } +export type GetContestNameQueryHookResult = ReturnType; +export type GetContestNameLazyQueryHookResult = ReturnType; +export type GetContestNameSuspenseQueryHookResult = ReturnType; +export type GetContestNameQueryResult = Apollo.QueryResult; export const GetContestSwitchDocument = gql` subscription GetContestSwitch($contest_id: uuid!) { contest_by_pk(id: $contest_id) { diff --git a/src/graphql/contest/index.graphql b/src/graphql/contest/index.graphql index 420d19f87..f54046648 100644 --- a/src/graphql/contest/index.graphql +++ b/src/graphql/contest/index.graphql @@ -102,6 +102,12 @@ query GetContestInfo($contest_id: uuid!) { } } +query GetContestName($contest_id: uuid!) { + contest_by_pk(id: $contest_id) { + name + } +} + subscription GetContestSwitch($contest_id: uuid!) { contest_by_pk(id: $contest_id) { code_upload_switch