Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { logger } from './src/utils/logger';
import { syncAllData } from './src/services/sync';
import React, { useEffect, useState } from 'react';
import { View, ActivityIndicator, Text, StyleSheet } from 'react-native';
import { initializeDatabase } from './src/db/index';
import AppNavigator from './src/navigation/AppNavigator';
import { NavigationContainer } from '@react-navigation/native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { syncAllData } from './src/services/sync';
import { View, ActivityIndicator, Text, StyleSheet } from 'react-native';
import { FLUENT_USER_EMAIL } from '@env';

const log = logger.create('App');
Expand Down
2 changes: 1 addition & 1 deletion src/db/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function getChapterAssignmentById(
bibleId: row.bible_id,
bookId: row.book_id,
chapterNumber: row.chapter_number,
assignedUserId: row.assigned_user_id ?? undefined,
assignedUserId: row.assigned_user_id,
status: row.status,
submittedTime: row.submitted_time ?? undefined,
updatedAt: row.updated_at,
Expand Down
27 changes: 27 additions & 0 deletions src/services/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Storage } from '@op-engineering/op-sqlite';
import { logger } from '../utils/logger';

const log = logger.create('KVStorage');

export const kvStorage = new Storage({
location: 'kv',
});

export const KV_KEYS = {
USER_ID: 'userId',
USER_EMAIL: 'userEmail',
} as const;

export function getUserIdSync(): string {
return kvStorage.getItemSync(KV_KEYS.USER_ID) ?? '';
}

export function getUserEmailSync(): string {
return kvStorage.getItemSync(KV_KEYS.USER_EMAIL) ?? '';
}

export function setUserSync(userId: string, userEmail: string) {
kvStorage.setItemSync(KV_KEYS.USER_ID, userId);
kvStorage.setItemSync(KV_KEYS.USER_EMAIL, userEmail);
log.info('User stored in KV', { userId, userEmail });
}
3 changes: 2 additions & 1 deletion src/services/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '../db/repository';
import { logger } from '../utils/logger';
import { ApiBook, ApiVerse } from '../types/api/types';
import { setUserSync } from '../services/storage';

const log = logger.create('SyncService');

Expand All @@ -27,8 +28,8 @@ export async function syncUser(email: string) {

await insertUser(user);

setUserSync(String(user.id), user.email);
log.info('User synced', { email: user.email });

return user;
} catch (error) {
log.error('User sync failed', { error });
Expand Down
6 changes: 3 additions & 3 deletions src/types/db/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface ChapterAssignmentData {
bibleId: number;
bookId: number;
chapterNumber: number;
assignedUserId?: number | null;
assignedUserId?: number;
status: string;
submittedTime?: string | null;
updatedAt?: string;
Expand All @@ -72,7 +72,7 @@ export interface ChapterAssignmentRow {
bible_id: number;
book_id: number;
chapter_number: number;
assigned_user_id?: number | null;
assigned_user_id?: number;
status: string;
submitted_time?: string | null;
updated_at?: string;
Expand All @@ -86,7 +86,7 @@ export interface ChapterListItem {
chapter_number: number;
status: string;
book_name: string;
assigned_user_id?: number | null;
assigned_user_id?: number;
}

export interface ChapterRow {
Expand Down
Loading