Skip to content
Open

Done #135

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ <h3>Issues</h3>
<script src="index.js"></script>
<script id="repo-template" type="text/x-handlebars-template">
<h3>Forked Successfully!</h3>
<!--fill me in with templatey goodness-->
<p><strong>{{full_name}}:</strong></p>
<a href="{{html_url}}" target="_blank">{{html_url}}</a>
</script>
<script id="issues-template" type="text/x-handlebars-template">
<!--fill me in with templatey goodness-->
<ul>
{{#each this}}
<li>
<p>{{title}}</p>
<p>{{body}}</p>
<p><a href="{{html_url}}">{{url}}</a></p>
</li>
{{/each}}
</ul>
</script>
</body>
</html>
34 changes: 31 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
const userName = ''
const baseApi = 'https://api.github.com/'
const fork = `${userName}/javascript-fetch-lab`

function getIssues() {

fetch(`${baseApi}repos/${fork}/issues`).
then(resp => resp.json()).
then(json => showIssues(json))
}

function showIssues(json) {
const template = Handlebars.compile(document.getElementById('issues-template').innerHTML)
document.getElementById('issues').innerHTML = template(json)
}

function createIssue() {
const issueTitle = document.getElementById('title').value
const issueBody = document.getElementById('body').value
const postData = { title: issueTitle, body: issueBody }

fetch(`${baseApi}repos/${fork}/issues`, {
method: 'post',
headers: {
Authorization: `token ${getToken()}`
},
body: JSON.stringify(postData)
}).then(resp => getIssues())
}

function showResults(json) {
const template = Handlebars.compile(document.getElementById('repo-template').innerHTML)
document.getElementById('results').innerHTML = template(json)
}

function forkRepo() {
const repo = 'learn-co-curriculum/javascript-fetch-lab'
//use fetch to fork it!

fetch(`${baseApi}repos/${repo}/forks`, {
method: 'post',
headers: {
Authorization: `token ${getToken()}`
}
}).then(resp => resp.json()).
then(json => showResults(json))
}

function getToken() {
//change to your token to run in browser, but set
//back to '' before committing so all tests pass
return ''
}