Skip to content

Commit

Permalink
adding multiple posts capability (#9)
Browse files Browse the repository at this point in the history
* adding logs metadata and second post

* adding file extensions

* adding links to markdown instead of rendering

* parameterizing link

* using react-collapse

* trying events

* cleaning up mapping

* adding focus fetching

* adding onclick
  • Loading branch information
dparkar authored Oct 3, 2017
1 parent d2d772a commit 14c3632
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 32 deletions.
10 changes: 10 additions & 0 deletions content/2017-10-01_16:23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# dplogs : Behind the scenes

<p>
React
Github Pages
Azure Application Insights
Visual Studio Code
Ubuntu
Git
</p>
16 changes: 16 additions & 0 deletions content/logs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"key":2,
"datetime":"2017-10-01T16:23:00.000Z",
"title":"dplogs_:_Behind_the_scenes",
"filename":"2017-10-01_16:23.md",
"tags":["react","ui","javascript","blog"]
},
{
"key":1,
"datetime":"2017-08-20T19:27:00.000Z",
"title":"Hello_World_!",
"filename":"2017-08-20_19:27.md",
"tags":["react","miscellaneous"]
}
]
39 changes: 36 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
"npm-run-all": "^4.0.2",
"prettier": "^1.5.2",
"prop-types": "^15.5.10",
"react": "^15.6.1",
"react": "^15.6.2",
"react-appinsights": "^1.0.2",
"react-burger-menu": "^2.1.5",
"react-chronos": "^1.0.4",
"react-collapse": "^4.0.3",
"react-dom": "^15.6.1",
"react-markdown": "^2.5.0",
"react-motion": "^0.5.2",
"react-router": "^3.0.5",
"react-vertical-timeline": "^0.1.2",
"source-map-explorer": "^1.4.0"
Expand Down
126 changes: 98 additions & 28 deletions src/logs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,129 @@ import React from 'react';
import { TrackedComponent } from 'react-appinsights';
import GitHub from 'github-api';
import ReactMarkdown from 'react-markdown';
import { Collapse } from 'react-collapse';
import { presets } from 'react-motion';
import './logs.css';

let repo;
const user = 'dparkar';
const repoName = 'blog-react';
const repoBranch = 'master';
const repoLogsFolder = 'content';
const repoContentPath = 'content';
const repoLogsMetadataFile = 'logs.json';

export default class Logs extends TrackedComponent {
constructor(props) {
super(props);
var gh = new GitHub();
// get the repo
var repo = gh.getRepo(user, repoName);
// get the folder contents
repo.getContents(repoBranch, repoLogsFolder, true, (err1, files) => {
if (err1) {
console.log(err1); // we can't get the data, for some reason
return;
}
// go through each file in the folder
files.forEach(function(file) {
repo = gh.getRepo(user, repoName);
// get the logs metadata
repo.getContents(
repoBranch,
repoContentPath + '/' + repoLogsMetadataFile,
true,
(err, logs) => {
if (err) {
console.log(err); // we can't get the data, for some reason
return;
}
logs.forEach(function(log) {
log['selected'] = false;
log['content'] = '';
}, this);
logs[0]['selected'] = true;
repo.getContents(
repoBranch,
repoLogsFolder + '/' + file.name,
repoContentPath + '/' + logs[0].filename,
true,
(err2, content) => {
if (err2) {
console.log(err2); // we can't have the data, for some reason
(err, content) => {
if (err) {
console.log(err); // we can't have the data, for some reason
return;
}
console.log(content);
this.setState({ logs: content });
logs[0].content = content;
this.setState({ logs: logs });
}
);
}, this);
});
// Update state
this.setState({ logs: logs });
}
);
// Intialize state
this.state = {
//repoName: repoName,
id: 'fetching id ...',
logs: 'fetching logs ...'
logs: []
};
}

handleClick = e => {
var logIndex = this.state.logs.findIndex(
log => log.datetime === e.currentTarget.dataset.id
);
var logs = this.state.logs;
logs.forEach(function(log) {
log['selected'] = false;
}, this);
var log = this.state.logs[logIndex];
if (log.content === '') {
repo.getContents(
repoBranch,
repoContentPath + '/' + log.filename,
true,
(err, content) => {
if (err) {
console.log(err); // we can't have the data, for some reason
return;
}
log.content = content;
log.selected = true;
logs[logIndex] = log;
this.setState({ logs: logs });
}
);
} else {
log.selected = true;
logs[logIndex] = log;
this.setState({ logs: logs });
}
};
render() {
let logTitles;
if (this.state.logs.length === 0) {
logTitles = <p>retrieving logs ...</p>;
} else {
logTitles = this.state.logs.map(log => {
if (log.selected) {
return (
<Collapse
key={log.datetime}
isOpened={true}
onClick={this.handleClick}
data-id={log.datetime}
springConfig={presets.wobbly}
>
{log.datetime + '_' + log.title} {'[' + log.tags + ']'}
<ReactMarkdown source={log.content} />
</Collapse>
);
} else {
return (
<Collapse
key={log.datetime}
isOpened={true}
onClick={this.handleClick}
data-id={log.datetime}
springConfig={presets.wobbly}
>
{log.datetime + '_' + log.title} {'[' + log.tags + ']'}
</Collapse>
);
}
});
}

return (
<div className="Logs">
<ReactMarkdown source={this.state.logs} />
{logTitles}
<p>work in progress ...</p>
<img
src="https://i.makeagif.com/media/10-27-2015/_jDzHB.gif"
alt="work in progress"
/>
<p>
See code here : {' '}
<a href="https://github.com/dparkar/blog-react">
Expand Down
15 changes: 15 additions & 0 deletions src/logs.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.ReactCollapse--collapse {
max-width: auto;
border: 1px solid rgba(3, 169, 244, 0.3);
border-radius: 10px;
background-color: rgba(255, 255, 255, 0.5);
margin-left: auto ;
margin-right: auto ;
margin-top: 1%;
margin-left: 1%;
margin-right: 1%;
cursor: pointer;
}
.ReactCollapse--collapse:hover {
border-color: cyan;
}

0 comments on commit 14c3632

Please sign in to comment.