1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-23 06:51:12 +02:00

migrate settings save code to firebase 10

This commit is contained in:
Kushagra Gour
2024-05-10 13:30:49 +05:30
parent 61d4e976e4
commit cdc8301072
2 changed files with 18 additions and 12 deletions

View File

@@ -1081,18 +1081,15 @@ export default class App extends Component {
alertsService.add('Setting saved');
});
if (window.user) {
window.db.getDb().then(remoteDb => {
remoteDb
.collection('users')
.doc(window.user.uid)
.update({
[`settings.${settingName}`]: this.state.prefs[settingName]
})
.then(arg => {
log(`Setting "${settingName}" for user`, arg);
})
.catch(error => log(error));
});
db.updateUserSetting(
window.user.uid,
settingName,
this.state.prefs[settingName]
)
.then(arg => {
log(`Setting "${settingName}" saved`, arg);
})
.catch(error => log(error));
}
trackEvent('ui', 'updatePref-' + settingName, prefs[settingName]);
}

View File

@@ -210,6 +210,14 @@ function getArrayFromQuerySnapshot(querySnapshot) {
return getDocs(q).then(getArrayFromQuerySnapshot);
}
async function updateUserSetting(userId, settingName, settingValue) {
const remoteDb = await getDb();
return updateDoc(doc(remoteDb, `users/${userId}`), {
[`settings.${settingName}`]: settingValue
});
}
window.db = {
getDb,
getUser,
@@ -219,6 +227,7 @@ function getArrayFromQuerySnapshot(querySnapshot) {
fetchItem,
getPublicItemCount,
getUserSubscriptionEvents,
updateUserSetting,
local: dbLocalAlias,
sync: dbSyncAlias
};