Bidirectional progress sync between koreader and booklore reader (#2312)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+18
@@ -45,6 +45,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">Sync reading progress with Booklore eBook Reader</label>
|
||||
<p-toggle-switch
|
||||
name="syncWithBookloreReader"
|
||||
[(ngModel)]="syncWithBookloreReader"
|
||||
(ngModelChange)="onToggleSyncWithBookloreReader($event)"
|
||||
inputId="syncWithBookloreReader"
|
||||
[disabled]="!credentialsSaved || !koReaderSyncEnabled">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
Enable bidirectional sync between Booklore's eBook reader and KOReader. <strong>Note:</strong> Progress sync is approximate and may update by chapter rather than exact page or location.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
|
||||
+22
@@ -31,6 +31,7 @@ export class KoreaderSettingsComponent implements OnInit, OnDestroy {
|
||||
editMode = true;
|
||||
showPassword = false;
|
||||
koReaderSyncEnabled = false;
|
||||
syncWithBookloreReader = false;
|
||||
koReaderUsername = '';
|
||||
koReaderPassword = '';
|
||||
credentialsSaved = false;
|
||||
@@ -64,6 +65,7 @@ export class KoreaderSettingsComponent implements OnInit, OnDestroy {
|
||||
this.koReaderUsername = koreaderUser.username;
|
||||
this.koReaderPassword = koreaderUser.password;
|
||||
this.koReaderSyncEnabled = koreaderUser.syncEnabled;
|
||||
this.syncWithBookloreReader = koreaderUser.syncWithBookloreReader ?? false;
|
||||
this.credentialsSaved = true;
|
||||
},
|
||||
error: err => {
|
||||
@@ -104,6 +106,26 @@ export class KoreaderSettingsComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
onToggleSyncWithBookloreReader(enabled: boolean) {
|
||||
this.koreaderService.toggleSyncProgressWithBookloreReader(enabled).subscribe({
|
||||
next: () => {
|
||||
this.syncWithBookloreReader = enabled;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Sync Updated',
|
||||
detail: `Booklore eBook Reader sync has been ${enabled ? 'enabled' : 'disabled'}.`
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: 'Unable to update Booklore eBook Reader sync setting. Please try again.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleShowPassword() {
|
||||
this.showPassword = !this.showPassword;
|
||||
}
|
||||
|
||||
+5
-3
@@ -12,7 +12,8 @@ describe('KoreaderService', () => {
|
||||
const mockUser: KoreaderUser = {
|
||||
username: 'testuser',
|
||||
password: 'secret',
|
||||
syncEnabled: true
|
||||
syncEnabled: true,
|
||||
syncWithBookloreReader: false
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -118,11 +119,12 @@ describe('KoreaderService - API Contract Tests', () => {
|
||||
});
|
||||
|
||||
it('should validate all required KoreaderUser fields exist', () => {
|
||||
const requiredFields: (keyof KoreaderUser)[] = ['username', 'password', 'syncEnabled'];
|
||||
const requiredFields: (keyof KoreaderUser)[] = ['username', 'password', 'syncEnabled', 'syncWithBookloreReader'];
|
||||
const mockResponse: KoreaderUser = {
|
||||
username: 'test',
|
||||
password: 'pw',
|
||||
syncEnabled: true
|
||||
syncEnabled: true,
|
||||
syncWithBookloreReader: false
|
||||
};
|
||||
httpClientMock.get.mockReturnValue(of(mockResponse));
|
||||
service.getUser().subscribe(user => {
|
||||
|
||||
+7
@@ -8,6 +8,7 @@ export interface KoreaderUser {
|
||||
username: string;
|
||||
password: string;
|
||||
syncEnabled: boolean;
|
||||
syncWithBookloreReader: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
@@ -33,4 +34,10 @@ export class KoreaderService {
|
||||
params: {enabled: enabled.toString()}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSyncProgressWithBookloreReader(enabled: boolean): Observable<void> {
|
||||
return this.http.patch<void>(`${this.url}/me/sync-progress-with-booklore`, null, {
|
||||
params: {enabled: enabled.toString()}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user