From ff959fd46e6c915d316f8f04149002954885d263 Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Mon, 30 Jun 2025 19:17:30 +0000 Subject: [PATCH] update --- reader/src/App.jsx | 26 ++++++++++++++++++++++++-- reader/src/NamePage.jsx | 3 +++ reader/src/ResourcePage.jsx | 31 ++++++++++++++++--------------- reader/src/store.js | 3 ++- resource-provider/server.js | 12 +++++------- 5 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 reader/src/NamePage.jsx diff --git a/reader/src/App.jsx b/reader/src/App.jsx index 0ead355..4162094 100644 --- a/reader/src/App.jsx +++ b/reader/src/App.jsx @@ -1,5 +1,13 @@ import { StrictMode, Fragment, useLayoutEffect, useRef, useState, useEffect, useMemo } from "react"; -import { Navigate, BrowserRouter, Link, Outlet, Route, Routes } from "react-router"; +import { + Navigate, + useSearchParams, + BrowserRouter, + Link, + Outlet, + Route, + Routes, +} from "react-router"; import { marked } from "marked"; import { resourcesInstance } from "./api.js"; import { useStore } from "./store.js"; @@ -20,6 +28,7 @@ import { VRuleIcon, } from "./icons/Icons"; import ResourcePage from "./ResourcePage.jsx"; +import NamePage from "./NamePage.jsx"; import io from "socket.io-client"; //const socket = io("http://localhost:3000"); @@ -134,6 +143,7 @@ export function App() { } /> } /> + } /> @@ -161,7 +171,19 @@ function LoadingWrapper({ children }) { function Layout() { const config = useStore((state) => state.config); + const changeConfig = useStore((state) => state.changeConfig); const topic = useTopic(); + const [searchParams, setSearchParams] = useSearchParams(); + + useEffect(() => { + if (searchParams.has("v")) { + const resV = Number(searchParams.get("v")); + if (typeof resV === "number" && resV >= 0 && resV <= 8) { + changeConfig({ version: resV }); + } + setSearchParams({}); + } + }, [searchParams, changeConfig, setSearchParams]); return (
@@ -298,7 +320,7 @@ export function Reader({ topic }) { const resourceIdx = useStore((state) => state.resourceIdx); const selectResource = useStore((state) => state.selectResource); - + console.log(resourceIdx); const selectedResource = topic.resources[resourceIdx]; return ( diff --git a/reader/src/NamePage.jsx b/reader/src/NamePage.jsx new file mode 100644 index 0000000..7ece023 --- /dev/null +++ b/reader/src/NamePage.jsx @@ -0,0 +1,3 @@ +export default function NamePage() { + return
Hello name page
; +} diff --git a/reader/src/ResourcePage.jsx b/reader/src/ResourcePage.jsx index 4b3407f..47f5825 100644 --- a/reader/src/ResourcePage.jsx +++ b/reader/src/ResourcePage.jsx @@ -17,6 +17,7 @@ function LoadingWrapper() { } function SelectResource({ topics, selectedTopic, selectedResource, onChange, disabled }) { + const version = useStore((state) => state.config.version); function handleChange(newTopicIdx, newResourceIdx) { if (disabled) { return; @@ -43,7 +44,7 @@ function SelectResource({ topics, selectedTopic, selectedResource, onChange, dis id="topicSelect" value={selectedTopic.seq - 1} onChange={(event) => { - handleChange(parseInt(event.target.value), 0); + handleChange(parseInt(event.target.value), version); }} className="disabled:bg-gray-50 disabled:text-gray-500 px-2 py-1 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white" > @@ -121,8 +122,9 @@ const ResourcePage = ({ topics }) => { const [tokenInput, setTokenInput] = useState(""); // Topic + resource + const version = useStore((state) => state.config.version); const [topicIdx, setTopicIdx] = useState(0); - const [resourceIdx, setResourceIdx] = useState(0); + const [resourceIdx, setResourceIdx] = useState(version); const setStructure = useStore((state) => state.setStructure); const selectedTopic = topics[topicIdx]; const selectedResource = selectedTopic.resources[resourceIdx]; @@ -170,19 +172,18 @@ const ResourcePage = ({ topics }) => { }, [content]); const handleLoad = () => { - return; - const iframe = iframeRef.current; - if (iframe) { - try { - // Only works for same-origin content - const contentHeight = iframe.contentDocument.body.scrollHeight; - if (contentHeight > 100) { - iframe.style.height = contentHeight + "px"; - } - } catch (error) { - console.log("Cross-origin iframe - cannot access content height"); - } - } + //const iframe = iframeRef.current; + //if (iframe) { + // try { + // // Only works for same-origin content + // const contentHeight = iframe.contentDocument.body.scrollHeight; + // if (contentHeight > 100) { + // iframe.style.height = contentHeight + "px"; + // } + // } catch (error) { + // console.log("Cross-origin iframe - cannot access content height"); + // } + //} }; const handleTokenSubmit = () => { diff --git a/reader/src/store.js b/reader/src/store.js index d0ca163..d0b3ece 100644 --- a/reader/src/store.js +++ b/reader/src/store.js @@ -20,7 +20,7 @@ export const useStore = create((set, get) => ({ if (topicIdx === null) { set({ topicIdx, resourceIdx: null }); } else { - set({ topicIdx, resourceIdx: 0 }); + set({ topicIdx, resourceIdx: get().config.version }); } }, selectResource: (resourceIdx) => { @@ -59,6 +59,7 @@ function getLocalConfig() { narrowMode: true, justifyText: false, contentZoomLevel: 100, + version: 0, }; const config_str = localStorage.getItem("config"); const config = config_str ? JSON.parse(config_str) : {}; diff --git a/resource-provider/server.js b/resource-provider/server.js index 5ddd556..d3282a2 100644 --- a/resource-provider/server.js +++ b/resource-provider/server.js @@ -124,8 +124,8 @@ app.post( verifyToken, asyncHandler(async (req, res) => { try { - const { topicSeq, resourceSeq, content } = req.body; - if (!topicSeq || !resourceSeq || !content) { + const { topicSeq, resourceSeq, content = "" } = req.body; + if (!topicSeq || !resourceSeq) { res.status(400).json({ message: "Missing body" }); return; } @@ -186,11 +186,9 @@ app.post( } if (sourceResourceSeq === targetResourceSeq) { - res - .status(400) - .json({ - message: "Source and target resource sequences cannot be the same", - }); + res.status(400).json({ + message: "Source and target resource sequences cannot be the same", + }); return; }