import React from 'react';
import {
HashRouter as Router,
Switch,
Route,
Link,
useParams
} from "react-router-dom";
import './App.css';
class Album extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null,
media_items: null,
};
}
componentDidMount() {
let {album} = this.props;
fetch(process.env.PUBLIC_URL + `/api/album/${album}`)
.then(res => res.json())
.then(
(result) => this.setState({media_items: result}),
(error) => this.setState({error}),
);
}
render() {
let {error, media_items} = this.state;
console.log(this.state);
if (error !== null) {
return
Error: {JSON.stringify(error)} ;
} else if (media_items !== null) {
console.log(media_items);
return media_items.map((mi) => {
// TODO(wathiede): use coverPhotoMediaItemId and fetch from a
// locally cached image.
return
{ mi.filename}
});
} else {
return Loading... ;
}
}
}
class AlbumIndex extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null,
albums: null,
};
}
componentDidMount() {
fetch(process.env.PUBLIC_URL + "/api/albums")
.then(res => res.json())
.then(
(result) => this.setState({albums: result}),
(error) => this.setState({error}),
);
}
render() {
let {error, albums} = this.state;
if (error !== null) {
return Error: {JSON.stringify(error)} ;
} else if (albums !== null) {
console.log(albums);
return albums.map((a) => {
let img = ;
if (a.coverPhotoMediaItemId !== undefined) {
img =
}
let figure =
{img}
{ a.title || "No title" } - { a.mediaItemsCount || 0 } photos
;
return
{ figure }
});
} else {
return Loading... ;
}
}
}
const AlbumRoute = () => {
// We can use the `useParams` hook here to access
// the dynamic pieces of the URL.
let { album_id } = useParams();
return ;
}
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
curAlbum: window.location.hash,
};
}
render() {
let {curAlbum} = this.state;
console.log(this.state);
let content;
return (
);
}
}
export default App;