Skip to content

Commit 3b4a7a5

Browse files
authored
Feat : Created Skeleton of ItemListPage
Changed BookmarkPage to ItemListPage s.t. the template can be re-used to render other pages as well Resolves : #33
1 parent e805990 commit 3b4a7a5

6 files changed

Lines changed: 47 additions & 25 deletions

File tree

frontend/components/environment/Main/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default function Main({ location }) {
5555
<Route path="/item" component={RoutingPage} />
5656
<Route path="/account" component={RoutingPage} />
5757
<Route path="/user" component={RoutingPage} />
58-
<Route path="/bookmark" component={RoutingPage} />
58+
<Route path="/leftpane" component={RoutingPage} />
5959

6060
{/* 404 Fallback page */}
6161
<Route path="/error">

frontend/components/organisms/LeftPane/LeftPane.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default function LeftPane() {
5353
<ListSubheader className="leftpane-label"> 내 문서 </ListSubheader>
5454
<ListItem disableGutters sx={{ py: 0 }}>
5555
<ListItemButton disableGutters sx={{ py: 0 }}>
56-
<MenuItem value={{ title: '북마크', link: '/bookmark' }} />
56+
<MenuItem value={{ title: '북마크', link: '/leftpane/bookmarks' }} />
5757
</ListItemButton>
5858
</ListItem>
5959
<ListItem disableGutters sx={{ py: 0 }}>
@@ -63,7 +63,7 @@ export default function LeftPane() {
6363
</ListItem>
6464
<ListItem disableGutters sx={{ py: 0 }}>
6565
<ListItemButton disableGutters sx={{ py: 0 }}>
66-
<MenuItem value={{ title: '내가 작성한 문서', link: '/' }} />
66+
<MenuItem value={{ title: '내가 작성한 문서', link: '/leftpane/myitems' }} />
6767
</ListItemButton>
6868
</ListItem>
6969
<ListItem disableGutters sx={{ py: 0 }}>

frontend/components/pages/BookmarkPage/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

frontend/components/pages/BookmarkPage/BookmarkPage.js renamed to frontend/components/pages/ItemListPage/ItemListPage.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,90 @@
11
import React, { useState, useEffect } from 'react';
22
import { useSelector } from 'react-redux';
3+
import { useParams } from 'react-router';
34
import R from 'ramda';
45

56
import HorizontalHeader from '_organisms/HorizontalHeader';
67
import HorizontalContent from '_organisms/HorizontalContent';
78
import PromiseItemArray from '_utils/promiseArray';
89
import { snakeToCamelCase } from 'json-style-converter/es5';
910
import { getItemByItemId } from '_api/item';
11+
import { object } from 'prop-types';
1012

11-
export default function BookmarkPage() {
13+
export default function ItemListPage() {
1214
const { user } = useSelector(R.pick(['user']));
13-
const [bookmarkObjects, setBookmarkObjects] = useState({ cabinet: [], document: [], card: [] });
15+
const { userItem } = useSelector(R.pick(['userItem']));
16+
const [title, setTitle] = useState('');
17+
const [itemObjects, setItemObjects] = useState({ cabinet: [], document: [], card: [] });
1418
const [loading, setLoading] = useState(true);
15-
const bookmarkArrays = user.bookmarks;
19+
const { path } = useParams();
1620

1721
useEffect(() => {
18-
Promise.all(bookmarkArrays.map((elem) => getItemByItemId(elem))).then((objectArray) => {
22+
let array;
23+
switch (path) {
24+
case 'bookmarks':
25+
setTitle('북마크');
26+
array = user.bookmarks;
27+
break;
28+
case 'myitems':
29+
setTitle('내가 작성한 문서');
30+
array = userItem;
31+
break;
32+
default:
33+
array = [];
34+
}
35+
Promise.all(array.map((elem) => {
36+
if (typeof elem === 'object') {
37+
return elem;
38+
}
39+
return getItemByItemId(elem);
40+
})).then((objectArray) => {
1941
const camelObjectArray = snakeToCamelCase(objectArray);
20-
setBookmarkObjects({
42+
setItemObjects({
2143
cabinet: camelObjectArray.filter((elem) => elem.type === 'cabinet'),
2244
document: camelObjectArray.filter((elem) => elem.type === 'document'),
2345
card: camelObjectArray.filter((elem) => elem.type === 'card'),
2446
});
2547
setLoading(false);
2648
});
27-
}, []);
49+
}, [path, user]);
2850

2951
return !loading && (
3052
<div className="recommend-page">
3153
<div className="recommend-page-header">
32-
북마크
54+
{title}
3355
</div>
3456
<div className="recommend-container">
3557

3658
{
37-
(bookmarkObjects.cabinet === [])
38-
? '북마크가 없습니다.'
59+
(itemObjects.cabinet.length === 0)
60+
? ''
3961
: (
4062
<div className="recommend-block">
4163
<HorizontalHeader type="cabinet" />
4264
<hr />
43-
<HorizontalContent type="cabinet" cardArray={bookmarkObjects.cabinet} />
65+
<HorizontalContent type="cabinet" cardArray={itemObjects.cabinet} />
4466
</div>
4567
)
4668
}
4769
{
48-
(bookmarkObjects.document === [])
49-
? '북마크가 없습니다.'
70+
(itemObjects.document.length === 0)
71+
? ''
5072
: (
5173
<div className="recommend-block">
5274
<HorizontalHeader type="document" />
5375
<hr />
54-
<HorizontalContent type="document" cardArray={bookmarkObjects.document} />
76+
<HorizontalContent type="document" cardArray={itemObjects.document} />
5577
</div>
5678
)
5779
}
5880
{
59-
(bookmarkObjects.card === [])
60-
? '북마크가 없습니다.'
81+
(itemObjects.card.length === 0)
82+
? ''
6183
: (
6284
<div className="recommend-block">
6385
<HorizontalHeader type="card" />
6486
<hr />
65-
<HorizontalContent type="card" cardArray={bookmarkObjects.card} />
87+
<HorizontalContent type="card" cardArray={itemObjects.card} />
6688
</div>
6789
)
6890
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import BookmarkPage from './ItemListPage';
2+
3+
export default BookmarkPage;

frontend/components/pages/RoutingPage/RoutingPage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ProfilePage from '_pages/ProfilePage';
1212
import RecoveryPage from '_pages/RecoveryPage';
1313
import SearchPage from '_pages/SearchPage';
1414
import TestPage from '_pages/TestPage';
15-
import BookmarkPage from '_pages/BookmarkPage';
15+
import ItemListPage from '_pages/ItemListPage';
1616
import { attemptGetGroup } from '_thunks/group';
1717
import { attemptLoadItems } from '_thunks/item';
1818

@@ -57,8 +57,8 @@ export default function RoutingPage() {
5757
{/* Search Page */}
5858
<Route path="/search/:searchQuery" component={SearchPage} />
5959

60-
{/* Bookmark Page */}
61-
<Route path="/bookmark" component={BookmarkPage} />
60+
{/* LeftPane Pages */}
61+
<Route path="/leftpane/:path" component={ItemListPage} />
6262

6363
{/* Item Page */}
6464
<Route path="/create" component={EditorPage} />

0 commit comments

Comments
 (0)