From 1eba3e43e71e29ed57653072bb7a6c8bd2e3b2bc Mon Sep 17 00:00:00 2001 From: monoid Date: Thu, 28 Apr 2022 00:01:41 +0900 Subject: [PATCH] simple search --- src/client/app.tsx | 5 +- src/client/component/contentinfo.tsx | 1 - src/client/component/headline.tsx | 22 +++++-- src/client/page/contentinfo.tsx | 85 ++++++++++++++++++++-------- src/client/page/gallery.tsx | 3 +- src/client/page/reader/comic.tsx | 2 +- src/db/doc.ts | 6 +- 7 files changed, 89 insertions(+), 35 deletions(-) diff --git a/src/client/app.tsx b/src/client/app.tsx index 5d0886c..7e39b92 100644 --- a/src/client/app.tsx +++ b/src/client/app.tsx @@ -1,7 +1,7 @@ import React, { createContext, useEffect, useRef, useState } from 'react'; import ReactDom from 'react-dom'; import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'; -import { Gallery, DocumentAbout, LoginPage, NotFoundPage, ProfilePage, DifferencePage, SettingPage } from './page/mod'; +import { Gallery, DocumentAbout, LoginPage, NotFoundPage, ProfilePage, DifferencePage, SettingPage, ReaderPage } from './page/mod'; import { getInitialValue, UserContext } from './state'; import { ThemeProvider, createTheme } from '@mui/material'; @@ -32,7 +32,8 @@ const App = () => { } /> } /> - }> + }> + }> } /> }> }> diff --git a/src/client/component/contentinfo.tsx b/src/client/component/contentinfo.tsx index db19935..77e3f17 100644 --- a/src/client/component/contentinfo.tsx +++ b/src/client/component/contentinfo.tsx @@ -83,7 +83,6 @@ export const ContentInfo = (props: { //const classes = useStyles(); const theme = useTheme(); const document = props.document; - const propclasses = props.classes ?? {}; /*const rootName = props.short ? classes.short_root : classes.root; const thumbnail_anchor = props.short ? classes.short_thumbnail_anchor : ""; const thumbnail_content = props.short ? classes.short_thumbnail_content : diff --git a/src/client/component/headline.tsx b/src/client/component/headline.tsx index 295be22..bb7586d 100644 --- a/src/client/component/headline.tsx +++ b/src/client/component/headline.tsx @@ -9,7 +9,7 @@ import { ChevronLeft, ChevronRight, Menu as MenuIcon, Search as SearchIcon, AccountCircle } from '@mui/icons-material'; -import { Link as RouterLink } from 'react-router-dom'; +import { Link as RouterLink, useNavigate } from 'react-router-dom'; import { doLogout, UserContext } from '../state'; const drawerWidth = 270; @@ -80,6 +80,8 @@ export const Headline = (prop: { const menuId = 'primary-search-account-menu'; const user_ctx = useContext(UserContext); const isLogin = user_ctx.username !== ""; + const navigate = useNavigate(); + const [search, setSearch] = useState(""); const renderProfileMenu = ( - + navigate(`/search?word=${encodeURIComponent(search)}`)} /> - + setSearch(e.target.value)} + onKeyUp={(e) => { + if (e.key === "Enter") { + let words = search.includes("&") ? search.split("&") : [search]; + words = words.map(w => w.trim()) + .map(w => w.includes(":") ? + `allow_tag=${w}` + : `word=${encodeURIComponent(w)}`); + navigate(`/search?${words.join("&")}`); + } + }} + value={search}> { isLogin ? @@ -159,7 +173,7 @@ export const Headline = (prop: { {renderProfileMenu} -