Skip to content

Commit a60eb50

Browse files
committed
feat: support switching branches
1 parent b57e9de commit a60eb50

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

miniprogram/pages/repo/home.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Page({
1313
repo: '',
1414
detail: {},
1515
repourl: '',
16+
branches: [],
17+
branchIndex: 0,
1618
readme: '',
1719
loading: true,
1820
no: '暂无描述',
@@ -44,9 +46,9 @@ Page({
4446
REPO.getRepoInfo(query).then(res => {
4547
this.setData({
4648
detail: res,
47-
loading: false,
4849
repourl: `${res.namespace.html_url}/${res.path}`
4950
})
51+
this.fetchBranches(query)
5052
}).catch(err => {
5153
console.log(err)
5254
this.setData({
@@ -64,7 +66,38 @@ Page({
6466
})
6567
}).catch(err => {
6668
console.log(err)
69+
this.setData({
70+
readme: Base64.decode(''),
71+
})
72+
})
73+
},
74+
75+
fetchBranches (query) {
76+
REPO.getRepoBranches(query).then(res => {
77+
const index = res.findIndex(el => el.name === this.data.detail.default_branch)
78+
this.setData({
79+
branches: res,
80+
branchIndex: index,
81+
loading: false
82+
})
83+
}).catch(err => {
84+
console.log(err)
85+
this.setData({
86+
loading: false
87+
})
88+
})
89+
},
90+
91+
switchBranch (e) {
92+
this.setData({
93+
branchIndex: e.detail.value
6794
})
95+
const query = {
96+
owner: this.data.owner,
97+
repo: this.data.repo,
98+
ref: this.data.branches[this.data.branchIndex].name
99+
}
100+
this.fetchReadme(query)
68101
},
69102

70103
copyIt: function (e) {
@@ -86,7 +119,7 @@ Page({
86119
owner: this.data.owner,
87120
repo: this.data.repo,
88121
name: this.data.detail.human_name,
89-
sha: this.data.detail.default_branch
122+
sha: this.data.branches[this.data.branchIndex].name
90123
}
91124
wx.navigateTo({
92125
url: `../repo/dir?query=${JSON.stringify(query)}`

miniprogram/pages/repo/home.wxml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@
3434
</view>
3535
<view class="list">
3636
<view class="list_title">分支</view>
37-
<view class="list_content">{{ detail.default_branch }}</view>
37+
<picker bindchange="switchBranch" value="{{branchIndex}}" range="{{branches}}" range-key="name">
38+
<view class="picker">
39+
<view class="list_content">
40+
<text>{{ branches[branchIndex].name }}</text>
41+
<van-icon name="arrow" />
42+
</view>
43+
</view>
44+
</picker>
45+
<!-- <view class="list_content">{{ detail.default_branch }}</view> -->
3846
</view>
3947
<view wx:if="{{ detail.language }}" class="list">
4048
<view class="list_title">语言</view>

0 commit comments

Comments
 (0)