Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
添加 Unstar 功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lvxianchao committed May 26, 2019
1 parent 97d5539 commit 8c8d291
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/js/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@
<el-card class="repository-container">
<el-header style="height: auto;">
<header>
<Star :repository="repository"></Star>

<a :href="repository.repo.html_url" target="_blank" class="full-name">
<i class="fa fa-home"></i>
<span>{{ repository.repo.full_name }}</span>
</a>

<!--复制克隆项目地址到剪切板-->
<el-tooltip effect="dark" placement="top" content="Clone with HTTPS">
<el-button type="info" icon="fa fa-clone" circle class="clone"
@click="copyCloneUrlWithHttps" size="small">
Expand Down Expand Up @@ -126,7 +129,8 @@
</el-main>

<el-aside v-show="isTocShow" class="toc-aside">
<Toc :readmeHtmlWithoutAnchor="readmeHtml" :repository="repository" @render="render"></Toc>
<Toc :readmeHtmlWithoutAnchor="readmeHtml" :repository="repository"
@render="render"></Toc>
</el-aside>
</el-container>
</el-card>
Expand All @@ -147,6 +151,7 @@
import SearchOnline from './SearchOnline';
import Donate from './Donate';
import VirtualList from 'vue-virtual-scroll-list';
import Star from './Star';
export default {
name: 'App',
Expand Down Expand Up @@ -178,7 +183,7 @@
}
},
components: {
Tags, Search, Toc, Followers, SearchOnline, Donate, VirtualList,
Tags, Search, Toc, Followers, SearchOnline, Donate, VirtualList, Star,
},
methods: {
// 处理语言 icon
Expand Down
60 changes: 60 additions & 0 deletions src/js/components/Star.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<el-tooltip effect="dark" placement="top" :content="isStarred ? 'Unstar': 'Star'">
<i class="fa" :class="isStarred ? 'fa-star': 'fa-star-o'" @click="star"></i>
</el-tooltip>
</template>

<script>
import Github from 'github-api';
export default {
name: "Star",
props: ['repository'],
data() {
return {
isStarred: true,
}
},
watch: {
'repository.repo.id'(n) {
let starredRepositoryIds = db.get('repositories').map('repo.id').value();
this.isStarred = _.includes(starredRepositoryIds, n);
}
},
methods: {
star() {
let owner = this.repository.repo.owner.login;
let repo = this.repository.repo.name;
let token = db.get('token').value();
let repository = new Github({token: token}).getRepo(owner, repo);
if (this.isStarred) {
repository.unstar();
let repositories = db.get('repositories').value();
_.remove(repositories, repository => {
return repository.repo.id === this.repository.repo.id;
});
db.set('repositories', repositories).write();
} else {
repository.star();
let obj = this.repository;
Object.assign(obj, {starred_at: ''});
db.get('repositories').push(obj).write();
}
this.isStarred = !this.isStarred;
}
}
}
</script>

<style scoped>
i {
margin-right: 15px;
cursor: pointer;
}
</style>
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "The Fucking Github",
"version": "1.2.1",
"version": "1.3.0",
"description": "View starred repositories, organizing stars, searching stars for Github.",
"homepage_url": "https://github.com/lvxianchao/the-fucking-github",
"icons": {
Expand Down

0 comments on commit 8c8d291

Please sign in to comment.