diff --git a/client/app/App.css b/client/app/App.css index 1852faca..651ac9be 100644 --- a/client/app/App.css +++ b/client/app/App.css @@ -124,11 +124,7 @@ h2 { margin-top: var(--margin_top); } -p { - font-size: 1.25em; - letter-spacing: .05em; - margin: calc(var(--margin_top) / 2) 0 calc(var(--margin_bottom) * 2) -} + .explore-form-row { align-items: stretch; @@ -185,6 +181,72 @@ button.btn:hover { position: relative; } +.arrow-right, +.arrow-left { + background: var(--theme_color); + display: inline-flex; + height: 2px; + position: relative; + vertical-align: middle; + width: 24px; +} + +.arrow-right { + margin-left: 4px; +} + +.arrow-left { + margin-right: 4px; +} + + .arrow-right::before, + .arrow-right::after, + .arrow-left::before, + .arrow-left::after { + background: var(--theme_color); + content: ""; + height: 2px; + position: absolute; + transform-origin: 50% 50%; + width: 10px; + } + + .arrow-right::before, + .arrow-right::after { + right: -3px; + } + + .arrow-left::before, + .arrow-left::after { + left: -3px; + } + + .arrow-right::before, + .arrow-left::before { + top: -3px; + } + + .arrow-right::before { + transform: rotate(45deg); + } + + .arrow-left::before { + transform: rotate(-45deg); + } + + .arrow-right::after, + .arrow-left::after { + bottom: -3px; + } + + .arrow-right::after { + transform: rotate(-45deg); + } + + .arrow-left::after { + transform: rotate(45deg); + } + button.btn .arrow-right, button.btn .arrow-right::before, button.btn .arrow-right::after { @@ -225,6 +287,7 @@ button.btn:hover .arrow-right::after { padding-left: 40%; text-transform: uppercase; text-align: left; + margin: var(--margin_top) auto; } @media (min-width: 64em) { @@ -241,7 +304,7 @@ button.btn:hover .arrow-right::after { margin: 0; } -main.content-wrapper div.container { +main.content-wrapper div.welcome-container { min-width: 100vw; max-width: 100vw; margin: 0; diff --git a/client/app/components/checkbox.css b/client/app/components/checkbox.css new file mode 100644 index 00000000..6d1c92ac --- /dev/null +++ b/client/app/components/checkbox.css @@ -0,0 +1,35 @@ +.checkbox-control { + display: inline-block; + position: relative; +} + +.checkbox-input { + height: 16px; + left: 0; + margin: 0; + opacity: 0; + position: absolute; + top: 50%; + transform: translateY(-50%); + width: 16px; + z-index: 1; +} + +.checkbox-input:checked ~ label { + background-color: var(--secondary_a); +} + +.checkbox-input:focus-visible + .checkbox-label { + outline: 2px solid var(--secondary_a); + outline-offset: 2px; +} + +.checkbox-label { + background: var(--white); + border: 2px solid var(--secondary_a); + display: inline-block; + margin-bottom: 2px; + margin-right: 4px; + padding: 6px; + vertical-align: middle; +} \ No newline at end of file diff --git a/client/app/components/checkbox.tsx b/client/app/components/checkbox.tsx index ca3873dc..09241eda 100644 --- a/client/app/components/checkbox.tsx +++ b/client/app/components/checkbox.tsx @@ -1,3 +1,5 @@ +import './checkbox.css'; + const Checkbox = ({ label, onChange, @@ -8,15 +10,17 @@ const Checkbox = ({ checked: boolean; }) => { return ( -
+ onChange()} checked={checked} + aria-label={label} id={`check-${label.toLowerCase()}`} + className="checkbox-input" /> - {label} -
+ {label} + ); }; diff --git a/client/app/components/header.tsx b/client/app/components/header.tsx index 97109d4d..5ac83ca4 100644 --- a/client/app/components/header.tsx +++ b/client/app/components/header.tsx @@ -1,9 +1,10 @@ import React from "react"; import { Link } from "react-router"; import LoginModal from "./login-modal"; -import "./header.css"; import { useLogin } from "../context/loginContext"; +import "./header.css"; + export type HeaderProps = { projIcons: { logo: string; diff --git a/client/app/components/search-input.css b/client/app/components/search-input.css new file mode 100644 index 00000000..f9692553 --- /dev/null +++ b/client/app/components/search-input.css @@ -0,0 +1,44 @@ +.query-input-group { + position: relative; +} + +.query-input-group.has-submit-button::after { + background: var(--secondary_a); + content: ""; + height: 2em; + position: absolute; + right: 6em; + top: 0.625em; + width: 1px; +} + +#query-form-submit { + height: 100%; + opacity: 0; + pointer-events: all; + position: absolute; + right: 0; + top: 0; + width: 5em; + z-index: 9; +} + +.query-input-group:has(#query-form-submit:focus-visible) { + outline: 2px solid var(--secondary_a); + outline-offset: 2px; + border-radius: 2em; +} + +#search-icon-label { + border-color: var(--secondary_a); + border-radius: 2em 0 0 2em; + border-right: none; + border-width: 2px; + background: var(--white); + padding: 0.375rem 1.125rem; +} + +#search-text { + border-radius: 0 2em 2em 0; + border-left: none; +} diff --git a/client/app/components/search-input.tsx b/client/app/components/search-input.tsx new file mode 100644 index 00000000..ba3684c2 --- /dev/null +++ b/client/app/components/search-input.tsx @@ -0,0 +1,59 @@ +import './search-input.css'; + +type SearchInputProps = { + onInputChange: (query: string) => void; + placeholder: string; + submitValue: string; + showSubmitButton: boolean; + value?: string; +}; + +const SearchInput: React.FC = ({ + onInputChange, + placeholder, + submitValue, + showSubmitButton, + value, +}) => { + return ( +
+ + + + + + + onInputChange(e.target.value)} + value={value} + /> + {showSubmitButton && } + +
+ ); +}; + +export default SearchInput; diff --git a/client/app/context/action.ts b/client/app/context/action.ts index 4ddadd3c..8cfccd73 100644 --- a/client/app/context/action.ts +++ b/client/app/context/action.ts @@ -1,5 +1,6 @@ import axios from "axios"; import { primeCsrf, tekdbApi } from "../api/tekdbApi"; +import type { FilterCategories } from "../types"; export type LoginState = { success?: boolean; @@ -56,7 +57,7 @@ export const submitLoginAction = async ( } }; -export const submitSearchAction = async ({ categories, query }: { categories: string[], query: string }) => { +export const submitSearchAction = async ({ categories, query }: { categories: FilterCategories[], query: string }) => { const params = new URLSearchParams({ query }); categories.forEach((category) => params.append("category", category)); diff --git a/client/app/context/searchContext.tsx b/client/app/context/searchContext.tsx index 6d634690..fdd97bcb 100644 --- a/client/app/context/searchContext.tsx +++ b/client/app/context/searchContext.tsx @@ -1,18 +1,28 @@ -import React, { useCallback, use } from "react"; +import React, { + createContext, + useCallback, + use, + useState, +} from "react"; import type { ReactNode } from "react"; +import {useLocation} from "react-router"; +import type { FilterCategories, Result } from "../types"; import { useNavigate } from "react-router"; import { submitSearchAction } from "./action"; +import { CATEGORIES } from "../types"; type useSearch = { - categories: string[]; - results: any[]; + categories: FilterCategories[]; + results: Result[]; query: string; - handleCategoryTypeChange: (type: string) => void; - handleSearch: (formData: FormData) => Promise; + searchedQuery: string; + handleCategoryTypeChange: (type: FilterCategories) => void; + handleSearch: () => Promise; handleQueryChange: (query: string) => void; + handleCategoryAndSearch: (type: FilterCategories) => void; }; -const SearchContext = React.createContext(null); +const SearchContext = createContext(null); interface SearchProviderProps { children: ReactNode; @@ -20,18 +30,22 @@ interface SearchProviderProps { export const SearchProvider: React.FC = ({ children }) => { const navigate = useNavigate(); - const [categories, setCategories] = React.useState([]); - const [results, setResults] = React.useState([]); - const [query, setQuery] = React.useState(""); + const location = useLocation(); + const [categories, setCategories] = useState(CATEGORIES); + const [results, setResults] = useState([]); + const [query, setQuery] = useState(""); // search query input by the user + const [searchedQuery, setSearchedQuery] = useState(""); // the executed searched query const handleCategoryTypeChange = useCallback( - (type: string) => { + (type: FilterCategories) => { if (categories.includes(type)) { setCategories( - categories.filter((category: string) => category !== type), + categories.filter((category: FilterCategories) => category !== type), ); + return categories.filter((category: FilterCategories) => category !== type); } else { setCategories([...categories, type]); + return [...categories, type]; } }, [categories], @@ -41,24 +55,40 @@ export const SearchProvider: React.FC = ({ children }) => { setQuery(query); }, []); - const handleSearch = useCallback(async () => { + const handleSearch = useCallback(async (categoriesToSearch?: FilterCategories[]) => { try { - const response = await submitSearchAction({ categories, query }); + const response = await submitSearchAction({ categories: categoriesToSearch ?? categories, query }); const { results } = response; setResults(results); - await navigate("/search"); + setSearchedQuery(query); // update the executed searched query + if (location.pathname !== "/search") { + await navigate("/search"); + } } catch (error) { console.error("Search failed", error); } - }, [categories, query, navigate]); + }, [categories, query, location]); + const handleCategoryAndSearch = useCallback( + (category: FilterCategories) => { + const newCategories = categories.includes(category) + ? categories.filter((c: FilterCategories) => c !== category) + : [...categories, category]; + handleSearch(newCategories); + handleCategoryTypeChange(category); + }, + [categories, handleSearch, handleCategoryTypeChange] + ); + const value = { categories, results, query, - handleCategoryTypeChange, + searchedQuery, + handleCategoryAndSearch, handleSearch, handleQueryChange, + handleCategoryTypeChange, }; return {children}; }; diff --git a/client/app/index.css b/client/app/index.css index 5fd97966..b0459c5a 100644 --- a/client/app/index.css +++ b/client/app/index.css @@ -125,39 +125,21 @@ h2 { margin-top: var(--margin_top); } -p { - font-size: 1.25em; - letter-spacing: .05em; - margin: calc(var(--margin_top) / 2) 0 calc(var(--margin_bottom) * 2) -} - .explore-form-row { align-items: stretch; flex-direction: row; } -.explore-form-row > div { - /* width: 100%; */ -} .explore-form { margin-top: calc(var(--margin_top) * 2); } -.explore-input-group { - /* margin: var(--margin_top) 0 calc(var(--margin_bottom) * 2); */ - padding: 0 10%; -} - hr { font-size: 1.25em; margin: calc(var(--margin_top) * 2) 0 calc(var(--margin_bottom) * 2); } -.explore-form .btn { - /* border: 1px solid var(--primary_d): */ - /* position: relative; */ -} .button-wrapper { /* justify-content: ; */ @@ -375,11 +357,6 @@ main { min-height: calc(100vh - 96px); } - -main[data-theme="dark"] { - /* background: var(--black); */ -} - main[data-theme="light"] { background: var(--white); --btn_border: 2px solid var(--black); @@ -542,19 +519,6 @@ h5 { background: var(--white); } -#search-icon-label { - border-color: var(--secondary_a); - border-radius: 2em 0 0 2em; - border-right: none; - border-width: 2px; - background: var(--white); - padding: .375rem 1.125rem; -} - -#search-text { - border-radius: 0 2em 2em 0; - border-left: none; -} #export-links { @@ -570,16 +534,6 @@ h5 { text-align: right; } -.query-input-group::after { - background: var(--secondary_a); - content: ''; - height: 2em; - position: absolute; - right: 6em; - top: .625em; - width: 1px; -} - .arrow-right.search-arrow, .arrow-right.search-arrow::before, .arrow-right.search-arrow::after { @@ -593,21 +547,6 @@ h5 { pointer-events: none; } -.query-input-group { - position: relative; -} - -#query-form-submit { - height: 100%; - opacity: 0; - pointer-events: all; - position: absolute; - right: 0; - top: 0; - width: 5em; - z-index: 9; -} - /* Filter Category Checkboxs */ #filter-checkboxes { margin: var(--margin_top) auto; diff --git a/client/app/routes/explore.tsx b/client/app/routes/explore.tsx index 8dbee053..d6455c06 100644 --- a/client/app/routes/explore.tsx +++ b/client/app/routes/explore.tsx @@ -1,7 +1,8 @@ -import React from "react"; +import React, {useEffect} from "react"; import { useSearch } from "../context/searchContext"; import Checkbox from "../components/checkbox"; -import { CATEGORIES } from "../utils/constants"; +import SearchInput from "../components/search-input"; +import { CATEGORIES } from "../types"; import "./explore.css"; @@ -11,16 +12,20 @@ const ExploreRoute: React.FC = () => { handleSearch, handleQueryChange, categories, - query, } = useSearch(); + // clear the search query on component mount + useEffect(() => { + handleQueryChange(""); + }, []) + const onSubmit = (e: React.FormEvent) => { e.preventDefault(); - handleSearch(new FormData(e.currentTarget)); + handleSearch(); }; return ( -
+
@@ -41,49 +46,14 @@ const ExploreRoute: React.FC = () => {

-
- - - - - - - + handleQueryChange(e.target.value)} + submitValue="GO" + showSubmitButton={false} /> -
- -
{

Categories:

{CATEGORIES.map((category) => ( - handleCategoryTypeChange(category)} - /> +
+ handleCategoryTypeChange(category)} + /> +
))}
diff --git a/client/app/routes/search.css b/client/app/routes/search.css new file mode 100644 index 00000000..36f82158 --- /dev/null +++ b/client/app/routes/search.css @@ -0,0 +1,52 @@ +.category-name-col { + color: var(--secondary_a) !important; + font-size: 0.75em; + font-weight: bold; + text-transform: uppercase; +} + +.explore-form { + margin-top: calc(var(--margin_top) * 2); +} + +#search-icon-label { + border-color: var(--secondary_a); + border-radius: 2em 0 0 2em; + border-right: none; + border-width: 2px; + background: var(--white); + padding: .375rem 1.125rem; +} + +.form-center { + text-align: center; +} + +input[type="text"], +.form-control, +input[type="password"] { + background: var(--white); + border-color: var(--secondary_a); + border-radius: 2em; + border-width: 2px; + font-size: 1.125em; + line-height: 2; +} + +.arrow-right.search-arrow, +.arrow-right.search-arrow::before, +.arrow-right.search-arrow::after { + background: var(--primary_a); +} + +.arrow-right.search-arrow { + position: absolute; + right: 2.5em; + top: 1.5625em; + pointer-events: none; +} + + +.highlight { + background-color: yellow; +} diff --git a/client/app/routes/search.tsx b/client/app/routes/search.tsx index 28ff8191..398de126 100644 --- a/client/app/routes/search.tsx +++ b/client/app/routes/search.tsx @@ -1,62 +1,214 @@ -import React from "react"; +import React, { useMemo, useCallback } from "react"; +import { + createColumnHelper, + tableFeatures, + rowPaginationFeature, + createPaginatedRowModel, + useTable, + metaHelper, +} from "@tanstack/react-table"; +import { Table as BTable } from "react-bootstrap"; + import { useSearch } from "../context/searchContext"; import Checkbox from "../components/checkbox"; -import { CATEGORIES } from "../utils/constants"; +import SearchInput from "../components/search-input"; +import { CATEGORIES } from "../types"; +import type { Result } from "../types"; + +import "./search.css"; + +interface ColumnMeta { + className?: string; +} + +const features = tableFeatures({ + rowPaginationFeature, + paginatedRowModel: createPaginatedRowModel(), + columnMeta: metaHelper(), +}); + +const columnHelper = createColumnHelper(); + +const Table: React.FC<{ data: Result[]; columns: any[] }> = ({ + data, + columns, +}) => { + const table = useTable( + { + features, + columns, + data, + initialState: { pagination: { pageIndex: 0, pageSize: 25 } }, + debugTable: false, + }, + (state) => state, // default selector + ); + return ( +
+
+ + + + + +
Page
+ + {(table.state.pagination.pageIndex + 1).toLocaleString()} of{" "} + {table.getPageCount().toLocaleString()} + +
+
+ + + + Category + Name + Description + Search snippet + + + + {table.getRowModel().rows.map((row) => { + return ( + console.log(row.original.link)}> + {row.getAllCells().map((cell) => { + return ( + + + + ); + })} + + ); + })} + + +
+ + + + + +
Page
+ + {(table.state.pagination.pageIndex + 1).toLocaleString()} of{" "} + {table.getPageCount().toLocaleString()} + +
+
+
+ ); +}; const SearchRoute: React.FC = () => { const { - handleCategoryTypeChange, + handleCategoryAndSearch, handleSearch, handleQueryChange, categories, results, query, + searchedQuery, } = useSearch(); - const onSubmit = (e: React.FormEvent) => { - e.preventDefault(); - handleSearch(new FormData(e.currentTarget)); - }; + const onSubmit = useCallback( + (e: React.FormEvent) => { + e.preventDefault(); + handleSearch(); + }, + [handleSearch], + ); + + const columns = useMemo(() => { + return columnHelper.columns([ + columnHelper.accessor("category_name", { + cell: (info) => info.getValue(), + meta: { + className: "category-name-col", + }, + }), + columnHelper.accessor("name", { + cell: (info) => info.getValue(), + }), + columnHelper.accessor("description", { + cell: (info) => ( + + ), + }), + columnHelper.accessor("headline", { + cell: (info) => ( + + ), + }), + ]); + }, []); + return ( -
-
+
+
-
- - - - - - - handleQueryChange(e.target.value)} - value={query} - /> - +
+
+ +
@@ -65,15 +217,57 @@ const SearchRoute: React.FC = () => {

Filter By:

{CATEGORIES.map((category) => ( - handleCategoryTypeChange(category)} - /> +
+ handleCategoryAndSearch(category)} + /> +
))}
+
+
+
+
+ + Results: {results.length} + + {searchedQuery + ? ` Results for "${searchedQuery}"` + : " Results"} + + +
+
+ +
+
+
+
+
+
+ + + ); }; diff --git a/client/app/routes/welcome.css b/client/app/routes/welcome.css new file mode 100644 index 00000000..a0c7fc7e --- /dev/null +++ b/client/app/routes/welcome.css @@ -0,0 +1,5 @@ +p { + font-size: 1.25em; + letter-spacing: .05em; + margin: calc(var(--margin_top) / 2) 0 calc(var(--margin_bottom) * 2) +} \ No newline at end of file diff --git a/client/app/routes/welcome.tsx b/client/app/routes/welcome.tsx index 07961522..dd6a79f7 100644 --- a/client/app/routes/welcome.tsx +++ b/client/app/routes/welcome.tsx @@ -1,13 +1,15 @@ import { usePageContentAndSiteInfo } from "../api/pageContent"; import { useLogin } from "../context/loginContext"; +import "./welcome.css"; + const WelcomePage: React.FC = () => { const { pageContent, siteInfo } = usePageContentAndSiteInfo(); const { loginForm, setShowLoginModal } = useLogin(); const isAuthenticated = loginForm.isAuthenticated; return ( -
+
=20" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": ">=18" + } + }, + "node_modules/@tanstack/store": { + "version": "0.11.2", + "resolved": "https://registry.npmjs.org/@tanstack/store/-/store-0.11.2.tgz", + "integrity": "sha512-sJ4mjol8uQsHV0gOJzzjwXfh2Fwm+Sz0+8deqiTm4jGbMdjzNSW+xZCFm0kUa870uhd8yi+DpKnZb5Kc4apa0Q==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tanstack/table-core": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/@tanstack/table-core/-/table-core-9.3.1.tgz", + "integrity": "sha512-zQvlxSNi2qGM3L4jh85Z6hqMfdIR5qOfD9KHOU32nuKFJGN0RlJ7UvV1lsPb1fPVhpFYI0VP3jJGxLdLDpTKjQ==", + "license": "MIT", + "dependencies": { + "@tanstack/store": "^0.11.2" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", @@ -4195,6 +4260,15 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.7.0.tgz", + "integrity": "sha512-6L+EeigHMQhdaIPNIFUKwfWJSwWFQ8gJbJ2DLOs5sDIegTwR9fRxvnM3uciHKjIZhFz+KAv2emhWMRvDmMcY8A==", + "license": "MIT", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/valibot": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/valibot/-/valibot-1.2.0.tgz", diff --git a/client/package.json b/client/package.json index 5e1b0968..4de9f662 100644 --- a/client/package.json +++ b/client/package.json @@ -12,6 +12,7 @@ "dependencies": { "@react-router/dev": "^7.11.0", "@react-router/node": "^7.11.0", + "@tanstack/react-table": "^9.3.1", "axios": "^1.13.2", "bootstrap": "^5.3.8", "isbot": "^5",