Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xianshenglu committed Apr 27, 2022
2 parents 2addb88 + 64e72bc commit d47d24f
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
20 changes: 20 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# cloudflare-ip-tester-app

### Inspired by

- [CloudflareSpeedTest](https://github.com/XIU2/CloudflareSpeedTest)
- [cloudflare-ip-tester](https://github.com/TulvL/cloudflare-ip-tester)

### Functions

- test cloudflare-ip as many as you want


- generate a history statistics based on your test results.

<div style="display: flex;flex-flow:row wrap;">
<img src="./assets/images/test-run-min.jpg" height="600">
<img src="./assets/images/test-statistics-min.jpg" height="600">
</div>

### MIT License
Binary file added assets/images/test-run-min.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/test-statistics-min.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 37 additions & 7 deletions screens/TestRunScreen/components/TestPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleSheet, Button, TextInput } from "react-native";
import { Text, View } from "@/components/Themed";
import { useState } from "react";
import { useEffect, useState } from "react";
import { responseTestService } from "@/services/ResponseTest.service";
import { downloadTestService } from "@/services/DownloadTest.service";
import { TableHeader } from "@/components/Table/TableHeader";
Expand All @@ -9,7 +9,8 @@ import { useTableData } from "../hooks/useTableData";
import { useTestIpCount } from "../hooks/useTestIpCount";
import { TableRows } from "@/components/Table/TableRows";
import { initialTestPageTableHeaderCols, MyTableHeaderColumn } from "../model";
import { RequestStatus } from "@/typings";
import { useTestRunningStatus } from "../hooks/useTestRunningStatus";
import { miniStyle } from "@/theme";

export default function TestPage({ path }: { path: string }) {
const { testIpCount, setTestIpCount, getIpList } = useTestIpCount();
Expand Down Expand Up @@ -37,13 +38,32 @@ export default function TestPage({ path }: { path: string }) {
changeTableHeadersSortType,
} = useTableHeader<MyTableHeaderColumn>(initialTestPageTableHeaderCols);

const { testRunningStatus, nextTestRunningStatus } = useTestRunningStatus();

function onReset() {
responseTestService.stop();
downloadTestService.stop();
resetTableData();
resetTableHeader();
initTableData(getIpList());
const newIpList = getIpList();
initTableData(newIpList);
nextTestRunningStatus();
}

useEffect(() => {
// in the future may need to add a status check
startResponseSpeedTest(
getSelectedIpList(),
Number(testIpCoCurrentCount),
testUrl
);
startDownloadSpeedTest(
getSelectedIpList(),
Number(testIpCoCurrentCount),
testUrl
);
}, [testRunningStatus]);

function onSort(
colId: MyTableHeaderColumn["id"],
sortType: MyTableHeaderColumn["sort"]
Expand All @@ -70,7 +90,7 @@ export default function TestPage({ path }: { path: string }) {
}
title="TEST RESPOND "
/>
<View style={{ marginRight: 10 }}></View>
<View style={{ marginRight: 5 }}></View>
<Button
onPress={() =>
startDownloadSpeedTest(
Expand All @@ -81,7 +101,7 @@ export default function TestPage({ path }: { path: string }) {
}
title="TEST DOWNLOAD"
/>
<View style={{ marginRight: 10 }}></View>
<View style={{ marginRight: 5 }}></View>
<Button onPress={onReset} title="START" />
</View>
<View style={styles.toolbar}>
Expand Down Expand Up @@ -109,8 +129,18 @@ export default function TestPage({ path }: { path: string }) {
/>
</View>

<TableHeader onSort={onSort} cols={tableHeaders} />
<TableRows rows={tableData} columns={tableHeaders} rowKeyName={"ip"} />
<TableHeader
onSort={onSort}
cols={tableHeaders}
style={{ cellTextStyle: miniStyle.textStyle }}
/>

<TableRows
rows={tableData}
columns={tableHeaders}
rowKeyName={"ip"}
style={{ cellTextStyle: miniStyle.textStyle }}
/>
</View>
);
}
Expand Down
24 changes: 24 additions & 0 deletions screens/TestRunScreen/hooks/useTestRunningStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useState } from "react";
export enum TestRunningStatus {
Uninitialized = "Uninitialized",
Running = "Running",
}
const nextTestRunningStatusMap = {
[TestRunningStatus.Uninitialized]: TestRunningStatus.Running as const,
[TestRunningStatus.Running]: TestRunningStatus.Uninitialized as const,
};
export function useTestRunningStatus() {
const [testRunningStatus, setTestRunningStatus] =
useState<`${TestRunningStatus}`>(TestRunningStatus.Uninitialized);

function nextTestRunningStatus() {
setTestRunningStatus((prev) => {
return nextTestRunningStatusMap[prev];
});
}

return {
testRunningStatus,
nextTestRunningStatus,
};
}
6 changes: 6 additions & 0 deletions theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { StyleSheet } from "react-native";
export const miniStyle = StyleSheet.create({
textStyle: {
fontSize: 12,
},
});

0 comments on commit d47d24f

Please sign in to comment.