diff --git a/app/src/conf.ts b/app/src/conf.ts index e574ef12..7186f594 100644 --- a/app/src/conf.ts +++ b/app/src/conf.ts @@ -1,6 +1,6 @@ import axios from "axios"; -export const version: string = "3.2.0"; +export const version: string = "3.2.1"; export const deploy: boolean = true; export let rest_api: string = "http://localhost:8094"; export let ws_api: string = "ws://localhost:8094"; diff --git a/app/src/routes/Home.tsx b/app/src/routes/Home.tsx index e9168045..568fafb6 100644 --- a/app/src/routes/Home.tsx +++ b/app/src/routes/Home.tsx @@ -22,7 +22,7 @@ import { } from "../components/ui/tooltip.tsx"; import { useDispatch, useSelector } from "react-redux"; import type { RootState } from "../store"; -import { selectAuthenticated } from "../store/auth.ts"; +import {selectAuthenticated, selectInit} from "../store/auth.ts"; import { login, supportModels } from "../conf.ts"; import { deleteConversation, @@ -282,6 +282,7 @@ function ChatWrapper() { }); const [clearEvent, setClearEvent] = useState<() => void>(() => {}); const dispatch = useDispatch(); + const init = useSelector(selectInit); const auth = useSelector(selectAuthenticated); const model = useSelector(selectModel); const web = useSelector(selectWeb); @@ -297,16 +298,23 @@ function ChatWrapper() { clearEvent?.(); } + async function processSend(data: string, auth: boolean, model: string, web: boolean): Promise { + const message: string = formatMessage(file, data); + if (message.length > 0 && data.trim().length > 0) { + if (await manager.send(t, auth, { message, web, model })) { + clearFile(); + return true; + } + return false; + } + } + async function handleSend(auth: boolean, model: string, web: boolean) { // because of the function wrapper, we need to update the selector state using props. if (!target.current) return; const el = target.current as HTMLInputElement; - const message: string = formatMessage(file, el.value); - if (message.length > 0 && el.value.trim().length > 0) { - if (await manager.send(t, auth, { message, web, model })) { - clearFile(); - el.value = ""; - } + if (await processSend(el.value, auth, model, web)) { + el.value = ""; } } @@ -315,6 +323,14 @@ function ChatWrapper() { if (el) el.focus(); }); + useEffect(() => { + if (!init) return; + const search = new URLSearchParams(window.location.search); + const query = (search.get("q") || "").trim(); + if (query.length > 0) processSend(query, auth, model, web).then(); + window.history.replaceState({}, "", "/"); + }, [init]); + return (
diff --git a/app/src/store/auth.ts b/app/src/store/auth.ts index f9024cd4..9786350d 100644 --- a/app/src/store/auth.ts +++ b/app/src/store/auth.ts @@ -6,6 +6,7 @@ export const authSlice = createSlice({ name: "auth", initialState: { token: "", + init: false, authenticated: false, username: "", }, @@ -21,6 +22,9 @@ export const authSlice = createSlice({ setUsername: (state, action) => { state.username = action.payload as string; }, + setInit: (state, action) => { + state.init = action.payload as boolean; + }, logout: (state) => { state.token = ""; state.authenticated = false; @@ -40,6 +44,7 @@ export function validateToken(dispatch: any, token: string, hook?: () => any) { if (token.length === 0) { dispatch(setAuthenticated(false)); dispatch(setUsername("")); + dispatch(setInit(true)); return; } else axios @@ -47,6 +52,7 @@ export function validateToken(dispatch: any, token: string, hook?: () => any) { .then((res) => { dispatch(setAuthenticated(res.data.status)); dispatch(setUsername(res.data.user)); + dispatch(setInit(true)); hook && hook(); }) .catch((err) => { @@ -57,7 +63,8 @@ export function validateToken(dispatch: any, token: string, hook?: () => any) { export const selectAuthenticated = (state: any) => state.auth.authenticated; export const selectUsername = (state: any) => state.auth.username; +export const selectInit = (state: any) => state.auth.init; -export const { setToken, setAuthenticated, setUsername, logout } = +export const { setToken, setAuthenticated, setUsername, logout, setInit } = authSlice.actions; export default authSlice.reducer;