Skip to content

Commit 8baa65e

Browse files
committed
updated Storage React Native Expo
1 parent 09db331 commit 8baa65e

File tree

10 files changed

+70
-192
lines changed

10 files changed

+70
-192
lines changed

CosyncStorage/ReactNative-Expo/CosyncStorageExpo/config/Config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
//
2525

2626
exports.Realm = {
27-
appId: '',
28-
publicPartition: 'public',
27+
appId: 'qrxtra-yenuj',
2928
cosyncAsset:'CosyncAsset',
3029
cosyncAssetUpload : 'CosyncAssetUpload'
3130
}

CosyncStorage/ReactNative-Expo/CosyncStorageExpo/config/Schema.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ exports.CosyncAsset = {
3030
"properties": {
3131

3232
"_id":{ "type": "objectId", "indexed": true },
33-
"_partition":{ "type": "string", "indexed": true },
34-
"uid":{ "type": "string", "indexed": true },
33+
"userId":{ "type": "string", "indexed": true },
3534
"sessionId":{ "type": "string", "indexed": true},
3635
"path":{ "type": "string", "default": ""},
3736
"expirationHours": { "type": "double", "default": 24},
@@ -61,11 +60,9 @@ exports.CosyncAssetUpload = {
6160
"primaryKey":"_id",
6261
"properties": {
6362
"_id":{ "type": "objectId", "indexed": true },
64-
"_partition":{ "type": "string", "indexed": true },
65-
"uid":{ "type": "string", "indexed": true },
63+
"userId":{ "type": "string", "indexed": true },
6664
"sessionId":{ "type": "string", "indexed": true},
67-
"extra":{ "type": "string", "default": ""},
68-
"assetPartition":{ "type": "string", "indexed": true },
65+
"extra":{ "type": "string", "default": ""},
6966
"filePath": { "type": "string", "default": "" },
7067
"path":{ "type": "string", "default": ""},
7168
"expirationHours": { "type": "double", "default": 24},

CosyncStorage/ReactNative-Expo/CosyncStorageExpo/ios/CosyncStorageExpo.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
1111
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1212
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
13-
31840951A76749A1983303D9 /* noop-file.swift in Sources */ = {isa = PBXBuildFile; fileRef = F233B282078947A5A1BDD928 /* noop-file.swift */; };
1413
3E461D99554A48A4959DE609 /* SplashScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */; };
1514
96905EF65AED1B983A6B3ABC /* libPods-CosyncStorageExpo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 58EEBF8E8E6FB1BC6CAF49B5 /* libPods-CosyncStorageExpo.a */; };
1615
B18059E884C0ABDD17F3DC3D /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC715A2D49A985799AEE119 /* ExpoModulesProvider.swift */; };
1716
BB2F792D24A3F905000567C9 /* Expo.plist in Resources */ = {isa = PBXBuildFile; fileRef = BB2F792C24A3F905000567C9 /* Expo.plist */; };
17+
F02C2A87C29F49D2B1CA74F8 /* noop-file.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2963838B9B743EEACA5F1A6 /* noop-file.swift */; };
1818
/* End PBXBuildFile section */
1919

