Skip to content

Commit

Permalink
client: Even more type checking improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Dec 29, 2024
1 parent 6850afa commit 2e92a2e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions client/js/requests/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function enrichItemsResponse(data: RawItemsResponse): ItemsResponse {

type QueryFilter = {
fromDatetime?: Date;
itemsPerPage?: number;
};

/**
Expand Down
4 changes: 3 additions & 1 deletion client/js/selfoss-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ class selfoss {
): void {
const awaitStateChange = (): void => {
reg.installing.addEventListener('statechange', (event) => {
if (event.target.state === 'installed') {
// https://github.com/microsoft/TypeScript/issues/40153
const sw = event.target as ServiceWorker;
if (sw.state === 'installed') {
callback(reg);
}
});
Expand Down
48 changes: 30 additions & 18 deletions client/js/selfoss-db-offline.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import selfoss from './selfoss-base';
import { OfflineStorageNotAvailableError } from './errors';
import Dexie from 'dexie';
import Dexie, {
PromiseExtended,
Table,
Transaction,
TransactionMode,
} from 'dexie';
import { OfflineDb } from './model/OfflineDb';
import { FilterType } from './Filter';
import dexie from 'dexie';

const ENTRY_STATUS_NAMES = ['unread', 'starred'];
const ENTRY_STATUS_NAMES: Array<'unread' | 'starred'> = ['unread', 'starred'];

export default class DbOffline {
/** @var Date the datetime of the newest garbage collected entry, i.e. deleted because not of interest. */
Expand All @@ -17,23 +23,29 @@ export default class DbOffline {
public olderEntriesOnline: boolean = false;
public needsSync: boolean;

_tr(...args) {
return selfoss.db.storage.transaction(...args).catch((error) => {
selfoss.app.showError(
selfoss.app._('error_offline_storage', [error.message]),
);
selfoss.db.broken = true;
selfoss.db.enableOffline.update(false);
selfoss.entries?.reload();

// If this is a QuotaExceededError, garbage collect more
// entries and hope it helps.
if (error.name === Dexie.errnames.QuotaExceeded) {
this.GCEntries(true);
}
_tr<U>(
mode: TransactionMode,
tables: Table[],
scope: (trans: Transaction) => PromiseLike<U> | U,
): PromiseExtended<U> {
return selfoss.db.storage
.transaction(mode, tables, scope)
.catch((error) => {
selfoss.app.showError(
selfoss.app._('error_offline_storage', [error.message]),
);
selfoss.db.broken = true;
selfoss.db.enableOffline.update(false);
selfoss.entries?.reload();

return Promise.reject(error);
});
// If this is a QuotaExceededError, garbage collect more
// entries and hope it helps.
if (error.name === Dexie.errnames.QuotaExceeded) {
this.GCEntries(true);
}

return Promise.reject(error);
});
}

init() {
Expand Down
2 changes: 1 addition & 1 deletion client/js/templates/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function PureApp(props: PureAppProps): React.JSX.Element {
}

type AppProps = {
configuration: object;
configuration: Configuration;
};

type AppState = {
Expand Down

0 comments on commit 2e92a2e

Please sign in to comment.