Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Convert everything to TypeScript #121

Merged
merged 43 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4385d36
Start ts
amaury1093 Jul 1, 2019
2ba71ab
Convert all files to TS
amaury1093 Jul 1, 2019
c911747
Make search work
amaury1093 Jul 6, 2019
1a02aaf
Make png import work
amaury1093 Jul 6, 2019
4805930
Add retry
amaury1093 Jul 6, 2019
e41774b
Make api call work
amaury1093 Jul 7, 2019
957ebaa
Add long waiting on Loading
amaury1093 Jul 7, 2019
8f8abe1
Make screens work
amaury1093 Jul 7, 2019
156a810
Make cigarettes work
amaury1093 Jul 7, 2019
3fa011d
Make header work
amaury1093 Jul 7, 2019
7d1db03
Reverse geocoding
amaury1093 Jul 7, 2019
7e3b3b8
Make details work
amaury1093 Jul 7, 2019
e137e0b
Make search work
amaury1093 Jul 7, 2019
4bcc494
Fix reload app
amaury1093 Jul 7, 2019
8f992fe
Make tests pass
amaury1093 Jul 7, 2019
0fcf5e3
Run eslint
amaury1093 Jul 7, 2019
5edd500
AqiHistory
amaury1093 Jul 9, 2019
f05a927
Add History manager back
amaury1093 Jul 9, 2019
704bb62
Start getting background location
amaury1093 Jul 9, 2019
9784aa1
Remove circular dependency
amaury1093 Jul 10, 2019
28b334c
Fix isSaveNeeded
amaury1093 Jul 10, 2019
2e54f5e
Add getData for testing
amaury1093 Jul 10, 2019
8462eeb
Add clearTable
amaury1093 Jul 10, 2019
60874bd
Fix tests
amaury1093 Jul 10, 2019
50af1ec
Update README
amaury1093 Jul 10, 2019
2a03a7f
Remove vs code settings
amaury1093 Jul 10, 2019
6135652
Fix too many requests
amaury1093 Jul 12, 2019
9886b4f
Add task to save to AsyncStorage
amaury1093 Jul 13, 2019
9206856
Return correct background fetch response
amaury1093 Jul 13, 2019
cf203ab
Refactor a bit the components
amaury1093 Jul 13, 2019
b1eed90
Make scroll work nicely
amaury1093 Jul 13, 2019
5fd5ccb
Add shadow on buttons
amaury1093 Jul 13, 2019
40f8848
Make stuff work
amaury1093 Jul 13, 2019
a516044
Weekly monthly
amaury1093 Jul 13, 2019
86d52a0
Calculate cigarettes
amaury1093 Jul 13, 2019
c1fed0b
Small fixes
amaury1093 Jul 13, 2019
bce6ecb
Small fixes
amaury1093 Jul 13, 2019
b12ee31
Small tweaks with icons
amaury1093 Jul 14, 2019
eb862cb
Add more dev info
amaury1093 Jul 16, 2019
050761c
Reverse geocode in search
amaury1093 Jul 16, 2019
d7ba1fd
Small tweaks
amaury1093 Jul 16, 2019
8c029ed
Small tweaks
amaury1093 Jul 17, 2019
d44d40b
Update icons
amaury1093 Jul 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix too many requests
  • Loading branch information
amaury1093 committed Jul 12, 2019
commit 6135652d64ffb68be7f326dc16477b04fd958281
30 changes: 15 additions & 15 deletions App/managers/AqiHistoryDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface AqiHistoryItem extends AqiHistoryItemInput {
id: number;
}

export const SAVE_DATA_INTERVAL = 3600 * 1000; // 1 hour
export const SAVE_DATA_INTERVAL = 3600; // 1 hour in s
const AQI_HISTORY_DB = 'AQI_HISTORY_DB';
const AQI_HISTORY_TABLE = 'AqiHistory';