2020
/* Begin PBXFileReference section */
@@ -28,11 +28,11 @@
2828
58EEBF8E8E6FB1BC6CAF49B5 /* libPods-CosyncStorageExpo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CosyncStorageExpo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
2929
6C2E3173556A471DD304B334 /* Pods-CosyncStorageExpo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CosyncStorageExpo.debug.xcconfig"; path = "Target Support Files/Pods-CosyncStorageExpo/Pods-CosyncStorageExpo.debug.xcconfig"; sourceTree = "<group>"; };
3030
7A4D352CD337FB3A3BF06240 /* Pods-CosyncStorageExpo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CosyncStorageExpo.release.xcconfig"; path = "Target Support Files/Pods-CosyncStorageExpo/Pods-CosyncStorageExpo.release.xcconfig"; sourceTree = "<group>"; };
31-
9965068665524D4D934A8DDC /* CosyncStorageExpo-Bridging-Header.h */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.c.h; name = "CosyncStorageExpo-Bridging-Header.h"; path = "CosyncStorageExpo/CosyncStorageExpo-Bridging-Header.h"; sourceTree = "<group>"; };
31+
95CF0C7E383546E7BE558670 /* CosyncStorageExpo-Bridging-Header.h */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.c.h; name = "CosyncStorageExpo-Bridging-Header.h"; path = "CosyncStorageExpo/CosyncStorageExpo-Bridging-Header.h"; sourceTree = "<group>"; };
3232
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = SplashScreen.storyboard; path = CosyncStorageExpo/SplashScreen.storyboard; sourceTree = "<group>"; };
3333
BB2F792C24A3F905000567C9 /* Expo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Expo.plist; sourceTree = "<group>"; };
34+
D2963838B9B743EEACA5F1A6 /* noop-file.swift */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.swift; name = "noop-file.swift"; path = "CosyncStorageExpo/noop-file.swift"; sourceTree = "<group>"; };
3435
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
35-
F233B282078947A5A1BDD928 /* noop-file.swift */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.swift; name = "noop-file.swift"; path = "CosyncStorageExpo/noop-file.swift"; sourceTree = "<group>"; };
3636
FAC715A2D49A985799AEE119 /* ExpoModulesProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ExpoModulesProvider.swift; path = "Pods/Target Support Files/Pods-CosyncStorageExpo/ExpoModulesProvider.swift"; sourceTree = "<group>"; };
3737
/* End PBXFileReference section */
3838

@@ -59,8 +59,8 @@
5959
13B07FB61A68108700A75B9A /* Info.plist */,
6060
13B07FB71A68108700A75B9A /* main.m */,
6161
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */,
62-
F233B282078947A5A1BDD928 /* noop-file.swift */,
63-
9965068665524D4D934A8DDC /* CosyncStorageExpo-Bridging-Header.h */,
62+
D2963838B9B743EEACA5F1A6 /* noop-file.swift */,
63+
95CF0C7E383546E7BE558670 /* CosyncStorageExpo-Bridging-Header.h */,
6464
);
6565
name = CosyncStorageExpo;
6666
sourceTree = "<group>";
@@ -292,7 +292,7 @@
292292
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
293293
13B07FC11A68108700A75B9A /* main.m in Sources */,
294294
B18059E884C0ABDD17F3DC3D /* ExpoModulesProvider.swift in Sources */,
295-
31840951A76749A1983303D9 /* noop-file.swift in Sources */,
295+
F02C2A87C29F49D2B1CA74F8 /* noop-file.swift in Sources */,
296296
);
297297
runOnlyForDeploymentPostprocessing = 0;
298298
};

CosyncStorage/ReactNative-Expo/CosyncStorageExpo/ios/CosyncStorageExpo/Info.plist

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,6 @@
4646
</dict>
4747
</dict>
4848
</dict>
49-
50-
51-
<key>NSPhotoLibraryUsageDescription</key>
52-
<string>$(PRODUCT_NAME) would like access to your photo gallery</string>
53-
<key>NSLocationWhenInUseUsageDescription</key>
54-
<string></string>
55-
<key>NSMicrophoneUsageDescription</key>
56-
<string></string>
57-
<key>NSPhotoLibraryAddUsageDescription</key>
58-
<string>App needs photo library Access</string>
59-
6049
<key>UILaunchStoryboardName</key>
6150
<string>SplashScreen</string>
6251
<key>UIRequiredDeviceCapabilities</key>

CosyncStorage/ReactNative-Expo/CosyncStorageExpo/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ SPEC CHECKSUMS:
515515
ExpoModulesCore: 32c0ccb47f477d330ee93db72505380adf0de09a
516516
EXSplashScreen: 21669e598804ee810547dbb6692c8deb5dd8dbf3
517517
FBLazyVector: c71c5917ec0ad2de41d5d06a5855f6d5eda06971
518-
FBReactNativeSpec: 3e7467b4488303b7438d01169ef6ea03c970d330
518+
FBReactNativeSpec: c3237e68ddfed4970b1597a6b597d836467f0455
519519
GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4
520520
glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62
521521
RCT-Folly: ec7a233ccc97cc556cf7237f0db1ff65b986f27c

CosyncStorage/ReactNative-Expo/CosyncStorageExpo/managers/RealmManager.js

