Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Roparat Sukapirom authored and Roparat Sukapirom committed Sep 25, 2016
0 parents commit 67a5386
Show file tree
Hide file tree
Showing 20 changed files with 1,541 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
build

# misc
.DS_Store
.env
npm-debug.log
941 changes: 941 additions & 0 deletions README.md

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "test-react",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.5.1"
},
"dependencies": {
"bootstrap": "^3.3.7",
"jquery": "^3.1.1",
"react": "^15.3.2",
"react-copy-to-clipboard": "^4.2.3",
"react-dom": "^15.3.2",
"react-router": "^2.8.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"homepage": "https://www.roparat.com/react-picasa"
}
Binary file added public/favicon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favico.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>
25 changes: 25 additions & 0 deletions src/AlbumCover.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.gallery-panel{
margin: 5px 5px 5px 5px;
max-width: calc(240px + 10px);
background-color: mintcream;
}

.gallery-image{
max-width: 240px;
height: auto;
}

.gallery-panel-title{
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.flex{
display: flex;
flex-direction: row;
align-items: flex-start;
flex-wrap: wrap;
justify-content: center;
}
35 changes: 35 additions & 0 deletions src/AlbumCover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import './AlbumCover.css'

class AlbumCover extends React.Component {

constructor(){
super();
this._handleClick = this._handleClick.bind(this);
}

static get propTypes() {
return {

}
}

_handleClick(e){
console.log(`handleClick ${e}`);
alert("Click");
this.props.onAlbumClick(this.props.albumId);
}

render(){
return (
<div className="gallery-panel thumbnail" >
<div className="gallery-panel-image">
<img className="gallery-image" src={this.props.imageURL} alt={this.props.title} />
</div>
<div className="gallery-panel-title">{this.props.title}</div>
</div>
);
}
}

export default AlbumCover;
73 changes: 73 additions & 0 deletions src/AllGallery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react';
import * as PicasaService from './PicasaService';
import AlbumCover from './AlbumCover';
import {Link} from 'react-router';
import Loading from './Loading';

export default class AllGallery extends React.Component {

constructor(props) {
super(props);
this.state = {
isDone:false
};
this.loadSingleGallery = this.loadSingleGallery.bind(this);
}

static get propTypes() {
return {
username : React.PropTypes.string
}
}

loadSingleGallery( albumid ){

}

render() {
if (this.state.isDone){
var galleryjsx = this.gallerys.gallerys.map((gallery)=>{
return (
<Link key={gallery.albumid} to={`/gallery/${gallery.albumid}`}>
<AlbumCover key={`a-${gallery.albumid}`} albumid={gallery.albumid} imageURL={PicasaService.getImageUrl(gallery.albumCover,240,true)} title={gallery.title} onAlbumClick={this.loadSingleGallery}/>
</Link>
);
});
return <div className="gallery-list flex">{galleryjsx}</div>;
} else {
return <Loading />;
}

}

componentDidUpdate(prevProps, prevState, prevContext){
if (this.context.username !== prevContext.username){
console.log('loading...');
this.setState({isDone:false});
var username = this.props.username || this.context.username;
PicasaService.fetchGalleryList(username)
.then((result) => {
this.gallerys = result;
this.setState({
isDone:true
});
});
}
}

componentDidMount() {
var username = this.props.username || this.context.username;

PicasaService.fetchGalleryList(username)
.then((result) => {
this.gallerys = result;
this.setState({
isDone:true
});
});
}
}

AllGallery.contextTypes = {
username: React.PropTypes.string
};
24 changes: 24 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}

.App-header {
background-color: #222;
padding: 20px;
color: white;
text-align: center;
}

.App-intro {
font-size: large;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

.panel {
margin: 5px;
}
133 changes: 133 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React, { Component } from 'react';
import './App.css';
import {IndexLink} from 'react-router';

class NavBar extends React.Component {
render(){
return (
<nav className="navbar navbar-default">
<div className="navbar-header">
<IndexLink className="navbar-brand" to="/">Picasa Gallery</IndexLink>
</div>
</nav>
);
}
};

class SettingsPanel extends React.Component {
constructor(){
super();
this.changeImageSize = this.changeImageSize.bind(this);
this.changeUsername = this.changeUsername.bind(this);
this.updateUsername = this.updateUsername.bind(this);
this.state = {
username: ''
}
}

componentWillMount() {
this.setState({
username:this.context.username
});
}

componentWillReceiveProps(nextProps, nextContext){
console.log(`will receive props ${nextProps} ${nextContext}`);
this.setState({
username:nextContext.username
});
}

render(){
return (
<div className="panel panel-default">
<div className="panel-body">
<form className="form-inline">
<div className="form-group">
<label data-for="username">Name</label>
<span> </span>
<input type="text" className="form-control" id="username" placeholder="roparat" value={this.state.username} onChange={this.changeUsername}/>
</div>
<span> </span>
<button type="submit" className="btn btn-default" onClick={this.updateUsername}>Update</button>
<span> </span>
<div className="form-group">
<label data-for="imagesize">Image Size</label>
<span> </span>
<input type="number" className="form-control" id="imagesize" placeholder="1024" value={this.context.imageSize} onChange={this.changeImageSize}/>
</div>
</form>
</div>
</div>
);
}
changeImageSize(e){
this.props.onChange({imageSize:parseInt(e.target.value,10)});
}

changeUsername(e){
this.setState({username:e.target.value});
}

updateUsername(e){
this.props.onChange({username:this.state.username});
}
}

SettingsPanel.contextTypes = {
username: React.PropTypes.string,
imageSize: React.PropTypes.number
};

class App extends Component {

constructor(){
super();
this.state = {
username:'roparat',
imageSize:1024
};
this.handleSettingsChange = this.handleSettingsChange.bind(this);
}

getChildContext(){
console.log('getChildContext');
return {
username:this.state.username,
imageSize:this.state.imageSize
}
}

handleSettingsChange(settings){
console.log('handleSettingsChange');
if (settings.imageSize){
this.setState({imageSize:settings.imageSize});
}
if (settings.username){
this.setState({username:settings.username});
}
}

render() {
return (
<div className="App">
<NavBar/>
<SettingsPanel onChange={this.handleSettingsChange}/>
<div className="content">
{this.props.children}
</div>
</div>
);
}

componentWillReceiveProps(props){
console.log(props);
}
}

App.childContextTypes = {
username : React.PropTypes.string,
imageSize : React.PropTypes.number
};

export default App;
8 changes: 8 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
10 changes: 10 additions & 0 deletions src/Loading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.loading{
width: 100%;
}

.loading-image{
margin: 10px auto 10px auto;
left: 0;
right: 0;
position: absolute;
}
Loading

0 comments on commit 67a5386

Please sign in to comment.