|
1 | 1 | import { useState, useEffect } from 'react' |
2 | 2 | import { Platform } from 'react-native'; |
3 | 3 | import { db } from "../db/dbConnection"; |
4 | | -import { CONNECTION_STRING, API_TOKEN } from "@env"; |
| 4 | +import { ANDROID_CONNECTION_STRING, CONNECTION_STRING, API_TOKEN } from "@env"; |
5 | 5 | import { getDylibPath } from "@op-engineering/op-sqlite"; |
6 | 6 | import { randomUUID } from 'expo-crypto'; |
7 | 7 | import { useSyncContext } from '../components/SyncContext'; |
@@ -65,12 +65,19 @@ const useCategories = () => { |
65 | 65 | await db.execute('CREATE TABLE IF NOT EXISTS tags (uuid TEXT NOT NULL PRIMARY KEY, name TEXT, UNIQUE(name));') |
66 | 66 | await db.execute('CREATE TABLE IF NOT EXISTS tasks_tags (uuid TEXT NOT NULL PRIMARY KEY, task_uuid TEXT, tag_uuid TEXT, FOREIGN KEY (task_uuid) REFERENCES tasks(uuid), FOREIGN KEY (tag_uuid) REFERENCES tags(uuid));') |
67 | 67 |
|
68 | | - await db.execute(`SELECT cloudsync_init('*');`); |
| 68 | + await db.execute(`SELECT cloudsync_init('tasks');`); |
| 69 | + await db.execute(`SELECT cloudsync_init('tags');`); |
| 70 | + await db.execute(`SELECT cloudsync_init('tasks_tags');`); |
| 71 | + |
69 | 72 | await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', [randomUUID(), 'Work']) |
70 | 73 | await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', [randomUUID(), 'Personal']) |
71 | 74 |
|
72 | | - await db.execute(`SELECT cloudsync_network_init('${CONNECTION_STRING}');`); |
73 | | - await db.execute(`SELECT cloudsync_network_set_token('${API_TOKEN}');`) |
| 75 | + if ((ANDROID_CONNECTION_STRING || CONNECTION_STRING) && API_TOKEN) { |
| 76 | + await db.execute(`SELECT cloudsync_network_init('${Platform.OS == 'android' && ANDROID_CONNECTION_STRING ? ANDROID_CONNECTION_STRING : CONNECTION_STRING}');`); |
| 77 | + await db.execute(`SELECT cloudsync_network_set_token('${API_TOKEN}');`) |
| 78 | + } else { |
| 79 | + throw new Error('No valid CONNECTION_STRING or API_TOKEN provided, cloudsync_network_init will not be called'); |
| 80 | + } |
74 | 81 |
|
75 | 82 | db.execute('SELECT cloudsync_network_sync(100, 10);') |
76 | 83 | getCategories() |
|
0 commit comments