diff --git a/frontend/app/editor.tsx b/frontend/app/editor.tsx index aaedbf7..b92f77a 100644 --- a/frontend/app/editor.tsx +++ b/frontend/app/editor.tsx @@ -1,5 +1,5 @@ import { DownloadOutlined } from '@ant-design/icons'; -import { Button, Col, Layout, Row, Tree, message, Upload } from "antd"; +import { Button, Col, Layout, Row, Tree, message, Upload, Divider } from "antd"; import { UploadOutlined, DownOutlined } from '@ant-design/icons'; import type { TreeDataNode, TreeProps } from 'antd'; import { @@ -7,12 +7,14 @@ import { Zip, AsyncZipDeflate, Unzip, AsyncUnzipInflate, Unzipped } from 'fflate'; -import { useState, useEffect } from 'react'; -import { InboxOutlined } from '@ant-design/icons'; +import { useState, useEffect, Key } from 'react'; +import { InboxOutlined, CheckOutlined, UndoOutlined } from '@ant-design/icons'; import type { ChangeHandler, MonacoDiffEditorProps } from './monaco'; import type { UploadProps } from 'antd'; import Text from "antd/es/typography/Text"; import { saveAs } from 'file-saver'; +const { DirectoryTree } = Tree; + // import MonacoDiffEditor from './monaco'; import dynamic from "next/dynamic"; @@ -29,6 +31,8 @@ export default function DiffEditor() { const [oldTreeData, setOldTreeData] = useState(null) const [newTreeData, setNewTreeData] = useState(null) const [selectedKey, setSelectedKey] = useState('') + const [expandedKeysOld, setExpandedKeysOld] = useState([]) + const [expandedKeysNew, setExpandedKeysNew] = useState([]) const makeOrGetDir = (children: TreeDataNode[], key: string, name: string) => { const node = children.find((child) => child.title === name) @@ -53,6 +57,7 @@ export default function DiffEditor() { let current = root let currentKey = '' for (let i = 0; i < dirs.length - 1; i++) { + if (dirs[i].length === 0) { continue } const t = makeOrGetDir(current, currentKey.toString(), dirs[i]) if (t.children === undefined) { message.error(`Folder and file name collision: ${t.key}.`) @@ -61,10 +66,12 @@ export default function DiffEditor() { currentKey = t.key as string current = t.children as TreeDataNode[] } + if (dirs.length === 0 || dirs[dirs.length-1].length === 0) { continue } const leaf: TreeDataNode = { title: dirs[dirs.length - 1], key: path, - disabled: other !== null && other[path] === undefined + disabled: other !== null && other[path] === undefined, + isLeaf: true, } current.push(leaf) } @@ -108,6 +115,7 @@ export default function DiffEditor() { } const onSelectTree: TreeProps['onSelect'] = (selectedKeys, info) => { + console.log('selected', selectedKeys, info); if (selectedKeys.length === 0) { setSelectedKey('') } else { @@ -159,27 +167,27 @@ export default function DiffEditor() { const UploadWindow = () => (<> - +

- + {oldTreeData === null ? : }

-

Click or drag file to this area to upload

+

Old Project

- Support for a single or bulk upload. Strictly prohibited from uploading company data or other - banned files. + Click or drag file to this area to upload.
+ Support zip latex project. You can download from overleaf.

- +

- + {newTreeData === null ? : }

-

Click or drag file to this area to upload

+

New Project

- Support for a single or bulk upload. Strictly prohibited from uploading company data or other - banned files. + Click or drag file to this area to upload.
+ Support zip latex project. You can download from overleaf.

@@ -189,12 +197,14 @@ export default function DiffEditor() { const DiffWindow = () => (<> - } defaultExpandedKeys={['0-0-0']} onSelect={onSelectTree} treeData={convertZipToTree(oldTreeData, newTreeData)} + expandedKeys={expandedKeysOld} + onExpand={(expandedKeys) => setExpandedKeysOld(expandedKeys)} /> @@ -208,22 +218,27 @@ export default function DiffEditor() { /> - } defaultExpandedKeys={['0-0-0']} onSelect={onSelectTree} treeData={convertZipToTree(newTreeData, oldTreeData)} + expandedKeys={expandedKeysNew} + onExpand={(expandedKeys) => setExpandedKeysNew(expandedKeys)} /> - - + + - + + + + @@ -240,6 +255,7 @@ export default function DiffEditor() { New Project + {oldTreeData !== null && newTreeData !== null ? : } {/*
*/} ); diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 43ddfed..951db01 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -18,7 +18,7 @@ import Flex from 'antd/es/flex'; import Giscus from './giscus'; import { useState, useEffect, useRef } from 'react'; -import { Divider, Form } from 'antd'; +import { Col, Divider, Form, Row } from 'antd'; import { Color } from 'antd/es/color-picker'; import { ColorFactory } from 'antd/es/color-picker/color'; import message from 'antd/es/message'; @@ -224,47 +224,64 @@ export default function Home() { let customStyle = (
Custom Style Options
) @@ -280,7 +297,7 @@ export default function Home() { false} maxCount={1} accept='zip,application/zip,application/x-zip,application/x-zip-compressed'> @@ -289,7 +306,7 @@ export default function Home() { false} maxCount={1} accept='zip,application/zip,application/x-zip,application/x-zip-compressed'> @@ -339,7 +356,7 @@ export default function Home() { { setFields({ ...fields, download_diff_proj: e.target.checked }); }}> - Additionally download the diffed latex project as a tar file + Download the diff project (.tar)