Automatically add newly added books to Kobo shelf (#1826)
This commit is contained in:
+20
@@ -44,6 +44,26 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (koboSyncSettings.syncEnabled) {
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">Auto-Add New Books to Kobo Shelf</label>
|
||||
<p-toggle-switch
|
||||
id="autoAddToShelf"
|
||||
name="autoAddToShelf"
|
||||
[(ngModel)]="koboSyncSettings.autoAddToShelf"
|
||||
(ngModelChange)="onAutoAddToggle()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
When enabled, newly added books will be automatically added to your Kobo shelf for syncing.
|
||||
This eliminates the need to manually add each book to the shelf.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (koboSyncSettings.syncEnabled) {
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
|
||||
+30
-31
@@ -37,6 +37,7 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly sliderChange$ = new Subject<void>();
|
||||
private readonly progressThresholdChange$ = new Subject<void>();
|
||||
|
||||
hasKoboTokenPermission = false;
|
||||
isAdmin = false;
|
||||
@@ -55,7 +56,8 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
token: '',
|
||||
syncEnabled: false,
|
||||
progressMarkAsReadingThreshold: 1,
|
||||
progressMarkAsFinishedThreshold: 99
|
||||
progressMarkAsFinishedThreshold: 99,
|
||||
autoAddToShelf: true
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -70,6 +72,13 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
).subscribe(() => {
|
||||
this.saveSettings();
|
||||
});
|
||||
|
||||
this.progressThresholdChange$.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(() => {
|
||||
this.updateKoboSettings('Progress thresholds updated successfully');
|
||||
});
|
||||
}
|
||||
|
||||
private setupUserStateSubscription() {
|
||||
@@ -108,6 +117,7 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
this.koboSyncSettings.syncEnabled = settings.syncEnabled;
|
||||
this.koboSyncSettings.progressMarkAsReadingThreshold = settings.progressMarkAsReadingThreshold ?? 1;
|
||||
this.koboSyncSettings.progressMarkAsFinishedThreshold = settings.progressMarkAsFinishedThreshold ?? 99;
|
||||
this.koboSyncSettings.autoAddToShelf = settings.autoAddToShelf ?? false;
|
||||
this.credentialsSaved = !!settings.token;
|
||||
},
|
||||
error: () => {
|
||||
@@ -191,55 +201,44 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
message: 'Disabling Kobo sync will delete your Kobo shelf. Are you sure you want to proceed?',
|
||||
header: 'Confirm Disable',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => this.performToggle(false),
|
||||
accept: () => this.updateKoboSettings('Kobo sync disabled'),
|
||||
reject: () => {
|
||||
this.koboSyncSettings.syncEnabled = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.performToggle(true);
|
||||
this.updateKoboSettings('Kobo sync enabled');
|
||||
}
|
||||
}
|
||||
|
||||
private performToggle(enabled: boolean) {
|
||||
this.koboService.toggleSync(enabled).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Sync Updated',
|
||||
detail: enabled
|
||||
? 'Kobo sync enabled'
|
||||
: 'Kobo sync disabled'
|
||||
});
|
||||
this.shelfService.reloadShelves();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to update sync setting'
|
||||
});
|
||||
}
|
||||
});
|
||||
onProgressThresholdsChange() {
|
||||
this.progressThresholdChange$.next();
|
||||
}
|
||||
|
||||
onProgressThresholdsChange() {
|
||||
this.koboService.updateProgressThresholds(
|
||||
this.koboSyncSettings.progressMarkAsReadingThreshold,
|
||||
this.koboSyncSettings.progressMarkAsFinishedThreshold
|
||||
).subscribe({
|
||||
onAutoAddToggle() {
|
||||
const message = this.koboSyncSettings.autoAddToShelf
|
||||
? 'New books will be automatically added to Kobo shelf'
|
||||
: 'Auto-add to Kobo shelf disabled';
|
||||
this.updateKoboSettings(message);
|
||||
}
|
||||
|
||||
private updateKoboSettings(successMessage: string) {
|
||||
this.koboService.updateSettings(this.koboSyncSettings).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Thresholds Updated',
|
||||
detail: 'Progress thresholds updated successfully'
|
||||
summary: 'Settings Updated',
|
||||
detail: successMessage
|
||||
});
|
||||
if (!this.koboSyncSettings.syncEnabled) {
|
||||
this.shelfService.reloadShelves();
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to update progress thresholds'
|
||||
detail: 'Failed to update Kobo settings'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
+4
-15
@@ -8,6 +8,7 @@ export interface KoboSyncSettings {
|
||||
syncEnabled: boolean;
|
||||
progressMarkAsReadingThreshold?: number;
|
||||
progressMarkAsFinishedThreshold?: number;
|
||||
autoAddToShelf: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
@@ -22,22 +23,10 @@ export class KoboService {
|
||||
}
|
||||
|
||||
createOrUpdateToken(): Observable<KoboSyncSettings> {
|
||||
return this.http.put<KoboSyncSettings>(`${this.baseUrl}`, null);
|
||||
return this.http.put<KoboSyncSettings>(`${this.baseUrl}/token`, null);
|
||||
}
|
||||
|
||||
toggleSync(enabled: boolean): Observable<void> {
|
||||
const params = new HttpParams().set('enabled', enabled.toString());
|
||||
return this.http.put<void>(`${this.baseUrl}/sync`, null, { params });
|
||||
}
|
||||
|
||||
updateProgressThresholds(readingThreshold?: number, finishedThreshold?: number): Observable<KoboSyncSettings> {
|
||||
let params = new HttpParams();
|
||||
if (readingThreshold !== undefined && readingThreshold !== null) {
|
||||
params = params.set('readingThreshold', readingThreshold.toString());
|
||||
}
|
||||
if (finishedThreshold !== undefined && finishedThreshold !== null) {
|
||||
params = params.set('finishedThreshold', finishedThreshold.toString());
|
||||
}
|
||||
return this.http.put<KoboSyncSettings>(`${this.baseUrl}/progress-thresholds`, null, { params });
|
||||
updateSettings(settings: KoboSyncSettings): Observable<KoboSyncSettings> {
|
||||
return this.http.put<KoboSyncSettings>(`${this.baseUrl}`, settings);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user