Skip to content

Commit e9f0726

Browse files
authored
Fix lint and add CI workflow (#2)
* Fix lint issues * Remove lefthook yml * Add actions workflow * Update readme * JSX nits * Bump package
1 parent 8295353 commit e9f0726

File tree

11 files changed

+69
-180
lines changed

11 files changed

+69
-180
lines changed

.circleci/config.yml

Lines changed: 0 additions & 98 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Use Node.js
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: '18.x'
18+
cache: 'npm'
19+
- name: Install dependencies
20+
run: yarn
21+
- name: Lint
22+
run: yarn lint
23+
- name: Build package
24+
run: yarn prepare

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const { startUpload, abortUpload } = useFileUpload({
3737
});
3838

3939
const onPressUpload = async () => {
40-
const promises = data.map(item => startUpload(item));
40+
const promises = data.map((item) => startUpload(item));
4141
// Use Promise.all instead if you want to throw an error from a timeout or error.
4242
// As of October 2022 you have to polyfill allSettled in React Native.
4343
const result = await Promise.allSettled(promises);
@@ -209,7 +209,7 @@ Another downside is fault tolerance. By splitting the files into separate reques
209209

210210
### How does the local node server throttle the upload requests?
211211

212-
The local node server throttles the upload requests to simulate a real world scenario on a cellular connection or slower network. This helps test out the progress and timeout handling on the client. It does this by using the node `throttle` library. See the `/upload` route in [here](example/server/server.ts) for the details.
212+
The local node server throttles the upload requests to simulate a real world scenario on a cellular connection or slower network. This helps test out the progress and timeout handling on the client. It does this by using the [node-throttle](https://github.com/TooTallNate/node-throttle) library. See the `/upload` route in [here](example/server/server.ts) for the details.
213213

214214
### How do I bypass the throttling on the local node server?
215215

example/server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const upload = multer({
4646
method: 'POST',
4747
headers: req.headers,
4848
},
49-
requestResp => {
49+
(requestResp) => {
5050
requestResp.pipe(res);
5151
}
5252
)

example/src/App.tsx

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,27 @@ export default function App() {
5050
keysAndValues: [{ key: 'progress', value: progress }],
5151
});
5252
},
53-
onDone: data => {
54-
console.log('onDone, data: ', data);
53+
onDone: (_data) => {
54+
//console.log('onDone, data: ', data);
5555
updateItem({
56-
item: data.item,
56+
item: _data.item,
5757
keysAndValues: [{ key: 'completed', value: true }],
5858
});
5959
},
60-
onError: data => {
61-
console.log('onError, data: ', data);
60+
onError: (_data) => {
61+
//console.log('onError, data: ', data);
6262
updateItem({
63-
item: data.item,
63+
item: _data.item,
6464
keysAndValues: [
6565
{ key: 'progress', value: undefined },
6666
{ key: 'failed', value: true },
6767
],
6868
});
6969
},
70-
onTimeout: data => {
71-
console.log('onTimeout, data: ', data);
70+
onTimeout: (_data) => {
71+
//console.log('onTimeout, data: ', data);
7272
updateItem({
73-
item: data.item,
73+
item: _data.item,
7474
keysAndValues: [
7575
{ key: 'progress', value: undefined },
7676
{ key: 'failed', value: true },
@@ -80,7 +80,7 @@ export default function App() {
8080
});
8181

8282
const isUploading = useMemo(() => {
83-
return data.some(item => {
83+
return data.some((item) => {
8484
return (
8585
typeof item.progress === 'number' &&
8686
item.progress > 0 &&
@@ -96,9 +96,9 @@ export default function App() {
9696
item: Item;
9797
keysAndValues: { key: K; value: Item[K] }[];
9898
}) => {
99-
setData(prevState => {
99+
setData((prevState) => {
100100
const newState = [...prevState];
101-
const itemToUpdate = newState.find(s => s.uri === item.uri);
101+
const itemToUpdate = newState.find((s) => s.uri === item.uri);
102102

103103
if (itemToUpdate) {
104104
keysAndValues.forEach(({ key, value }) => {
@@ -118,36 +118,36 @@ export default function App() {
118118
});
119119

120120
const items: Item[] =
121-
response?.assets?.map(a => ({
121+
response?.assets?.map((a) => ({
122122
name: a.fileName!,
123123
type: a.type!,
124124
uri: a.uri!,
125125
})) ?? [];
126126

127-
setData(prevState => [...prevState, ...items]);
127+
setData((prevState) => [...prevState, ...items]);
128128
};
129129

130130
const onPressUpload = async () => {
131131
// allow uploading any that previously failed
132-
setData(prevState =>
133-
[...prevState].map(item => ({
132+
setData((prevState) =>
133+
[...prevState].map((item) => ({
134134
...item,
135135
failed: false,
136136
}))
137137
);
138138

139139
const promises = data
140-
.filter(item => typeof item.progress !== 'number') // leave out any in progress
141-
.map(item => startUpload(item));
140+
.filter((item) => typeof item.progress !== 'number') // leave out any in progress
141+
.map((item) => startUpload(item));
142142
// use Promise.all here if you want an error from a timeout or error
143143
const result = await allSettled(promises);
144144
console.log('result: ', result);
145145
};
146146

147147
const onPressDeleteItem = (item: Item) => () => {
148-
setData(prevState => {
148+
setData((prevState) => {
149149
const newState = [...prevState];
150-
const deleteIndex = prevState.findIndex(s => s.uri === item.uri);
150+
const deleteIndex = prevState.findIndex((s) => s.uri === item.uri);
151151

152152
if (deleteIndex > -1) {
153153
newState.splice(deleteIndex, 1);
@@ -226,12 +226,10 @@ export default function App() {
226226
) : null}
227227
{item.failed ? (
228228
<Pressable onPress={onPressRetry(item)}>
229-
<Text style={styles.refreshIconText}>&#x21bb;</Text>
229+
<Text style={styles.iconText}>&#x21bb;</Text>
230230
</Pressable>
231231
) : null}
232-
{item.completed ? (
233-
<Text style={styles.refreshIconText}>&#10003;</Text>
234-
) : null}
232+
{item.completed ? <Text style={styles.iconText}>&#10003;</Text> : null}
235233
<Pressable style={styles.deleteIcon} onPress={onPressDeleteItem(item)}>
236234
<Text style={styles.deleteIconText}>&#x2717;</Text>
237235
</Pressable>
@@ -250,13 +248,13 @@ export default function App() {
250248
onDragRelease={onDragRelease}
251249
dragStartAnimation={getDragStartAnimation()}
252250
>
253-
{data.map(d => renderItem(d))}
251+
{data.map((d) => renderItem(d))}
254252
</SortableGrid>
255253

256254
<View style={styles.flexContainer} />
257255
<View style={styles.row}>
258256
<Button title="Upload" onPress={onPressUpload} />
259-
{isUploading && <ActivityIndicator />}
257+
{isUploading ? <ActivityIndicator /> : null}
260258
</View>
261259
</View>
262260
</SafeAreaView>
@@ -302,7 +300,7 @@ const styles = StyleSheet.create({
302300
deleteIconText: {
303301
fontWeight: '800',
304302
},
305-
refreshIconText: {
303+
iconText: {
306304
fontSize: 64,
307305
color: '#fff',
308306
fontWeight: '800',

example/src/components/ProgressBar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useRef, useEffect } from 'react';
22
import { Animated, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
33

44
type Props = {
@@ -12,20 +12,20 @@ export default function ProgressBar({
1212
style,
1313
progressColor = '#3880ff',
1414
}: Props) {
15-
const valueAnimated = React.useRef(new Animated.Value(0)).current;
15+
const valueAnimated = useRef(new Animated.Value(0)).current;
1616
const width = valueAnimated.interpolate({
1717
inputRange: [0, 100],
1818
outputRange: ['0%', '100%'],
1919
extrapolate: 'clamp',
2020
});
2121

22-
React.useEffect(() => {
22+
useEffect(() => {
2323
Animated.timing(valueAnimated, {
2424
toValue: value,
2525
duration: 500,
2626
useNativeDriver: false,
2727
}).start();
28-
}, [value]);
28+
}, [value, valueAnimated]);
2929

3030
return (
3131
<View style={[styles.progressBar, style]}>

example/src/util/allSettled.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export const allSettled = (promises: Promise<any>[]) => {
22
return Promise.all(
3-
promises.map(promise =>
3+
promises.map((promise) =>
44
promise
5-
.then(value => ({ status: 'fulfilled', value }))
6-
.catch(reason => ({ status: 'rejected', reason }))
5+
.then((value) => ({ status: 'fulfilled', value }))
6+
.catch((reason) => ({ status: 'rejected', reason }))
77
)
88
);
99
};

lefthook.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)