calendar sync fixes

This commit is contained in:
Kima 2024-03-01 19:00:19 +01:00
parent 010867260c
commit 7ebc470a7b
4 changed files with 20 additions and 7 deletions

View File

@ -136,7 +136,7 @@ Future<Database> initDB(DatabaseProvider database) async {
// v5 shit
"roundings": "{}",
"grade_rarities": "{}",
"linked_accounts": "{}",
"linked_accounts": "[]",
});
} catch (error) {
print("ERROR: migrateDB: $error");

View File

@ -1,4 +1,5 @@
import 'dart:convert';
import 'package:refilc/models/linked_account.dart';
import 'package:refilc/models/self_note.dart';
import 'package:refilc/models/subject_lesson_count.dart';
import 'package:refilc_kreta_api/models/week.dart';
@ -208,4 +209,11 @@ class UserDatabaseStore {
await db.update("user_data", {"grade_rarities": raritiesJson},
where: "id = ?", whereArgs: [userId]);
}
Future<void> storeLinkedAccounts(List<LinkedAccount> accounts,
{required String userId}) async {
String accountsJson = jsonEncode(accounts.map((e) => e.json).toList());
await db.update("user_data", {"linked_accounts": accountsJson},
where: "id = ?", whereArgs: [userId]);
}
}

View File

@ -10,12 +10,14 @@ class LinkedAccount {
String username;
String displayName;
String id;
Map? json;
LinkedAccount({
required this.type,
required this.username,
required this.displayName,
required this.id,
required this.json,
});
factory LinkedAccount.fromJson(Map json) {
@ -30,6 +32,7 @@ class LinkedAccount {
username: json['username'],
displayName: json['display_name'],
id: json['id'],
json: json,
);
}
}

View File

@ -35,6 +35,8 @@ class ThirdPartyProvider with ChangeNotifier {
}) {
_context = context;
_linkedAccounts = initialLinkedAccounts ?? [];
if (_linkedAccounts.isEmpty) restore();
}
Future<void> restore() async {
@ -56,12 +58,12 @@ class ThirdPartyProvider with ChangeNotifier {
if (!await _googleSignIn.isSignedIn()) {
GoogleSignInAccount? account = await _googleSignIn.signIn();
LinkedAccount linked = LinkedAccount(
type: AccountType.google,
username: account?.email ?? '',
displayName: account?.displayName ?? '',
id: account?.id ?? '',
);
LinkedAccount linked = LinkedAccount.fromJson({
'type': 'google',
'username': account?.email ?? '',
'display_name': account?.displayName ?? '',
'id': account?.id ?? ''
});
_linkedAccounts.add(linked);
return account;