Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
김재형
2020-06-14 22:01:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c2c2de45070815f1063e1024987739bc2c33aeb8
c2c2de45
1 parent
3dd36f56
Implement folder browsing
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
frontend/src/App.tsx
frontend/src/file/FileList.tsx
frontend/src/file/FileListItem.tsx
frontend/src/App.tsx
View file @
c2c2de4
import React
, { useEffect }
from "react";
import { Switch, Route, Redirect
, useHistory
} from "react-router-dom";
import React from "react";
import { Switch, Route, Redirect } from "react-router-dom";
import { Login } from "auth/Login";
import { useAuth, TokenContext } from "auth/useAuth";
...
...
@@ -10,13 +10,6 @@ import { FileList } from "file/FileList";
export function App() {
const { token, login } = useAuth();
const root = token?.user.rootFolder;
const history = useHistory();
useEffect(() => {
if (root) {
history.push(`/folder/${root}`);
}
}, [history, root]);
return (
<Switch>
...
...
@@ -31,6 +24,9 @@ export function App() {
<Route path="/folder/:id">
<FileList />
</Route>
<Route>
<Redirect to={`/folder/${root}`} />
</Route>
</Switch>
</Page>
</TokenContext.Provider>
...
...
frontend/src/file/FileList.tsx
View file @
c2c2de4
...
...
@@ -42,8 +42,16 @@ export function FileList() {
const id = useParams<{ id: string }>().id;
const { data } = useFileList(id);
if (data && data.parent !== null) {
data.list.unshift(({
if (!data) {
return null;
}
const list = [...data.list].sort((itemA, itemB) =>
itemA.is_folder === itemB.is_folder ? 0 : itemA.is_folder ? -1 : 1
);
if (data.parent !== null) {
list.unshift(({
id: data.parent,
is_folder: true,
name: "..",
...
...
@@ -51,5 +59,10 @@ export function FileList() {
} as unknown) as FileItem);
}
return data && <Table columns={columns} dataSource={data.list} />;
return (
<div>
{data.parent !== null && <h3>{data.name}</h3>}
<Table columns={columns} dataSource={list} pagination={false} />
</div>
);
}
...
...
frontend/src/file/FileListItem.tsx
View file @
c2c2de4
import React, { Fragment } from "react";
import { FileItem } from "./useFileList";
import { Link } from "react-router-dom";
export function FileListItem({ item }: { item: FileItem }) {
return <Fragment>{item.name}</Fragment>;
return (
<Fragment>
{item.is_folder ? (
<Link to={`/folder/${item.id}`}>{item.name}</Link>
) : (
item.name
)}
</Fragment>
);
}
...
...
Please
register
or
login
to post a comment