Lines changed: 41 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export const signup = (userEmail, userPassword) => {
3838
const app = new Realm.App(appConfig);
3939
if(app.currentUser) app.currentUser.logOut();
4040

41-
app.emailPasswordAuth.registerUser(userEmail, userPassword).then(result => {
41+
let userDetail = RegisterUserDetails(userEmail, userPassword);
42+
43+
app.emailPasswordAuth.registerUser(userDetail).then(result => {
4244
resolve(true)
4345
}).catch(err => {
4446
resolve(err)
@@ -62,9 +64,7 @@ export const login = (userEmail, userPassword) => {
6264
closeAllRealm();
6365

6466
app.logIn(credentials).then(user => {
65-
global.user = user;
66-
67-
global.privatePartition = `user_id=${global.user.id}`;
67+
global.user = user;
6868

6969
openRealm().then( result => {
7070
resolve(user);
@@ -80,57 +80,62 @@ export const login = (userEmail, userPassword) => {
8080

8181
const closeAllRealm = () => {
8282

83-
try {
84-
for (const key in global.realmPartition) {
85-
const realm = global.realmPartition[key];
86-
if(realm) realm.close();
87-
}
83+
try {
84+
if(global.realm){
85+
global.realm.subscriptions.update((mutableSubs) => {
86+
mutableSubs.removeAll();
87+
});
88+
89+
global.realm.close();
90+
91+
}
8892
} catch (error) {
8993

9094
}
9195

92-
global.realmPartition = {};
93-
9496
}
9597

9698

9799
export const openRealm = () => {
98100

99101
return new Promise((resolve, reject) => {
100102

101-
if(global.realm && global.realmPrivate){
103+
if(global.realm){
102104
resolve(global)
103105
return;
104106
}
105107

106-
let configPublic = {
107-
schema: [Schema.CosyncAsset, Schema.CosyncAssetUpload],
108-
sync: {
109-
user: global.user,
110-
partitionValue: Configure.Realm.publicPartition
111-
}
112-
};
113-
114-
let configPrivate = {
115-
schema: [Schema.CosyncAsset, Schema.CosyncAssetUpload],
116-
sync: {
117-
user: global.user,
118-
partitionValue: global.privatePartition,
119-
}
120-
};
108+
121109

122110
try {
123111

124-
Realm.open(configPublic).then(realm => {
125-
global.realm = realm;
126-
127-
Realm.open(configPrivate).then(priRealm => {
128-
global.realmPrivate = priRealm;
129-
resolve({realm: realm, realmPrivate: priRealm});
130-
131-
})
112+
Realm.open({
113+
schema: [Schema.CosyncAsset, Schema.CosyncAssetUpload],
114+
sync: {
115+
user: global.user,
116+
flexible: true,
117+
},
118+
}).then(realm => {
119+
global.realm = realm;
120+
121+
realm.subscriptions.update((mutableSubs) => {
122+
123+
mutableSubs.add(realm.objects(Configure.Realm.cosyncAssetUpload).filtered(`userId == '${global.user.id}'`), {
124+
name: "cosyncAssetUploadSubscription",
125+
throwOnUpdate: true,
126+
});
127+
128+
mutableSubs.add(realm.objects(Configure.Realm.cosyncAsset), {
129+
name: "cosyncAssetSubscription",
130+
throwOnUpdate: true,
131+
});
132+
});
133+
134+
resolve(realm);
132135

133136
}).catch(err => {
137+
console.log(err)
138+
134139
reject(err);
135140
})
136141

@@ -141,47 +146,7 @@ export const openRealm = () => {
141146
})
142147
}
143148

144-
145-
146-
export const openRealmPartition = (partitionValue, reopen) => {
147-
148-
return new Promise((resolve, reject) => {
149-
150-
if(global.realmPartition[partitionValue]){
151-
if(!reopen){
152-
resolve(global.realmPartition[partitionValue]);
153-
return;
154-
}
155-
156-
}
157-
158-
let configPartition = {
159-
schema: [Schema.CosyncAsset, Schema.CosyncAssetUpload],
160-
sync: {
161-
user: global.user,
162-
partitionValue: partitionValue
163-
}
164-
};
165-
166-
try {
167-
168-
if(global.realmPartition[partitionValue]) global.realmPartition[partitionValue].close();
169-
170-
Realm.open(configPartition).then(realm => {
171-
global.realmPartition[partitionValue] = realm;
172-
resolve(realm);
173-
}).catch(err => {
174-
console.error(err)
175-
reject(err);
176-
})
177-
178-
} catch (error) {
179-
console.error(err)
180-
reject(error);
181-
}
182-
183-
})
184-
}
149+
185150

186151

187152

CosyncStorage/ReactNative-Expo/CosyncStorageExpo/screens/Asset.js

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ const Asset = props => {
7070
return [];
7171
});
7272

73-
const assetsPublic = await global.realm.objects(Configure.Realm.cosyncAsset).filtered(`uid = '${global.user.id}'`);
74-
console.log('loadAllAssets .... assetsPublic ', assetsPublic.length);
73+
const assetsPublic = await global.realm.objects(Configure.Realm.cosyncAsset);
74+
console.log('loadAllAssets .... assets ', assetsPublic.length);
7575

7676
let sortedAssetsPublic = assetsPublic.sorted("createdAt", false);
7777

@@ -91,24 +91,6 @@ const Asset = props => {
9191
}
9292
});
9393

94-
const assetsPrivate = global.realmPrivate.objects(Configure.Realm.cosyncAsset);
95-
console.log('loadAllAssets .... assetsPrivate ', assetsPrivate.length);
96-
97-
let sortedResult = assetsPrivate.sorted("createdAt", false);
98-
assetsPrivate.removeListener(changeAssetEvent);
99-
assetsPrivate.addListener(changeAssetEvent);
100-
101-
sortedResult.forEach(element => {
102-
if(element.status == "active"){
103-
let item = element;
104-
item.id = element._id.toString();
105-
106-
setAssetList(prevItems => {
107-
return [item, ...prevItems];
108-
});
109-
}
110-
});
111-
11294
setLoading(false);
11395

11496

@@ -135,68 +117,7 @@ const Asset = props => {
135117
});
136118
}
137119
}
138-
139-
function assetsEventListener(assets, changes) {
140-
// Update UI in response to inserted objects
141-
changes.insertions.forEach((index) => {
142-
let item = assets[index];
143-
144-
console.log("insertions ", item.status);
145-
146-
if(item.status == 'active'){
147-
item.id = item._id.toString();
148-
setAssetList(prevItems => {
149-
return [item, ...prevItems];
150-
});
151-
}
152-
});
153-
154-
changes.modifications.forEach((index) => {
155-
156-
let item = assets[index];
157-
console.log("modifications ", item.status);
158-
console.log("modifications: id ", item._id)
159-
console.log("modifications: assetList ", assetList.length)
160-
161-
if(item.status != 'active'){
162-
let itemId = item._id.toString();
163-
setAssetList(existingItems => {
164-
165-
console.log("existingItems ", existingItems.length);
166-
167-
return existingItems.filter((asset) => {
168-
169-
170-
console.log("existingItems asset ", asset._id);
171-
172-
173-
asset._id !== itemId
174-
});
175-
});
176-
177-
178-
}
179-
else if(item.status == 'active'){
180-
item.id = item._id.toString();
181-
setAssetList(prevItems => {
182-
return [item, ...prevItems];
183-
});
184-
}
185-
186-
});
187-
188-
changes.deletions.forEach((index) => {
189-
190-
191-
setAssetList(existingItems => {
192-
console.log("existingItems ", existingItems.length);
193-
194-
return existingItems.filter((item, i) => i !== index);
195-
})
196-
197-
});
198-
199-
}
120+
200121

201122
return (
202123
<SafeAreaView style={styles.container}>

CosyncStorage/ReactNative-Expo/CosyncStorageExpo/screens/Login.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ const Login = ({ navigation }) => {
5151
const ref_input_pwd = useRef();
5252
const authCtx = useContext(AuthContext);
5353

54+
useEffect(() => {
55+
setUserEmail("[email protected]");
56+
setUserPassword("qwerty");
57+
58+
console.log("useEffect ", userEmail);
59+
60+
}, []);
61+
62+
5463
const validateEmail = (text) => {
5564

5665
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

0 commit comments

Comments
 (0)