Skip to content

Commit cb70149

Browse files
authored
Merge pull request #2 from franxyzxyz/bookmark
Bookmark branch merged to master
2 parents ab46001 + 5e768f9 commit cb70149

19 files changed

+526
-46
lines changed

src/app/actions/index.jsx

+34-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ export function requestPages (title) {
1515
}
1616
}
1717

18+
export function popUp () {
19+
return {
20+
type: 'POPUP_ENABLED'
21+
}
22+
}
23+
24+
export function disabledPopUp(){
25+
return {
26+
type: 'POPUP_DISABLED'
27+
}
28+
}
29+
1830
export function receivePages (title, json) {
1931
return {
2032
type: 'RECEIVE_POSTS',
@@ -23,6 +35,26 @@ export function receivePages (title, json) {
2335
}
2436
}
2537

38+
export function addBookmark(title){
39+
return {
40+
type: 'ADD_BOOKMARK',
41+
title
42+
}
43+
}
44+
45+
export function editBookmark (title){
46+
return {
47+
type: 'EDIT_BOOKMARK',
48+
title
49+
}
50+
}
51+
52+
export function toggleBookmark (){
53+
return {
54+
type: 'TOGGLE_BOOKMARK'
55+
}
56+
}
57+
2658
export function fetchPages (title) {
2759
return dispatch => {
2860
/*
@@ -58,7 +90,7 @@ export function fetchPagesIfNeeded(title){
5890
}
5991
}
6092

61-
export function shouldFetchImage(state, title, imgTitle){
93+
export function shouldFetchImage(state, title){
6294
const image = state.imageByTitle[title]
6395
if (!image){
6496
return true
@@ -69,7 +101,7 @@ export function shouldFetchImage(state, title, imgTitle){
69101

70102
export function fetchImageIfNeeded(title, imgTitle){
71103
return (dispatch, getState) => {
72-
if (shouldFetchImage(getState(), title, imgTitle)) {
104+
if (shouldFetchImage(getState(), title)) {
73105
return dispatch(fetchImage(title, imgTitle))
74106
}
75107
}

src/app/components/app.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import React from 'react'
22
import '../fonts/league-spartan-master/_webfonts/stylesheet.scss'
33
import '../styles/index.scss'
44
import Wrapper from '../containers/app'
5+
import ViewBookmark from '../containers/viewbookmark'
6+
import PopUpContainer from '../containers/popup'
57

68
const App = () => (
79
<div>
810
<h1>POCKET - wiki</h1>
11+
<ViewBookmark />
912
<Wrapper />
13+
<PopUpContainer />
1014
</div>
1115
)
1216

src/app/components/bookmarkList.jsx

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { PropTypes, Component } from 'react'
2+
import ItemLink from '../containers/itemAction'
3+
import { reverseSnakeCase } from '../utilities/helper'
4+
5+
export default class BookmarkList extends Component {
6+
render() {
7+
const { bookmarkList } = this.props
8+
return (
9+
<div>
10+
<p className="bookmarkRecord">( {bookmarkList.length} RECORD{ bookmarkList.length > 1 &&
11+
<span>S</span>
12+
} FOUND )</p>
13+
<ul className="bookmarkList">
14+
{bookmarkList.map((bm, i) =>
15+
<ItemLink item={reverseSnakeCase(bm)} key={i}/>
16+
)}
17+
</ul>
18+
</div>
19+
)
20+
}
21+
}
22+
23+
BookmarkList.propTypes = {
24+
bookmarkList: PropTypes.array.isRequired
25+
}

src/app/components/bookmarklink.jsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, { PropTypes, Component } from 'react'
2+
3+
export default class BookmarkLink extends Component {
4+
render() {
5+
const { onClick, bookmarkList } = this.props
6+
return (
7+
<div className="utilBar">
8+
<a onClick={onClick} className="navLink">BOOKMARK ({bookmarkList.length})</a>
9+
</div>
10+
)
11+
}
12+
}
13+
14+
BookmarkLink.propTypes = {
15+
onClick: PropTypes.func.isRequired
16+
}

src/app/components/closebookmark.jsx

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, { PropTypes, Component } from 'react'
2+
3+
export default class CloseBookmarkElem extends Component {
4+
render() {
5+
const { onClick } = this.props
6+
return (
7+
<span className="float-right close"><i className="material-icons" onClick={onClick}>close</i></span>
8+
)
9+
}
10+
}
11+
12+
CloseBookmarkElem.propTypes = {
13+
onClick: PropTypes.func.isRequired
14+
}

src/app/components/item.jsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@ import React, { PropTypes, Component } from 'react'
22

33
export default class Item extends Component {
44
render() {
5-
const { item, onClick } = this.props
5+
const { item, onClick, onFav, showBookmark } = this.props
66
return (
7-
<li onClick={onClick}>{item}</li>
7+
<li>
8+
<a onClick={onClick}>{item}</a>
9+
{!showBookmark &&
10+
<a><i className="material-icons hearted" onClick={onFav}>favorite</i></a>
11+
}
12+
{showBookmark &&
13+
<a><i className="material-icons close" onClick={onFav}>close</i></a>
14+
}
15+
</li>
816
)
917
}
1018
}
1119

1220
Item.propTypes = {
1321
item: PropTypes.any.isRequired,
14-
onClick: PropTypes.func.isRequired
22+
onClick: PropTypes.func.isRequired,
23+
onFav: PropTypes.func.isRequired,
24+
showBookmark: PropTypes.bool.isRequired
1525
}

src/app/components/popup.jsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { PropTypes, Component } from 'react'
2+
3+
export default class PopUp extends Component {
4+
render() {
5+
const { popup } = this.props
6+
return (
7+
<div>
8+
{popup &&
9+
<div className="popUp">
10+
<i className="material-icons">favorite</i>
11+
</div>
12+
}
13+
</div>
14+
)
15+
}
16+
}
17+
18+
PopUp.propTypes = {
19+
popup: PropTypes.bool.isRequired
20+
}

src/app/containers/app.jsx

+37-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { selectTitle, fetchPagesIfNeeded } from '../actions'
55
import ItemLink from '../containers/itemAction'
66
import FetchPage from '../containers/fetchpage'
77
import FetchImage from '../containers/fetchimage'
8+
import FetchBookmark from '../containers/fetchbookmark'
9+
import CloseBookmark from '../containers/closebookmark'
810

911
const pageList = ['Monkey Majik','React (JavaScript library)','Node.js','Underscore.js','Neo4j','Badminton','D3.js','HAECO','Aeronautics','Hong Kong']
1012

@@ -27,19 +29,36 @@ class Wrapper extends Component {
2729
}
2830

2931
render() {
30-
const { selectedPage, pages, isFetching } = this.props
32+
const { selectedPage, pages, isFetching, showBookmark, bookmarkList, imageByTitle } = this.props
33+
const { image } = imageByTitle[selectedPage] || { image: ""}
34+
const style = {
35+
backgroundImage: 'url(' + image + ')',
36+
backgroundRepeat: 'no-repeat',
37+
backgroundSize: 'cover'
38+
}
3139
return (
3240
<div className="contentWrapper">
3341
<div className="pageNav">
34-
<ul className="pageItem">
35-
{pageList.map((page, i) =>
36-
<ItemLink item={page} key={i}/>
37-
)}
38-
</ul>
42+
{showBookmark &&
43+
<div className="bookmarkContainer">
44+
<CloseBookmark />
45+
<h2>BOOKMARKED PAGES</h2>
46+
<FetchBookmark bookmarkList={bookmarkList}/>
47+
</div>
48+
}
49+
{!showBookmark &&
50+
<ul className="pageItem">
51+
{pageList.map((page, i) =>
52+
<ItemLink item={page} key={i}/>
53+
)}
54+
</ul>
55+
}
3956
</div>
40-
<div className="pageContent">
41-
<FetchPage pages={pages} />
42-
<FetchImage pageimage={pages.pageimage}/>
57+
<div className="pageContent" style={style}>
58+
<div className="deco">
59+
<FetchPage pages={pages}/>
60+
<FetchImage pageimage={pages}/>
61+
</div>
4362
</div>
4463
</div>
4564
)
@@ -50,12 +69,14 @@ Wrapper.propTypes = {
5069
pages: PropTypes.any.isRequired,
5170
selectedPage: PropTypes.string.isRequired,
5271
isFetching: PropTypes.bool.isRequired,
53-
dispatch: PropTypes.func.isRequired
72+
dispatch: PropTypes.func.isRequired,
73+
showBookmark: PropTypes.bool.isRequired
5474
}
5575

5676
function mapStateToProps(state) {
5777
// connecting state datat to the components as props
58-
const { selectedPage, pagesByTitle } = state
78+
const { selectedPage, pagesByTitle, showBookmark, bookmarkList, imageByTitle } = state
79+
5980
// Mapping the state props (pagesbytitle) to the components
6081
const {
6182
isFetching,
@@ -64,14 +85,16 @@ function mapStateToProps(state) {
6485
isFetching: true,
6586
items: []
6687
}
67-
68-
const { image } = "abc"
88+
// console.log(pages)
89+
// const pageimage = pages.pageimage? 'File:' + pages.pageimage : (_.sample(pages.images).title || "")
6990

7091
return {
7192
selectedPage,
7293
pages,
7394
isFetching,
74-
image
95+
showBookmark,
96+
bookmarkList,
97+
imageByTitle
7598
}
7699
}
77100

src/app/containers/closebookmark.jsx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { connect } from 'react-redux'
2+
import { toggleBookmark } from '../actions'
3+
import CloseBookmarkElem from '../components/closebookmark'
4+
5+
const mapStateToProps = (state, ownProps) => {
6+
return {
7+
onClick: ownProps.onClick
8+
}
9+
}
10+
11+
const mapDispatchToProps = (dispatch, ownProps) => {
12+
return {
13+
onClick: () => {
14+
dispatch(toggleBookmark())
15+
}
16+
}
17+
}
18+
19+
const CloseBookmark = connect(
20+
mapStateToProps,
21+
mapDispatchToProps
22+
)(CloseBookmarkElem)
23+
24+
export default CloseBookmark

src/app/containers/fetchbookmark.jsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { connect } from 'react-redux'
2+
import { toggleBookmark } from '../actions'
3+
import BookmarkList from '../components/bookmarklist'
4+
5+
const mapStateToProps = (state, ownProps) => {
6+
return {
7+
bookmarkList: state.bookmarkList
8+
}
9+
}
10+
11+
const FetchBookmarkList = connect(
12+
mapStateToProps
13+
)(BookmarkList)
14+
15+
export default FetchBookmarkList

src/app/containers/fetchimage.jsx

+16-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component, PropTypes } from 'react'
22
import { connect } from 'react-redux'
33
import { fetchImageIfNeeded } from '../actions'
44
import ImgLink from '../components/image'
5+
import { trimmer } from '../utilities/helper'
56

67
class FetchImage extends Component {
78
constructor(props) {
@@ -11,26 +12,17 @@ class FetchImage extends Component {
1112
componentDidMount() {
1213
const { dispatch, selectedPage, pageimage } = this.props
1314
if (pageimage) {
14-
dispatch(fetchImageIfNeeded(selectedPage))
15+
dispatch(fetchImageIfNeeded(selectedPage, 'File:' + pageimage))
1516
}
1617
}
1718

1819
componentWillReceiveProps(nextProps) {
19-
const { dispatch, selectedPage } = this.props
20-
21-
if (!_.isEmpty(nextProps.pageimage)){
22-
dispatch(fetchImageIfNeeded(selectedPage, 'File:' + nextProps.pageimage))
23-
// console.log(nextProps.pageimage)
20+
const { dispatch } = this.props
21+
if (!_.isEmpty(nextProps.pageimage) && !nextProps.isFetching) {
22+
return dispatch(fetchImageIfNeeded(nextProps.selectedPage, 'File:' + nextProps.pageimage))
2423
}
25-
// if (!_.isEmpty(nextProps.pages)) {
26-
// let img = nextProps.pages.pageimage? 'File:'+nextProps.pages.pageimage : nextProps.pages.images[0].title;
27-
// if (!_.isEmpty(img)){
28-
// dispatch(fetchImageIfNeeded(nextProps.pages.title, img))
29-
// }
30-
// }
3124
}
3225

33-
3426
render() {
3527
const { image } = this.props
3628
return (
@@ -45,15 +37,24 @@ FetchImage.propTypes = {
4537
}
4638

4739
const mapStateToProps = (state, ownProps) => {
48-
const { imageByTitle, selectedPage } = state
40+
const { imageByTitle, selectedPage, pagesByTitle } = state
4941
const { image } = imageByTitle[selectedPage] || {
5042
image: ""
5143
}
44+
const {
45+
isFetching,
46+
} = pagesByTitle[selectedPage] || {
47+
isFetching: true
48+
}
49+
50+
const pageimage = !_.isEmpty(ownProps.pageimage)? (ownProps.pageimage.pageimage || trimmer('File:', _.sample(ownProps.pageimage.images).title)) : "";
5251

5352
return {
5453
image: image,
5554
selectedPage,
56-
pageimage: ownProps.pageimage || ""
55+
pagesByTitle,
56+
isFetching,
57+
pageimage: pageimage
5758
}
5859
}
5960

0 commit comments

Comments
 (0)