Skip to content

Commit 2212cbb

Browse files
committed
feat: added index delete support
1 parent 3d0aa4d commit 2212cbb

File tree

6 files changed

+69
-4
lines changed

6 files changed

+69
-4
lines changed

expo-example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ allprojects {
3939
maven { url 'https://www.jitpack.io' }
4040
}
4141
}
42-
apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"
42+
apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { useState } from 'react';
2+
import { Collection } from 'cbl-reactnative';
3+
import CBLCollectionActionContainer from '@/components/CBLCollectionActionContainer';
4+
import HeaderView from '@/components/HeaderView';
5+
import { Divider } from '@gluestack-ui/themed';
6+
import { StyledTextInput } from '@/components/StyledTextInput';
7+
import deleteIndex from '@/service/indexes/delete';
8+
9+
export default function IndexCreateScreen() {
10+
const [indexName, setIndexName] = useState<string>('');
11+
12+
function reset() {
13+
setIndexName('');
14+
}
15+
16+
async function update(collection: Collection): Promise<string[]> {
17+
try {
18+
await deleteIndex(collection, indexName);
19+
return [`Index ${indexName} was deleted successfully`];
20+
} catch (error) {
21+
// @ts-ignore
22+
return [error.message];
23+
}
24+
}
25+
26+
return (
27+
<CBLCollectionActionContainer
28+
handleUpdatePressed={update}
29+
handleResetPressed={reset}
30+
screenTitle="Delete Index"
31+
>
32+
<HeaderView name="Index" iconName="magnify" />
33+
<StyledTextInput
34+
autoCapitalize="none"
35+
placeholder="IndexName"
36+
onChangeText={(newText) => setIndexName(newText)}
37+
defaultValue={indexName}
38+
/>
39+
</CBLCollectionActionContainer>
40+
);
41+
}

expo-example/ios/expoexample/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
6363
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
6464
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
65+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
66+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
6567
</array>
6668
<key>UILaunchStoryboardName</key>
6769
<string>SplashScreen</string>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Collection } from 'cbl-reactnative';
2+
3+
export default async function deleteIndex(
4+
collection: Collection,
5+
indexName: string
6+
): Promise<void> {
7+
await collection.deleteIndex(indexName);
8+
}

ios/CblReactnative.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ class CblReactnative: NSObject {
169169
}
170170
}
171171

172-
@objc(collection_DeleteCollection:fromCollectionWithName:fromScopeWithName:fromDatabaseWithName:withResolver:withRejecter:)
173-
func collection_DeleteCollection(
172+
@objc(collection_DeleteIndex:fromCollectionWithName:fromScopeWithName:fromDatabaseWithName:withResolver:withRejecter:)
173+
func collection_DeleteIndex(
174174
indexName: NSString,
175175
collectionName: NSString,
176176
scopeName: NSString,

src/CblReactNativeEngine.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,21 @@ export class CblReactNativeEngine implements ICoreEngine {
169169
}
170170

171171
collection_DeleteIndex(args: CollectionDeleteIndexArgs): Promise<void> {
172-
return Promise.resolve(undefined);
172+
return new Promise((resolve, reject) => {
173+
this.CblReactNative.collection_DeleteIndex(
174+
args.indexName,
175+
args.collectionName,
176+
args.scopeName,
177+
args.name
178+
).then(
179+
() => {
180+
resolve();
181+
},
182+
(error: any) => {
183+
reject(error);
184+
}
185+
);
186+
});
173187
}
174188

175189
collection_GetBlobContent(

0 commit comments

Comments
 (0)