Expand Down Expand Up @@ -65,7 +65,7 @@ function initDb () {
() => resolve(db),
(_transaction: Transaction, error: Error) => reject(error)
);
});
}, reject);
}) as Promise<Database>,
toError
)
Expand All @@ -91,18 +91,18 @@ function isSaveNeeded () {
TE.tryCatch(
() =>
new Promise((resolve, reject) => {
db.readTransaction((tx: Transaction) => {
db.transaction((tx: Transaction) => {
// Get time of `SAVE_DATA_INTERVAL`ms before now
const now = new Date();
now.setMilliseconds(now.getMilliseconds() - SAVE_DATA_INTERVAL);

tx.executeSql(
`
SELECT * FROM ${AQI_HISTORY_TABLE}
WHERE creationTime > ?
WHERE creationTime > datetime(?)
LIMIT 1
`,
[now.getTime() / 1000],
[now.toISOString()],
(_transaction: Transaction, resultSet: ResultSet) => {
if (resultSet.rows.length > 0) {
try {
Expand All @@ -122,7 +122,7 @@ function isSaveNeeded () {
},
(_transaction: Transaction, error: Error) => reject(error)
);
});
}, reject);
}) as Promise<boolean>,
toError
)
Expand Down Expand Up @@ -167,7 +167,7 @@ export function saveData (value: AqiHistoryItemInput) {
() => resolve(),
(_transaction: Transaction, error: Error) => reject(error)
);
});
}, reject);
}) as Promise<void>,
toError
)
Expand All @@ -187,22 +187,22 @@ export function getAveragePm25 (date: Date) {
TE.tryCatch(
() =>
new Promise((resolve, reject) => {
db.readTransaction((tx: Transaction) => {
db.transaction((tx: Transaction) => {
console.log(
`<AqiHistoryDb> - getAveragePm25 - Reading data since ${date.toISOString()}`
);

tx.executeSql(
`
SELECT AVG(rawPm25) FROM ${AQI_HISTORY_TABLE}
WHERE creationTime > ?
WHERE creationTime > datetime(?)
`,
[date.getTime() / 1000],
[date.toISOString()],
(_transaction: Transaction, resultSet: ResultSet) =>
resolve(resultSet.rows.item(0)['AVG(rawPm25)']),
(_transaction: Transaction, error: Error) => reject(error)
);
});
}, reject);
}) as Promise<number>,
toError
)
Expand All @@ -223,7 +223,7 @@ export function getData (limit: number) {
TE.tryCatch(
() =>
new Promise((resolve, reject) => {
db.readTransaction((tx: Transaction) => {
db.transaction((tx: Transaction) => {
tx.executeSql(
`
SELECT * FROM ${AQI_HISTORY_TABLE}
Expand All @@ -235,7 +235,7 @@ export function getData (limit: number) {
resolve(resultSet.rows._array),
(_transaction: Transaction, error: Error) => reject(error)
);
});
}, reject);
}) as Promise<AqiHistoryItem[]>,
toError
)
Expand All @@ -253,14 +253,14 @@ export function clearTable () {
TE.tryCatch(
() =>
new Promise((resolve, reject) => {
db.readTransaction((tx: Transaction) => {
db.transaction((tx: Transaction) => {
tx.executeSql(
`DROP TABLE ${AQI_HISTORY_TABLE}`,
[],
() => resolve(undefined as void),
(_transaction: Transaction, error: Error) => reject(error)
);
});
}, reject);
}) as Promise<void>,
toError
)
Expand Down
2 changes: 1 addition & 1 deletion App/managers/AqiHistoryTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { LatLng } from '../stores/location';

export const AQI_HISTORY_TASK = 'AQI_HISTORY_TASK';

defineTask(AQI_HISTORY_TASK, async ({ data, error }) => {
defineTask(AQI_HISTORY_TASK, ({ data, error }) => {
if (error) {
console.log(`<AqiHistoryTask> - defineTask - Error ${error.message}`);
return;
Expand Down
12 changes: 8 additions & 4 deletions App/stores/location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

import * as Permissions from 'expo-permissions';
import * as ExpoLocation from 'expo-location';
import * as Permissions from 'expo-permissions';
import { isTaskRegisteredAsync } from 'expo-task-manager';
import { pipe } from 'fp-ts/lib/pipeable';
import * as T from 'fp-ts/lib/Task';
import * as TE from 'fp-ts/lib/TaskEither';
Expand Down Expand Up @@ -65,9 +66,12 @@ function fetchGpsPosition () {
console.log('<LocationContext> - fetchGpsPosition - Fetching location');

// Start the task to record periodically on the background the location
ExpoLocation.startLocationUpdatesAsync(AQI_HISTORY_TASK, {
timeInterval: SAVE_DATA_INTERVAL
});
const isRegistered = await isTaskRegisteredAsync(AQI_HISTORY_TASK);
if (!isRegistered) {
ExpoLocation.startLocationUpdatesAsync(AQI_HISTORY_TASK, {
timeInterval: SAVE_DATA_INTERVAL * 1000 // in ms
});
}

return ExpoLocation.getCurrentPositionAsync({
timeout: 5000
Expand Down