-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIssues.js
89 lines (85 loc) · 2.06 KB
/
Issues.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {
Button,
Card,
CheckBox,
StyleService,
Text,
} from '@ui-kitten/components'
import React from 'react'
import { View } from 'react-native'
import { useIssues } from '../hooks/useGithub'
import { ImageOverlay } from './ImageOverlay'
import { Tag } from './Tag'
export const Issues = ({ url, selected, onSelectedChange }) => {
if (!url) return <Text>No repo</Text>
const urlWithoutProtocol = url
.toLowerCase()
.replace('https://', '')
.replace('http://', '')
const [owner, repo] = urlWithoutProtocol.split('?')[0].split('/').slice(-2)
const { data, error, isFetching } = useIssues(owner, repo)
if (isFetching)
return (
<Text>
Loading...{owner} {repo}
</Text>
)
if (error)
return (
<Text>
Error loading issues: {error.message} {owner} {repo}
</Text>
)
const toggle = (issue, checked) => {
if (checked) {
onSelectedChange([...selected, issue])
} else {
onSelectedChange(selected.filter((s) => s.id !== issue.id))
}
}
return (
<View style={styles.container}>
{data.map((issue) => (
<View style={styles.row}>
<CheckBox checked={selected.includes(issue)} onChange={(checked) => toggle(issue, checked) }/>
<View style={styles.issue} key={issue.id}>
<Text category="h6">
#{issue.number} {issue.title}
</Text>
<Text category="s1" style={styles.body}>
{issue.body}
</Text>
<View style={styles.tags}>
{issue.labels.map((label, index) => <Tag key={index}>{label.name}</Tag>)}
</View>
</View>
</View>
))}
</View>
)
}
const styles = StyleService.create({
image: {
height: 100,
},
row: {
flexDirection: 'row',
},
issue: {
marginLeft: 16,
marginBottom: 16,
},
tags: {
flexDirection: 'row',
marginHorizontal: -4,
marginVertical: 4,
},
container: { marginHorizontal: 16 },
detailItem: {
borderRadius: 16,
},
body: {
overflow: '',
maxHeight: 100,
},
})