Skip to content

Commit 893e88c

Browse files
DominicGBauerDominicGBauer
and
DominicGBauer
authored
chore: handle no attachment queue (#162)
Co-authored-by: DominicGBauer <[email protected]>
1 parent ed461d0 commit 893e88c

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

demos/react-native-supabase-todolist/library/powersync/system.ts

+19-15
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { SupabaseConnector } from '../supabase/SupabaseConnector';
99
import { KVStorage } from '../storage/KVStorage';
1010
import { PhotoAttachmentQueue } from './PhotoAttachmentQueue';
1111
import { type AttachmentRecord } from '@powersync/attachments';
12+
import { AppConfig } from '../supabase/AppConfig';
1213

1314
export class System {
1415
kvStorage: KVStorage;
1516
storage: SupabaseStorageAdapter;
1617
supabaseConnector: SupabaseConnector;
1718
powersync: AbstractPowerSyncDatabase;
18-
19-
attachmentQueue: PhotoAttachmentQueue;
19+
attachmentQueue: PhotoAttachmentQueue | undefined = undefined;
2020

2121
constructor() {
2222
this.kvStorage = new KVStorage();
@@ -29,26 +29,30 @@ export class System {
2929
this.storage = this.supabaseConnector.storage;
3030
this.powersync = factory.getInstance();
3131

32-
this.attachmentQueue = new PhotoAttachmentQueue({
33-
powersync: this.powersync,
34-
storage: this.storage,
35-
// Use this to handle download errors where you can use the attachment
36-
// and/or the exception to decide if you want to retry the download
37-
onDownloadError: async (attachment: AttachmentRecord, exception: any) => {
38-
if (exception.toString() === 'StorageApiError: Object not found') {
39-
return { retry: false };
32+
if (AppConfig.supabaseBucket) {
33+
this.attachmentQueue = new PhotoAttachmentQueue({
34+
powersync: this.powersync,
35+
storage: this.storage,
36+
// Use this to handle download errors where you can use the attachment
37+
// and/or the exception to decide if you want to retry the download
38+
onDownloadError: async (attachment: AttachmentRecord, exception: any) => {
39+
if (exception.toString() === 'StorageApiError: Object not found') {
40+
return { retry: false };
41+
}
42+
43+
return { retry: true };
4044
}
41-
42-
return { retry: true };
43-
}
44-
});
45+
});
46+
}
4547
}
4648

4749
async init() {
4850
await this.powersync.init();
4951
await this.powersync.connect(this.supabaseConnector);
5052

51-
await this.attachmentQueue.init();
53+
if (this.attachmentQueue) {
54+
await this.attachmentQueue.init();
55+
}
5256
}
5357
}
5458

demos/react-native-supabase-todolist/library/widgets/HeaderWidget.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export const HeaderWidget: React.FC<{
3737
size={20}
3838
style={{ padding: 5 }}
3939
onPress={() => {
40-
system.attachmentQueue.trigger();
40+
if (system.attachmentQueue) {
41+
system.attachmentQueue.trigger();
42+
}
4143
Alert.alert(
4244
'Status',
4345
`${status.connected ? 'Connected' : 'Disconnected'}. \nLast Synced at ${

0 commit comments

Comments
 (0)