<div id="app">
<main v-if="user">
<h1>Latest repositories starred</h1>
<ul>
<li v-for="repository in repositories">
<a :href="repository.html_url" target="_blank">{{repository.name}}</a>
</li>
</ul>
<p v-if="repositories.length === 0">Whoa, such empty!</p>
</main>
<div v-else>
<button @click.prevent="connect">Connect to GitHub</button>
</div>
</div>
#app {
font-family: Sans-serif;
font-size: 14px;
max-width: 695px;
}
#app div {
text-align: center;
width: 200px;
margin: 0 auto;
}
#app div::before {
display: inline-block;
content: " ";
width: 200px;
height: 200px;
background-image: url("https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png");
background-size: cover;
}
ul {
list-style: none;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
margin: 0;
padding: 0;
}
ul li {
display: inline-block;
width: 30%;
margin: 8px;
}
ul li a {
display: block;
padding: 8px;
border: 1px solid #d4d9ea;
border-radius: 4px;
box-shadow: 0 2px 4px 0 rgba(3, 13, 54, 0.26);
text-decoration: none;
color: black;
overflow:hidden;
}
ul li a:hover {
background-color: #FAFAFA;
}
var app = new Vue({
el: "#app",
data: {
user: null,
repositories: []
},
mounted: function() {
// Here we initialize Pizzly.
this.$pizzly = new Pizzly({
host: "pushtogsheet.herokuapp.com",
publishableKey: "pope8Qy8qfYyppnHRMgLMpQ8MuEUKDGeyhfGCj"
});
// If you don't have an account on Bearer.sh
// create one for free at https://www.bearer.sh/signup
// then grab your Bearer Publishable key
// (pk_production...) in the settings page.
},
methods: {
connect: function() {
// Here, we create a new method
// that "connect" a user to GitHub
this.$pizzly
.integration('github')
.connect()
.then(this.connectSuccess)
.catch(this.connectError);
},
connectSuccess: function(data) {
// On success, we update the user object
console.log(data)
this.user = data.authId;
this.fetchStarringRepositories()
},
connectError: function (err) {
console.error(err)
alert("Something went wrong. Look at the logs.")
},
fetchStarringRepositories: function() {
this.$pizzly
.integration("github")
.auth(this.user)
.get("/user/starred")
.then(response => response.json())
.then((data) => { this.repositories = data })
.catch(this.fetchError)
},
fetchError: function (err) {
console.error(err)
alert("Something went wrong. Look at the logs.")
}
}
});
This Pen doesn't use any external CSS resources.