Skip to content

Commit

Permalink
Merge commit '8d8a88a1e2cdec5e9c267f58deb284b3cb2229a7' into new_user…
Browse files Browse the repository at this point in the history
…_streams
  • Loading branch information
GreenAsJade committed Feb 22, 2024
2 parents ab87fd7 + 8d8a88a commit f3be8be
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/Player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface PlayerObjectType {
export interface PlayerProperties {
icon?: boolean;
iconSize?: number;
user: number | PlayerObjectType;
user?: number | PlayerObjectType;
historical?: PlayerObjectType;
flag?: boolean;
rank?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/report_manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { browserHistory } from "ogsHistory";
import { get, post } from "requests";
import { MODERATOR_POWERS } from "moderation";

const DONT_OFFER_COMMUNITY_MODERATION_TYPES_TO_MODERATORS = false;
const DONT_OFFER_COMMUNITY_MODERATION_TYPES_TO_MODERATORS = true;

interface Vote {
voter_id: number;
Expand Down
6 changes: 5 additions & 1 deletion src/views/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export function Settings(): JSX.Element {
</h2>

<div id="SettingsContainer">
{/* Desktop selector - mobile below */}
<SettingsGroupSelector>
{groups
.filter(
Expand All @@ -227,14 +228,17 @@ export function Settings(): JSX.Element {
))}
</SettingsGroupSelector>

{/* Mobile selector - desktop above */}
<Select
id="SettingsGroupDropdown"
className="settings-group-option-select"
classNamePrefix="ogs-react-select"
value={groups.filter((opt) => opt.key === selected)[0]}
getOptionValue={(data) => data.key}
onChange={(data: any) => select(data.key)}
options={groups.filter((x) => x.key !== "moderator" || user.is_moderator)}
options={groups.filter(
(x) => x.key !== "moderator" || user.is_moderator || user.moderator_powers,
)}
isClearable={false}
isSearchable={false}
blurInputOnSelect={true}
Expand Down
76 changes: 61 additions & 15 deletions src/views/Tournament/Tournament.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,26 @@ interface TournamentPlayers {
[k: string]: TournamentPlayer;
}

interface Round {
matches: Array<{
result: string;
black: number;
white: number;
player?: { id: number };
opponent?: object;
}>;
byes: number[];
groupify?: boolean;
}

interface TournamentSettings {
lower_bar: string;
upper_bar: string;
num_rounds: string;
group_size: string;
maximum_players: number | string;
active_round?: number;
"opengotha-staged-games"?: { [key: number]: { [key: string]: unknown } };
}
interface TournamentInterface {
id?: number;
Expand Down Expand Up @@ -224,11 +237,11 @@ export function Tournament(): JSX.Element {
const use_elimination_trees = is_elimination(tournament.tournament_type);

const players: TournamentPlayers = raw_players === null ? {} : raw_players;
const rounds = React.useMemo<any[]>(
const rounds = React.useMemo<Round[]>(
() => (loading ? [] : computeRounds(raw_rounds, players, tournament.tournament_type)),
[tournament.tournament_type, raw_rounds, players, loading],
);
const sorted_players = React.useMemo<any[]>(
const sorted_players = React.useMemo(
() =>
Object.keys(players)
.map((id) => players[id])
Expand Down Expand Up @@ -264,7 +277,12 @@ export function Tournament(): JSX.Element {
? explicitly_selected_round
: default_round;

const selected_round =
// Unfortunately, selected_round is used below in a way that TypeScript can't see that it's
// null or not. Hence, I am typing it "any" for now.
//
// TODO: extract the JSX that relies on non-null selected_round in into its own component,
// and do a proper non-null assertion once before mounting this component.
const selected_round: any =
typeof selected_round_idx === "number" && rounds && rounds.length > selected_round_idx
? rounds[selected_round_idx]
: null;
Expand Down Expand Up @@ -2396,13 +2414,13 @@ function compareUserRankWithPlayers(
return 0;
}
function computeRounds(
raw_rounds: any[],
raw_rounds: Round[],
players: { [id: string]: TournamentPlayer },
tournament_type: string,
) {
const compareUserRank = (a: TournamentPlayer, b: TournamentPlayer) =>
compareUserRankWithPlayers(a, b, players);
const linkPlayersToRoundMatches = (rounds: any, players: TournamentPlayers) => {
const linkPlayersToRoundMatches = (rounds: Round[], players: TournamentPlayers) => {
for (const round of rounds) {
if (!round.groupify) {
for (const match of round.matches) {
Expand Down Expand Up @@ -2597,7 +2615,12 @@ function computeRounds(
return rounds;
}

function OpenGothaRoster({ players }: { tournament: any; players: Array<any> }): JSX.Element {
function OpenGothaRoster({
players,
}: {
tournament: TournamentInterface;
players: TournamentPlayer[];
}): JSX.Element {
(window as any)["players"] = players;
players.sort((a, b) => a.username.localeCompare(b.username));
return (
Expand Down Expand Up @@ -2631,10 +2654,10 @@ function OpenGothaTournamentRound({
selectedRound,
rounds,
}: {
tournament: any;
tournament: TournamentInterface;
roundNotes: string;
selectedRound: number;
players: Array<any>;
players: TournamentPlayer[];
rounds: Array<any>;
}): JSX.Element {
//let [notes, _set_notes]:[string, (s) => void] = React.useState(tournament.settings[`notes-round-${selectedRound}`] || "");
Expand Down Expand Up @@ -3123,11 +3146,31 @@ function organizeEliminationBrackets(
}
}
}
function createEliminationNodes(rounds: any[]) {
let cur_bucket: any = {};
let last_cur_bucket: any = {};
const last_bucket: any = {};
const all_objects: any[] = [];

function createEliminationNodes(rounds: Round[]) {
// I apologize for the vague naming here. Please change to a better
// name if you have more familiarity with this code.
// -bpj
type ObjectType = {
black_src?: ObjectType | null;
white_src?: ObjectType | null;
bye_src?: ObjectType | null;
black_won?: boolean;
white_won?: boolean;
black_player?: number;
white_player?: number;
match?: Round["matches"][number];
second_bracket: boolean;
round: number;
is_final?: boolean;
parent?: ObjectType;
feeding_black?: boolean;
feeding_white?: boolean;
};
let cur_bucket: { [key: number]: ObjectType } = {};
let last_cur_bucket: { [key: number]: ObjectType } = {};
const last_bucket: { [key: number]: ObjectType } = {};
const all_objects: ObjectType[] = [];
for (let round_num = 0; round_num < rounds.length; ++round_num) {
const round = rounds[round_num];

Expand All @@ -3152,7 +3195,10 @@ function createEliminationNodes(rounds: any[]) {
}
if (obj.white_src) {
obj.white_src.parent = obj;
obj.black_src.feeding_white = true;
// Is this a bug? TypeScript complains because black_src
// can be null. Perhaps this should be white_src.feeding_white?
// -bpj
(obj.black_src as ObjectType).feeding_white = true;
}
all_objects.push(obj);

Expand Down Expand Up @@ -3210,7 +3256,7 @@ export function EliminationTree({
rounds,
players,
}: {
rounds: any[];
rounds: Round[];
players: TournamentPlayers;
}): JSX.Element | null {
const elimination_tree = React.useRef(
Expand Down

0 comments on commit f3be8be

Please sign in to comment.