Skip to content

Commit

Permalink
- some minor ui fixes
Browse files Browse the repository at this point in the history
- update some js deps
  • Loading branch information
ddvk committed Nov 16, 2024
1 parent 3994f1e commit afd5b3f
Show file tree
Hide file tree
Showing 11 changed files with 1,682 additions and 1,338 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ run: $(ASSETS)
go run $(CMD) $(ARG)

$(ASSETS): $(UIFILES) ui/yarn.lock
@cp ui/node_modules/pdfjs-dist/build/pdf.worker.js ui/public/
#@cp ui/node_modules/pdfjs-dist/build/pdf.worker.js ui/public/
$(YARN) build
@#remove unneeded stuff, todo: eject
@rm ui/build/service-worker.js ui/build/precache-manifest* ui/build/asset-manifest.json 2> /dev/null || true
Expand Down
12 changes: 6 additions & 6 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
"bootstrap": "^5.3.3",
"jwt-decode": "^3.1.2",
"moment": "^2.29.4",
"react": "^17.0.1",
"react": "^18.3.1",
"react-arborist": "^3.4.0",
"react-bootstrap": "^2.10.0",
"react-dom": "^17.0.1",
"react-dom": "^18.3.1",
"react-dropzone": "^11.3.2",
"react-dropzone-uploader": "^2.11.0",
"react-icons": "^4.2.0",
"react-pdf": "^5.5.0",
"react-pdf": "^9.1.1",
"react-router-dom": "^5.3.0",
"react-toastify": "^8.1.1",
"react-toastify": "^10.0.6",
"react-treebeard": "^3.2.4",
"sass": "^1.69.5",
"sass": "^1.81.0",
"typescript": "^4.4.4"
},
"scripts": {
Expand Down Expand Up @@ -53,7 +53,7 @@
"@types/react-dom": "^17.0.10",
"@types/react-router-dom": "^5.3.1",
"react-scripts": "5.0.1",
"sass-loader": "^13.3.2",
"sass-loader": "^16.0.3",
"webpack": "^5.89.0"
},
"proxy": "http://localhost:3000"
Expand Down
2 changes: 1 addition & 1 deletion ui/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect} from "react";
import {useEffect} from "react";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import { ToastContainer } from 'react-toastify';

Expand Down
2 changes: 1 addition & 1 deletion ui/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,4 @@ main h2 {
padding: 0.5em 0;
}

@import "node_modules/bootstrap/scss/bootstrap";
@import "node_modules/bootstrap/scss/bootstrap";
6 changes: 5 additions & 1 deletion ui/src/components/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ const NavigationBar = () => {
Documents
</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link as={NavLink} to="/connect">
Connect
</Nav.Link>
</Nav.Item>
</Nav>
<Nav className="ms-auto">
<NavDropdown id="userMenu" title={user.UserID} align="end">
<NavDropdown.Item as={NavLink} to="/connect">Connect Device</NavDropdown.Item>
<NavDropdown.Item as={NavLink} to="/admin">Admin</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item as={Button} onClick={handleLogout}>Log out</NavDropdown.Item>
Expand Down
10 changes: 5 additions & 5 deletions ui/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from "react";
import ReactDOM from "react-dom";
import { createRoot } from "react-dom/client";
import App from "./App";
import ErrorBoundary from "./components/ErrorBoundary";
import "./index.css";

ReactDOM.render(
const domNode = document.getElementById('root');
const root = createRoot(domNode);
root.render(
<React.StrictMode>
<ErrorBoundary>
<App />
</ErrorBoundary>
</React.StrictMode>,
document.getElementById("root")
);
</React.StrictMode>);
35 changes: 29 additions & 6 deletions ui/src/pages/Documents/File.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import { useState } from "react";
import { useState, useEffect, useRef } from "react";
import { Button, ButtonGroup } from "react-bootstrap";
import { Document, Page } from "react-pdf";
import Navbar from 'react-bootstrap/Navbar';
import { FaChevronRight, FaChevronLeft, } from "react-icons/fa6";
import { AiOutlineDownload } from "react-icons/ai";
import constants from "../../common/constants";

import apiservice from "../../services/api.service"

import NameTag from "../../components/NameTag"

import { pdfjs,Document, Page } from "react-pdf";
// import 'react-pdf/dist/Page/AnnotationLayer.css';
// import 'react-pdf/dist/Page/TextLayer.css';
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.mjs',
import.meta.url,
).toString();

export default function FileViewer({ file, onSelect }) {
const { data } = file;

const downloadUrl = `${constants.ROOT_URL}/documents/${file.id}`;

const [page, setPage] = useState(1);
const [pages, setPages] = useState(1);

// const [width, setWidth] = useState(100);
const [height, setHeight] = useState(100);
const onLoadSuccess = (pdf) => {
setPage(1);
setPages(pdf.numPages);
Expand All @@ -32,6 +39,17 @@ export default function FileViewer({ file, onSelect }) {
return Math.min(p + 1, pages);
});
};
const parent = useRef(null);
useEffect(() => {
const resizeObserver = new ResizeObserver((event) => {
// Depending on the layout, you may need to swap inlineSize with blockSize
// https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/contentBoxSize
// setWidth(event[0].contentBoxSize[0].inlineSize);
setHeight(event[0].contentBoxSize[0].blockSize);
});

resizeObserver.observe(parent.current);
});

// TODO: add loading and error handling
const onDownloadClick = () => {
Expand Down Expand Up @@ -79,9 +97,14 @@ export default function FileViewer({ file, onSelect }) {
</Navbar>

{file && (
<div>
<div ref={parent} style={{height: "95%"}}>
<Document file={downloadUrl} onLoadSuccess={onLoadSuccess}>
<Page pageNumber={page} />
<Page pageNumber={page}
// width={ width }
height={ height}
renderAnnotationLayer={false}
renderTextLayer={false}
/>
</Document>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/Documents/Folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import FileList from "./FileList";
import NameTag from "../../components/NameTag"

export default function Folder({ selection, onSelect, onUpdate }) {
const [listStyle, setListStyle] = useState("grid");
const [listStyle, setListStyle] = useState("list");
const [folderName, setFolderName] = useState("");
const [showCreateFileModal, setShowCreateFolder] = useState(false);

Expand Down
4 changes: 0 additions & 4 deletions ui/src/pages/Documents/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import apiservice from "../../services/api.service";

import styles from "./Documents.module.scss";

function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

export default function StyledDropzone(props) {
const [uploading, setUploading] = useState(false);
const [lasterror, setLastError] = useState();
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/Documents/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function DocumentList() {

useEffect(() => {
loadDocs()
}, [])

This comment has been minimized.

Copy link
@davidpkj

davidpkj Nov 16, 2024

Contributor

I think this should not be removed. The empty array indicates that loadDocs should run only once on the initial render. If no array is passed, the function would be called each re-render and update causing an infinite loop.

})

return (
<Container fluid>
Expand Down
Loading

0 comments on commit afd5b3f

Please sign in to comment.