diff --git a/components/onesearch/link.tsx b/components/onesearch/link.tsx index 888e98d..6820c9b 100644 --- a/components/onesearch/link.tsx +++ b/components/onesearch/link.tsx @@ -1,30 +1,30 @@ import { normalizeURL } from "lib/normalizeURL"; +import { useNavigate } from "react-router"; -export default function Link(props: { children: React.ReactNode; query: string; selected: boolean }) { - if (props.selected) { - return ( -
{ - window.open(normalizeURL(props.query)); - }} - > - {props.children} -
- ); - } - else { - return ( -
{ - window.open(normalizeURL(props.query)); - }} - > - {props.children} -
- ); - } +interface LinkSuggestionProps { + children: React.ReactNode; + query: string; + selected: boolean; + inPage?: boolean; +} + +export default function LinkSuggestion(props: LinkSuggestionProps) { + const className = props.selected + ? `w-full h-10 leading-10 bg-zinc-300 dark:bg-zinc-700 px-5 z-10 cursor-pointer duration-100` + : `w-full h-10 leading-10 bg-zinc-100 hover:bg-zinc-300 dark:bg-zinc-800 hover:dark:bg-zinc-700 px-5 z-10 cursor-pointer duration-100`; + const navigate = useNavigate(); + return ( +
{ + if (props.inPage) { + navigate(props.query); + } else { + window.open(normalizeURL(props.query)); + } + }} + > + {props.children} +
+ ); } diff --git a/components/onesearch/onesearch.tsx b/components/onesearch/onesearch.tsx index 0ca2576..f97f6de 100644 --- a/components/onesearch/onesearch.tsx +++ b/components/onesearch/onesearch.tsx @@ -6,7 +6,7 @@ import getSearchEngineName from "lib/onesearch/getSearchEngineName"; import PlainSearch from "./plainSearch"; import { suggestionAtom } from "lib/state/suggestion"; import validLink from "lib/url/validLink"; -import Link from "./link"; +import LinkSuggestion from "./link"; import { selectedSuggestionAtom } from "lib/state/suggestionSelection"; import { settingsAtom } from "lib/state/settings"; import PlainText from "./plainText"; @@ -86,12 +86,14 @@ export default function OneSearch() { }); } - (async function () { - const NLU = await import("lib/nlp/load"); - const mainNLUModel = new NLU.NLU(); - setNLUModel(mainNLUModel); - setNLUModelLoaded(true); - })(); + useEffect(() => { + (async function () { + const NLU = await import("lib/nlp/load"); + const mainNLUModel = new NLU.NLU(); + setNLUModel(mainNLUModel); + setNLUModelLoaded(true); + })(); + }, []); useEffect(() => { if (NLUModel === null || NLUModel === undefined) { @@ -172,7 +174,7 @@ export default function OneSearch() { s.type === "link" ) { return ( - + {s.prompt && ( {s.prompt} )} @@ -182,7 +184,7 @@ export default function OneSearch() { {s.relevance} )} - + ); } else if (s.type === "text") { return ( @@ -198,6 +200,25 @@ export default function OneSearch() { )} ); + } else if (s.type === "inpage-link") { + return ( + + {s.prompt && ( + {s.prompt} + )} + {s.suggestion} + {devMode && ( + + {s.relevance} + + )} + + ); } })} diff --git a/lib/onesearch/handleEnter.ts b/lib/onesearch/handleEnter.ts index e604bb5..239b925 100644 --- a/lib/onesearch/handleEnter.ts +++ b/lib/onesearch/handleEnter.ts @@ -18,8 +18,11 @@ export default function ( } else if (selected.type === "NAVIGATION" || selected.type === "default-link") { window.open(normalizeURL(selected.suggestion)); } else if (selected.type === "text") { - console.log("????"); copyToClipboard(selected.suggestion); searchBoxRef.current?.focus(); + } else if (selected.type === "link") { + window.open(normalizeURL(selected.suggestion)); + } else if (selected.type === "inpage-link") { + location.href = normalizeURL(selected.suggestion); } } diff --git a/lib/onesearch/keywordSuggestion.ts b/lib/onesearch/keywordSuggestion.ts index 88fc9a0..0736f23 100644 --- a/lib/onesearch/keywordSuggestion.ts +++ b/lib/onesearch/keywordSuggestion.ts @@ -16,7 +16,7 @@ export function keywordSuggestion(query: string) { for (const keyword in dict_cn) { if (query.includes(keyword)) { const result: suggestionItem = { - type: "link", + type: "inpage-link", suggestion: dict_cn[keyword], prompt: keyword, relevance: 3000 @@ -27,7 +27,7 @@ export function keywordSuggestion(query: string) { for (const keyword in dict_en) { if (query.includes(keyword)) { const result: suggestionItem = { - type: "link", + type: "inpage-link", suggestion: dict_en[keyword], prompt: keyword, relevance: 3000 diff --git a/package.json b/package.json index 9f2030a..f474cb1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sparkhome", "private": false, - "version": "5.6.0", + "version": "5.7.0", "type": "module", "scripts": { "dev": "bun server.ts", diff --git a/pages/about/index.tsx b/pages/about/index.tsx index 4058bfb..134a5ca 100644 --- a/pages/about/index.tsx +++ b/pages/about/index.tsx @@ -58,7 +58,7 @@ function Version(props: { title: string; version: string; versionClass?: string {props.version} diff --git a/pages/index.tsx b/pages/index.tsx index 2192d6c..6b55cc9 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -12,8 +12,9 @@ export default function Homepage() { const setBgFocus = useSetAtom(bgFocusAtom); return ( -
+
+ + }, + { + path: "about", + element: , + children: [ + { + path: "license", + element: } - }, - fallbackLng: "en", - - interpolation: { - escapeValue: false // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape - }, - - detection: { - order: ['navigator'], - caches: [] - } - }); - + ] + } +]); export function App() { - return Loading...

}>{useRoutes(routes)}
; + return ( +
+ +
+ ); } diff --git a/src/i18n.ts b/src/i18n.ts new file mode 100644 index 0000000..630a51b --- /dev/null +++ b/src/i18n.ts @@ -0,0 +1,65 @@ +import * as en from "i18n/en.json" +import * as zh from "i18n/zh.json" +import * as ja from "i18n/ja.json" +import * as ar from "i18n/ar.json" +import * as de from "i18n/de.json" +import * as es from "i18n/es.json" +import * as fr from "i18n/fr.json" +import * as it from "i18n/it.json" +import * as ko from "i18n/ko.json" +import * as pt from "i18n/pt.json" +import * as ru from "i18n/ru.json" +import i18n from "i18next"; +import { initReactI18next } from "react-i18next"; +import LanguageDetector from 'i18next-browser-languagedetector'; +import ICU from 'i18next-icu'; +i18n.use(initReactI18next) // passes i18n down to react-i18next + .use(LanguageDetector) + .use(ICU) + .init({ + resources: { + en: { + translation: en + }, + zh: { + translation: zh + }, + ja: { + translation: ja + }, + ar: { + translation: ar + }, + de: { + translation: de + }, + es: { + translation: es + }, + fr: { + translation: fr + }, + it: { + translation: it + }, + ko: { + translation: ko + }, + pt: { + translation: pt + }, + ru: { + translation: ru + } + }, + fallbackLng: "en", + + interpolation: { + escapeValue: false // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape + }, + + detection: { + order: ['navigator'], + caches: [] + } + }); \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx index e26a904..d4ecb1c 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,6 +1,5 @@ import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; -import { BrowserRouter } from "react-router-dom"; import { App } from "./app"; import "./index.css"; import { NextUIProvider } from "@nextui-org/react"; @@ -9,10 +8,8 @@ const app = createRoot(document.getElementById("root")!); app.render( - - - - - + + + ); diff --git a/tailwind.config.ts b/tailwind.config.ts index 412e2f9..e7856ab 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -7,6 +7,7 @@ const config: Config = { "./pages/**/*.{js,ts,jsx,tsx,mdx}", "./components/**/*.{js,ts,jsx,tsx,mdx}", "./node_modules/@nextui-org/theme/**/*.{js,ts,jsx,tsx}", + "./src/**/*.{js,ts,jsx,tsx,mdx}" ], theme: { extend: { diff --git a/vite.config.ts b/vite.config.ts index a5a447a..8f41c4f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,5 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; -import Pages from "vite-plugin-pages"; import tsconfigPaths from 'vite-tsconfig-paths'; import { chunkSplitPlugin } from 'vite-plugin-chunk-split'; @@ -8,9 +7,6 @@ import { chunkSplitPlugin } from 'vite-plugin-chunk-split'; export default defineConfig({ plugins: [ react(), - Pages({ - dirs: "./pages/" - }), tsconfigPaths(), chunkSplitPlugin() ]