Skip to content

Commit 0cca038

Browse files
committed
fix: lint errors
1 parent e6ea0c8 commit 0cca038

2 files changed

Lines changed: 32 additions & 20 deletions

File tree

examples/sync-demo-bare/src/App.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,14 @@ function TestApp() {
5353
syncError,
5454
currentSyncInterval,
5555
} = useSyncStatus();
56-
const [nextSyncIn, setNextSyncIn] = useState<number | null>(null);
56+
const [now, setNow] = useState(() => Date.now());
5757

5858
useEffect(() => {
59-
if (!lastSyncTime || !currentSyncInterval) {
60-
setNextSyncIn(null);
61-
return;
62-
}
63-
64-
const update = () => {
65-
const remaining = Math.max(
66-
0,
67-
Math.ceil((lastSyncTime + currentSyncInterval - Date.now()) / 1000),
68-
);
69-
setNextSyncIn(remaining);
70-
};
59+
if (!lastSyncTime || !currentSyncInterval) return;
7160

72-
update();
73-
const id = setInterval(update, 1000);
61+
const id = setInterval(() => {
62+
setNow(Date.now());
63+
}, 1000);
7464
return () => clearInterval(id);
7565
}, [lastSyncTime, currentSyncInterval]);
7666
const [searchText, setSearchText] = useState('');
@@ -98,6 +88,15 @@ function TestApp() {
9888
return allRows.filter(row => row.value.toLowerCase().includes(searchLower));
9989
}, [allRows, searchText]);
10090

91+
const nextSyncIn = useMemo(() => {
92+
if (!lastSyncTime || !currentSyncInterval) return null;
93+
94+
return Math.max(
95+
0,
96+
Math.ceil((lastSyncTime + currentSyncInterval - now) / 1000),
97+
);
98+
}, [currentSyncInterval, lastSyncTime, now]);
99+
101100
// Hook 2: useOnTableUpdate - Row-level update notifications
102101
// Fires for individual row changes with automatic row data fetching
103102
useOnTableUpdate<{ id: string; value: string; created_at: string }>({

src/core/pushNotifications/__tests__/pushNotificationSyncTask.test.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ describe('pushNotificationSyncTask', () => {
101101
const foregroundCallback = jest.fn().mockResolvedValue(undefined);
102102
(getPersistedConfig as jest.Mock).mockResolvedValue({ debug: false });
103103
(isSqliteCloudNotification as jest.Mock).mockReturnValue(true);
104-
(getForegroundSyncCallback as jest.Mock).mockReturnValue(foregroundCallback);
104+
(getForegroundSyncCallback as jest.Mock).mockReturnValue(
105+
foregroundCallback
106+
);
105107
(AppState as any).currentState = 'active';
106108

107109
await handler({
@@ -117,7 +119,9 @@ describe('pushNotificationSyncTask', () => {
117119
const foregroundCallback = jest.fn().mockResolvedValue(undefined);
118120
(getPersistedConfig as jest.Mock).mockResolvedValue({ debug: false });
119121
(isSqliteCloudNotification as jest.Mock).mockReturnValue(true);
120-
(getForegroundSyncCallback as jest.Mock).mockReturnValue(foregroundCallback);
122+
(getForegroundSyncCallback as jest.Mock).mockReturnValue(
123+
foregroundCallback
124+
);
121125
(AppState as any).currentState = 'background';
122126

123127
await handler({
@@ -133,7 +137,9 @@ describe('pushNotificationSyncTask', () => {
133137
const foregroundCallback = jest.fn().mockResolvedValue(undefined);
134138
(getPersistedConfig as jest.Mock).mockResolvedValue({ debug: false });
135139
(isSqliteCloudNotification as jest.Mock).mockReturnValue(true);
136-
(getForegroundSyncCallback as jest.Mock).mockReturnValue(foregroundCallback);
140+
(getForegroundSyncCallback as jest.Mock).mockReturnValue(
141+
foregroundCallback
142+
);
137143
(AppState as any).currentState = 'inactive';
138144

139145
await handler({
@@ -146,7 +152,12 @@ describe('pushNotificationSyncTask', () => {
146152
});
147153

148154
it('falls through to executeBackgroundSync when callback is null and app is backgrounded', async () => {
149-
const fakeConfig = { debug: false, databaseId: 'db_id', databaseName: 'test.db', tablesToBeSynced: [] };
155+
const fakeConfig = {
156+
debug: false,
157+
databaseId: 'db_id',
158+
databaseName: 'test.db',
159+
tablesToBeSynced: [],
160+
};
150161
(getPersistedConfig as jest.Mock).mockResolvedValue(fakeConfig);
151162
(isSqliteCloudNotification as jest.Mock).mockReturnValue(true);
152163
(getForegroundSyncCallback as jest.Mock).mockReturnValue(null);
@@ -166,7 +177,9 @@ describe('pushNotificationSyncTask', () => {
166177
.mockRejectedValue(new Error('sync failed'));
167178
(getPersistedConfig as jest.Mock).mockResolvedValue({ debug: false });
168179
(isSqliteCloudNotification as jest.Mock).mockReturnValue(true);
169-
(getForegroundSyncCallback as jest.Mock).mockReturnValue(foregroundCallback);
180+
(getForegroundSyncCallback as jest.Mock).mockReturnValue(
181+
foregroundCallback
182+
);
170183

171184
await expect(handler({ data: {}, error: null })).resolves.toBeUndefined();
172185
});

0 commit comments

Comments
 (0)