Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various mostly client cleanups #1512

Merged
merged 8 commits into from
Dec 29, 2024
Merged
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
10 changes: 5 additions & 5 deletions client/js/helpers/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import React from 'react';
export function i18nFormat(translated, params) {
let formatted = '';

let curChar = undefined;
let curChar;
let buffer = '';

let state = 'out';
let placeholder = undefined;
let plural = undefined;
let pluralKeyword = undefined;
let pluralValue = undefined;
let placeholder;
let plural;
let pluralKeyword;
let pluralValue;

for (let i = 0, len = translated.length; i < len; i++) {
curChar = translated.charAt(i);
Expand Down
36 changes: 19 additions & 17 deletions client/js/selfoss-db-offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { OfflineStorageNotAvailableError } from './errors';
import Dexie from 'dexie';
import { FilterType } from './Filter';

const ENTRY_STATUS_NAMES = ['unread', 'starred'];

selfoss.dbOffline = {
/** @var Date the datetime of the newest garbage collected entry, i.e. deleted because not of interest. */
newestGCedEntry: null,
Expand Down Expand Up @@ -58,8 +60,7 @@ selfoss.dbOffline = {
return selfoss.dbOffline
._tr(
'r',
selfoss.db.storage.entries,
selfoss.db.storage.stamps,
[selfoss.db.storage.entries, selfoss.db.storage.stamps],
() => {
selfoss.dbOffline._memLastItemId();
selfoss.db.storage.stamps.get(
Expand Down Expand Up @@ -161,8 +162,7 @@ selfoss.dbOffline = {
storeEntries(entries) {
return selfoss.dbOffline._tr(
'rw',
selfoss.db.storage.entries,
selfoss.db.storage.stamps,
[selfoss.db.storage.entries, selfoss.db.storage.stamps],
() => {
selfoss.dbOffline.GCEntries();

Expand Down Expand Up @@ -253,7 +253,7 @@ selfoss.dbOffline = {
},

storeStats(stats) {
return selfoss.dbOffline._tr('rw', selfoss.db.storage.stats, () => {
return selfoss.dbOffline._tr('rw', [selfoss.db.storage.stats], () => {
for (const [name, value] of Object.entries(stats)) {
selfoss.db.storage.stats.put({
name,
Expand All @@ -264,7 +264,7 @@ selfoss.dbOffline = {
},

storeLastUpdate(lastUpdate) {
return selfoss.dbOffline._tr('rw', selfoss.db.storage.stamps, () => {
return selfoss.dbOffline._tr('rw', [selfoss.db.storage.stamps], () => {
if (lastUpdate) {
selfoss.db.storage.stamps.put({
name: 'lastItemsUpdate',
Expand All @@ -277,7 +277,7 @@ selfoss.dbOffline = {
getEntries(fetchParams) {
let hasMore = false;
return selfoss.dbOffline
._tr('r', selfoss.db.storage.entries, () => {
._tr('r', [selfoss.db.storage.entries], () => {
let howMany = 0;

const ascOrder =
Expand Down Expand Up @@ -361,7 +361,7 @@ selfoss.dbOffline = {
},

reloadOnlineStats() {
return selfoss.dbOffline._tr('r', selfoss.db.storage.stats, () => {
return selfoss.dbOffline._tr('r', [selfoss.db.storage.stats], () => {
selfoss.db.storage.stats.toArray((stats) => {
const newStats = {};
stats.forEach((stat) => {
Expand All @@ -377,7 +377,7 @@ selfoss.dbOffline = {
},

refreshStats() {
return selfoss.dbOffline._tr('r', selfoss.db.storage.entries, () => {
return selfoss.dbOffline._tr('r', [selfoss.db.storage.entries], () => {
const offlineCounts = { newest: 0, unread: 0, starred: 0 };

// IDBKeyRange does not support boolean indexes, so we need to
Expand Down Expand Up @@ -411,15 +411,15 @@ selfoss.dbOffline = {
datetime: d,
}));

return selfoss.dbOffline._tr('rw', selfoss.db.storage.statusq, () => {
return selfoss.dbOffline._tr('rw', [selfoss.db.storage.statusq], () => {
selfoss.db.storage.statusq.bulkAdd(newQueuedStatuses);
});
},

enqueueStatus(entryId, statusName, statusValue) {
return selfoss.dbOffline.enqueueStatuses([
{
entryId: entryId,
entryId,
name: statusName,
value: statusValue,
},
Expand Down Expand Up @@ -454,17 +454,19 @@ selfoss.dbOffline = {
return selfoss.dbOffline
._tr(
'rw',
selfoss.db.storage.entries,
selfoss.db.storage.stats,
selfoss.db.storage.statusq,
[
selfoss.db.storage.entries,
selfoss.db.storage.stats,
selfoss.db.storage.statusq,
],
() => {
const statsDiff = {};

// update entries statuses
itemStatuses.forEach((itemStatus) => {
const newStatus = {};

selfoss.db.entryStatusNames.forEach((statusName) => {
ENTRY_STATUS_NAMES.forEach((statusName) => {
if (statusName in itemStatus) {
statsDiff[statusName] = 0;
newStatus[statusName] = itemStatus[statusName];
Expand Down Expand Up @@ -521,7 +523,7 @@ selfoss.dbOffline = {
entriesMark(itemIds, unread) {
selfoss.dbOnline.statsDirty = true;
const newStatuses = itemIds.map((itemId) => {
return { id: itemId, unread: unread };
return { id: itemId, unread };
});
return selfoss.dbOffline.storeEntryStatuses(newStatuses);
},
Expand All @@ -534,7 +536,7 @@ selfoss.dbOffline = {
return selfoss.dbOffline.storeEntryStatuses([
{
id: itemId,
starred: starred,
starred,
},
]);
},
Expand Down
1 change: 0 additions & 1 deletion client/js/selfoss-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ selfoss.db = {
enableOffline: new ValueListenable(
window.localStorage.getItem('enableOffline') === 'true',
),
entryStatusNames: ['unread', 'starred'],
userWaiting: true,

/**
Expand Down
2 changes: 1 addition & 1 deletion client/js/templates/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ EntriesFilter.propTypes = {
unreadItemsCount: PropTypes.number.isRequired,
};

export default class App extends React.Component {
export class App extends React.Component {
constructor(props) {
super(props);
this.state = {
Expand Down
16 changes: 6 additions & 10 deletions client/js/templates/EntriesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export function EntriesPage({
}

return (
<React.Fragment>
<>
{currentSource !== null && allowedToUpdate && isOnline ? (
<button
type="button"
Expand Down Expand Up @@ -514,7 +514,7 @@ export function EntriesPage({
</button>
) : null}
</div>
</React.Fragment>
</>
);
}

Expand Down Expand Up @@ -725,14 +725,10 @@ class StateHolder extends React.Component {
refreshEntryStatuses(entryStatuses) {
this.state.entries.forEach((entry) => {
const { id } = entry;
let newStatus = false;
entryStatuses.some((entryStatus) => {
if (entryStatus.id == id) {
newStatus = entryStatus;
}
return newStatus;
});
if (newStatus) {
const newStatus = entryStatuses.find(
(entryStatus) => entryStatus.id == id,
);
if (newStatus !== null) {
this.starEntryInView(id, newStatus.starred);
this.markEntryInView(id, newStatus.unread);
}
Expand Down
4 changes: 2 additions & 2 deletions client/js/templates/HashPassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function HashPassword({ setTitle }) {
return;
}
setError(error);
setState(LoadingState.ERROR);
setState(LoadingState.FAILURE);
});
},
[navigate, passwordEntry.value],
Expand All @@ -58,7 +58,7 @@ export default function HashPassword({ setTitle }) {
<input type="text" value={hashedPassword} readOnly />
</label>
</p>
) : state === LoadingState.ERROR ? (
) : state === LoadingState.FAILURE ? (
<p className="error">
Unexpected happened.
<details>
Expand Down
8 changes: 4 additions & 4 deletions client/js/templates/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,10 @@ export default function Item({

{/* author */}
{author !== null ? (
<React.Fragment>
<>
<span className="entry-author">{author}</span>
<span className="entry-separator">•</span>
</React.Fragment>
</>
) : null}

{/* datetime */}
Expand All @@ -557,7 +557,7 @@ export default function Item({

{/* read time */}
{configuration.readingSpeed !== null ? (
<React.Fragment>
<>
<span className="entry-separator">•</span>
<span className="entry-readtime">
{_('article_reading_time', [
Expand All @@ -566,7 +566,7 @@ export default function Item({
),
])}
</span>
</React.Fragment>
</>
) : null}

{/* thumbnail */}
Expand Down
6 changes: 3 additions & 3 deletions client/js/templates/LoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ export default function LoginForm({ offlineEnabled }) {
const _ = useContext(LocalizationContext);

return (
<React.Fragment>
<>
{loading ? <SpinnerBig label={_('login_in_progress')} /> : null}
<form
action=""
className={classNames({ loading: loading })}
className={classNames({ loading })}
method="post"
onSubmit={formOnSubmit}
>
Expand Down Expand Up @@ -165,7 +165,7 @@ export default function LoginForm({ offlineEnabled }) {
</li>
</ul>
</form>
</React.Fragment>
</>
);
}

Expand Down
4 changes: 2 additions & 2 deletions client/js/templates/NavSources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default function NavSources({
const _ = useContext(LocalizationContext);

return (
<React.Fragment>
<>
<h2>
<button
type="button"
Expand Down Expand Up @@ -170,7 +170,7 @@ export default function NavSources({
))}
</ul>
</Collapse>
</React.Fragment>
</>
);
}

Expand Down
8 changes: 4 additions & 4 deletions client/js/templates/NavTags.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ function Tag({ tag, active, collapseNav }) {
{tag === null ? (
_('alltags')
) : (
<React.Fragment>
<>
<span className="tag">{unescape(tag.tag)}</span>
<span className="unread">
{tag.unread > 0 ? tag.unread : ''}
</span>
<ColorChooser tag={tag} onChange={colorChanged} />
</React.Fragment>
</>
)}
</Link>
</li>
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function NavTags({ setNavExpanded, tags }) {
const _ = useContext(LocalizationContext);

return (
<React.Fragment>
<>
<h2>
<button
type="button"
Expand Down Expand Up @@ -145,7 +145,7 @@ export default function NavTags({ setNavExpanded, tags }) {
))}
</ul>
</Collapse>
</React.Fragment>
</>
);
}

Expand Down
4 changes: 2 additions & 2 deletions client/js/templates/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function Navigation({
const canWrite = useAllowedToWrite();

return (
<React.Fragment>
<>
<div id="nav-logo"></div>
{canWrite && (
<button
Expand Down Expand Up @@ -113,7 +113,7 @@ export default function Navigation({
/>

<NavToolBar reloadAll={reloadAll} setNavExpanded={setNavExpanded} />
</React.Fragment>
</>
);
}

Expand Down
6 changes: 3 additions & 3 deletions client/js/templates/OpmlImport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function OpmlImport({ setTitle }) {
</p>,
);
} else if (response.status === 202) {
setState(LoadingState.ERROR);
setState(LoadingState.FAILURE);
setMessage(
<p className="msg error">
The following feeds could not be imported:
Expand All @@ -51,7 +51,7 @@ export default function OpmlImport({ setTitle }) {
</p>,
);
} else if (response.status === 400) {
setState(LoadingState.ERROR);
setState(LoadingState.FAILURE);
setMessage(
<p className="msg error">
There was a problem importing your OPML file:
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function OpmlImport({ setTitle }) {
});
return;
} else {
setState(LoadingState.ERROR);
setState(LoadingState.FAILURE);
setMessage(
<div className="msg error">
Unexpected error occurred.
Expand Down
Loading