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

Fix suppressed eslint issues #750

Merged
merged 4 commits into from
May 25, 2023
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
4 changes: 1 addition & 3 deletions web/src/app/ConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ class ConnectionManager {
const { connectionId } = subscription;
const added = !this.connections.get(connectionId);
if (added) {
const { baseUrl } = subscription;
const { topic } = subscription;
const { user } = subscription;
const { baseUrl, topic, user } = subscription;
const since = subscription.last;
const connection = new Connection(
connectionId,
Expand Down
19 changes: 10 additions & 9 deletions web/src/app/Poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ class Poller {
async pollAll() {
console.log(`[Poller] Polling all subscriptions`);
const subscriptions = await subscriptionManager.all();
for (const s of subscriptions) {
try {
// TODO(eslint): Switch to Promise.all
// eslint-disable-next-line no-await-in-loop
await this.poll(s);
} catch (e) {
console.log(`[Poller] Error polling ${s.id}`, e);
}
}

await Promise.all(
subscriptions.map(async (s) => {
try {
await this.poll(s);
} catch (e) {
console.log(`[Poller] Error polling ${s.id}`, e);
}
})
);
}

async poll(subscription) {
Expand Down
66 changes: 33 additions & 33 deletions web/src/app/SubscriptionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ class SubscriptionManager {
/** All subscriptions, including "new count"; this is a JOIN, see https://dexie.org/docs/API-Reference#joining */
async all() {
const subscriptions = await db.subscriptions.toArray();
await Promise.all(
subscriptions.map(async (s) => {
// eslint-disable-next-line no-param-reassign
s.new = await db.notifications.where({ subscriptionId: s.id, new: 1 }).count();
})
return Promise.all(
subscriptions.map(async (s) => ({
...s,
new: await db.notifications.where({ subscriptionId: s.id, new: 1 }).count(),
}))
);
return subscriptions;
}

async get(subscriptionId) {
Expand Down Expand Up @@ -40,33 +39,31 @@ class SubscriptionManager {
console.log(`[SubscriptionManager] Syncing subscriptions from remote`, remoteSubscriptions);

// Add remote subscriptions
const remoteIds = []; // = topicUrl(baseUrl, topic)
for (let i = 0; i < remoteSubscriptions.length; i += 1) {
const remote = remoteSubscriptions[i];
// TODO(eslint): Switch to Promise.all
// eslint-disable-next-line no-await-in-loop
const local = await this.add(remote.base_url, remote.topic, false);
const reservation = remoteReservations?.find((r) => remote.base_url === config.base_url && remote.topic === r.topic) || null;
// TODO(eslint): Switch to Promise.all
// eslint-disable-next-line no-await-in-loop
await this.update(local.id, {
displayName: remote.display_name, // May be undefined
reservation, // May be null!
});
remoteIds.push(local.id);
}
const remoteIds = await Promise.all(
remoteSubscriptions.map(async (remote) => {
const local = await this.add(remote.base_url, remote.topic, false);
const reservation = remoteReservations?.find((r) => remote.base_url === config.base_url && remote.topic === r.topic) || null;

await this.update(local.id, {
displayName: remote.display_name, // May be undefined
reservation, // May be null!
});

return local.id;
})
);

// Remove local subscriptions that do not exist remotely
const localSubscriptions = await db.subscriptions.toArray();
for (let i = 0; i < localSubscriptions.length; i += 1) {
const local = localSubscriptions[i];
const remoteExists = remoteIds.includes(local.id);
if (!local.internal && !remoteExists) {
// TODO(eslint): Switch to Promise.all
// eslint-disable-next-line no-await-in-loop
await this.remove(local.id);
}
}

await Promise.all(
localSubscriptions.map(async (local) => {
const remoteExists = remoteIds.includes(local.id);
if (!local.internal && !remoteExists) {
await this.remove(local.id);
}
})
);
}

async updateState(subscriptionId, state) {
Expand Down Expand Up @@ -108,9 +105,12 @@ class SubscriptionManager {
return false;
}
try {
// eslint-disable-next-line no-param-reassign
notification.new = 1; // New marker (used for bubble indicator); cannot be boolean; Dexie index limitation
await db.notifications.add({ ...notification, subscriptionId }); // FIXME consider put() for double tab
await db.notifications.add({
...notification,
subscriptionId,
// New marker (used for bubble indicator); cannot be boolean; Dexie index limitation
new: 1,
}); // FIXME consider put() for double tab
await db.subscriptions.update(subscriptionId, {
last: notification.id,
});
Expand Down
21 changes: 9 additions & 12 deletions web/src/app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ export const maybeWithBearerAuth = (headers, token) => {
export const withBasicAuth = (headers, username, password) => ({ ...headers, Authorization: basicAuth(username, password) });

export const maybeWithAuth = (headers, user) => {
if (user && user.password) {
if (user?.password) {
return withBasicAuth(headers, user.username, user.password);
}
if (user && user.token) {
if (user?.token) {
return withBearerAuth(headers, user.token);
}
return headers;
Expand All @@ -139,17 +139,14 @@ export const maybeAppendActionErrors = (message, notification) => {
};

export const shuffle = (arr) => {
let j;
let x;
for (let index = arr.length - 1; index > 0; index -= 1) {
j = Math.floor(Math.random() * (index + 1));
x = arr[index];
// eslint-disable-next-line no-param-reassign
arr[index] = arr[j];
// eslint-disable-next-line no-param-reassign
arr[j] = x;
const returnArr = [...arr];

for (let index = returnArr.length - 1; index > 0; index -= 1) {
const j = Math.floor(Math.random() * (index + 1));
[returnArr[index], returnArr[j]] = [returnArr[j], returnArr[index]];
}
return arr;

return returnArr;
};

export const splitNoEmpty = (s, delimiter) =>
Expand Down
12 changes: 1 addition & 11 deletions web/src/components/EmojiPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,7 @@ const Category = (props) => {
);
};

const emojiMatches = (emoji, words) => {
if (words.length === 0) {
return true;
}
for (const word of words) {
if (emoji.searchBase.indexOf(word) === -1) {
return false;
}
}
return true;
};
const emojiMatches = (emoji, words) => words.length === 0 || words.some((word) => emoji.searchBase.includes(word));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't care enough to revert this, but this is freaking awful :-) It's 100% less readable than the version before. And readability is king.


const Emoji = (props) => {
const { emoji } = props;
Expand Down
11 changes: 3 additions & 8 deletions web/src/components/Notifications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,10 @@ const ACTION_LABEL_SUFFIX = {
};

const updateActionStatus = (notification, action, progress, error) => {
// TODO(eslint): Fix by spreading? Does the code depend on the change, though?
// eslint-disable-next-line no-param-reassign
notification.actions = notification.actions.map((a) => {
if (a.id !== action.id) {
return a;
}
return { ...a, progress, error };
subscriptionManager.updateNotification({
...notification,
actions: notification.actions.map((a) => (a.id === action.id ? { ...a, progress, error } : a)),
});
subscriptionManager.updateNotification(notification);
};

const performHttpAction = async (notification, action) => {
Expand Down