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

migrate to labels for search fields #262

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 2 additions & 11 deletions app/live/live.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,9 @@ export const Live = ({
)}
<Row className="g-3 my-3">
<div className="input-group mw-search">
<span
className="input-group-text"
onClick={() => {
const searchElement =
document.getElementById("gameSearch");
if (document.activeElement !== searchElement) {
searchElement.focus();
}
}}
>
<label className="input-group-text" htmlFor="gameSearch">
<SearchIcon size={18} />
</span>
</label>
<input
type="search"
className="form-control"
Expand Down
17 changes: 3 additions & 14 deletions app/tournaments/[tournament]/combined-tournament.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,12 @@ export const CombinedTournament = ({

<div className="d-flex justify-content-center">
<div className="mb-3 input-group">
<span
<label
htmlFor="gameSearch"
className="input-group-text"
onClick={() => {
const searchElement =
document.getElementById(
"gameSearch",
);
if (
document.activeElement !==
searchElement
) {
searchElement.focus();
}
}}
>
<SearchIcon size={18} />
</span>
</label>
<input
type="search"
className="form-control"
Expand Down
19 changes: 4 additions & 15 deletions app/tournaments/[tournament]/tournament.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React, { createRef, useCallback, useEffect, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { Card, Col, Row, Tab, Tabs } from "react-bootstrap";
import { LiveUserRun } from "~src/components/live/live-user-run";
import { RecommendedStream } from "~src/components/live/recommended-stream";
Expand Down Expand Up @@ -56,8 +56,6 @@ export const GenericTournament = ({

const [loadingUserData, setLoadingUserData] = useState(true);

const gameSearchRef = createRef<HTMLInputElement>();

const handleSortChange: React.ChangeEventHandler<HTMLSelectElement> =
useCallback(
(event) => {
Expand Down Expand Up @@ -340,22 +338,13 @@ export const GenericTournament = ({
</Col>
<Col md={8} className="mb-4">
<div className="input-group">
<span
<label
className="input-group-text"
onClick={() => {
if (
gameSearchRef.current &&
document.activeElement !==
gameSearchRef.current
) {
gameSearchRef.current.focus();
}
}}
htmlFor="gameSearch"
>
<SearchIcon size={18} />
</span>
</label>
<input
ref={gameSearchRef}
type="search"
className="form-control"
placeholder="Filter by user"
Expand Down
14 changes: 3 additions & 11 deletions src/components/game/category-leaderboards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,12 @@ export const CategoryLeaderboards = ({
<Col lg={9} md={8}>
<div className="d-flex justify-content-center">
<div className="mb-3 input-group game-filter-mw">
<span
<label
className="input-group-text"
onClick={() => {
const searchElement =
document.getElementById("gameSearch");
if (
document.activeElement !== searchElement
) {
searchElement.focus();
}
}}
htmlFor="gameSearch"
>
<SearchIcon size={18} />
</span>
</label>
<input
type="search"
className="form-control"
Expand Down
14 changes: 3 additions & 11 deletions src/components/game/game-leaderboards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,12 @@ export const GameLeaderboards = ({
<Col lg={9} md={8}>
<div className="d-flex justify-content-center">
<div className="mb-3 input-group game-filter-mw">
<span
<label
htmlFor="gameSearch"
className="input-group-text"
onClick={() => {
const searchElement =
document.getElementById("gameSearch");
if (
document.activeElement !== searchElement
) {
searchElement.focus();
}
}}
>
<SearchIcon size={18} />
</span>
</label>
<input
type="search"
className="form-control"
Expand Down
1 change: 1 addition & 0 deletions src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface LayoutInput {
picture?: string;
}

// TODO: Move this to `scripts.tsx`
const themeInitializerScript = `
(function () {
document.documentElement.dataset.bsTheme = window.localStorage.getItem("theme") || "light";
Expand Down
1 change: 1 addition & 0 deletions src/components/live/splits-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const SplitsViewer = ({
</Row>
<hr className="border-bottom m-0" />
<div
// TODO: expose this via forwardRef
id="scrollBox"
className="bg-body-secondary overflow-y-auto h-55 w-100"
>
Expand Down
16 changes: 3 additions & 13 deletions src/components/pagination/pagination-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,20 @@ import { Search as SearchIcon } from "react-bootstrap-icons";
export const PaginationSearch = ({ text }: { text: string }) => {
const { search, setSearch } = useContext(PaginationContext);

const searchInputRef = React.useRef<HTMLInputElement>(null);

return (
<div className="input-group game-filter-mw">
<span
className="input-group-text"
onClick={() => {
if (document.activeElement !== searchInputRef.current) {
searchInputRef.current?.focus();
}
}}
>
<label className="input-group-text" htmlFor="pagination-search">
<SearchIcon size={18} />
</span>
</label>
<input
type="search"
className="form-control"
placeholder={text}
onChange={(e) => {
setSearch(e.target.value);
}}
ref={searchInputRef}
value={search}
id="gameSearch"
id="pagination-search"
/>
</div>
);
Expand Down
19 changes: 3 additions & 16 deletions src/components/search/use-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,22 @@ export const useSearch = () => {
export const RenderSearch = () => {
const { search, setSearch } = useContext(PaginationContext);

const searchInputRef = React.useRef<HTMLInputElement>(null);

return (
<div>
<div className="d-flex justify-content-start">
<div className="mb-3 input-group">
<span
className="input-group-text"
onClick={() => {
if (
document.activeElement !==
searchInputRef.current
) {
searchInputRef.current?.focus();
}
}}
>
<label className="input-group-text" htmlFor="race-search">
<SearchIcon size={18} />
</span>
</label>
<input
type="search"
className="form-control"
placeholder="Filter by game/category/user"
onChange={(e) => {
setSearch(e.target.value);
}}
ref={searchInputRef}
value={search}
id="gameSearch"
id="race-search"
/>
</div>
</div>
Expand Down
12 changes: 3 additions & 9 deletions src/components/tournament/tournament-runs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,12 @@ export const TournamentRuns: React.FunctionComponent<TournamentRunsProps> = ({
<h2>Tournament runs</h2>
<div className="d-flex justify-content-start mb-1">
<div className="mb-3 input-group game-filter-mw">
<span
<label
className="input-group-text"
onClick={() => {
const searchElement =
document.getElementById("gameSearch");
if (document.activeElement !== search) {
searchElement.focus();
}
}}
htmlFor="tournamentRunSearch"
>
<SearchIcon size={18} />
</span>
</label>
<input
type="search"
className="form-control"
Expand Down
3 changes: 2 additions & 1 deletion src/styles/_globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ body {

.input-group,
.form-select,
.cursor-pointer {
.cursor-pointer,
label.input-group-text {
cursor: pointer;
}

Expand Down
Loading