-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Extract preferences related server handlers from main.ts to server/preferences/app.ts #4420
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Bundle Stats — desktop-clientHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger
Smaller No assets were smaller Unchanged
|
Bundle Stats — loot-coreHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger
Smaller No assets were smaller Unchanged No assets were unchanged |
Warning Rate limit exceeded@joel-jeremy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 56 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe pull request introduces significant changes to the Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/loot-core/src/server/preferences/app.ts (3)
49-49
:getSyncedPrefs
function
Returns a map of preference IDs to values from the database. Consider minimal error-handling for missing or invalid table entries.Also applies to: 59-59
94-134
: Simplify boolean assignment at line 115
Instead of using the ternary operator, you can use a direct boolean expression, e.g.:- floatingSidebar: floatingSidebar === 'true' ? true : false, + floatingSidebar: floatingSidebar === 'true',This reduces complexity without altering behavior.
🧰 Tools
🪛 Biome (1.9.4)
[error] 115-115: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with(lint/complexity/noUselessTernary)
136-157
:saveMetadataPrefs
function
Consider verifying ifuserToken
is null and returning an error to match patterns used in other server calls. Currently, it’s used at line 141 without a guarantee of its presence.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
upcoming-release-notes/4420.md
is excluded by!**/*.md
📒 Files selected for processing (5)
packages/loot-core/src/server/main.ts
(2 hunks)packages/loot-core/src/server/preferences/app.ts
(2 hunks)packages/loot-core/src/server/preferences/types/handlers.d.ts
(0 hunks)packages/loot-core/src/types/handlers.d.ts
(1 hunks)packages/loot-core/src/types/server-handlers.d.ts
(0 hunks)
💤 Files with no reviewable changes (2)
- packages/loot-core/src/server/preferences/types/handlers.d.ts
- packages/loot-core/src/types/server-handlers.d.ts
✅ Files skipped from review due to trivial changes (1)
- packages/loot-core/src/types/handlers.d.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/loot-core/src/server/preferences/app.ts
[error] 115-115: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with
(lint/complexity/noUselessTernary)
🔇 Additional comments (12)
packages/loot-core/src/server/preferences/app.ts (10)
1-3
: Great job on the new imports
They are used appropriately, and the modules are properly referenced within the file.
5-7
: Imports for preference types look correct
GlobalPrefs
,MetadataPrefs
, andSyncedPrefs
are clearly used in their respective handlers.
11-11
: Import usage forgetDefaultDocumentDir
This import is used later to provide a fallback for document directories. The usage appears consistent and correct.
13-13
:post
import for server calls
The use ofpost
aligns with other asynchronous server calls in the codebase. No issues found.
14-18
: New metadata-pref imports
These are essential for retrieving and saving metadata preferences. The approach is consistent.
21-28
:PreferencesHandlers
interface
Defining this interface with new methods for both global and metadata preferences helps centralize preferences management.
32-37
: Registering preference handlers
Linking methods such assaveSyncedPrefs
andgetSyncedPrefs
underpreferences/
is clear and organized.
39-39
:saveSyncedPrefs
function
Straightforward implementation that updates thepreferences
table. Glad to see it wrapped in anasync
context for proper DB operations.Also applies to: 45-45, 47-47
61-92
:saveGlobalPrefs
logic
Each known preference field is set inasyncStorage
when present. The conditional checks are appropriate, and returning'ok'
is consistent with other APIs.
159-162
:loadMetadataPrefs
function
This succinctly returns the metadata from_getMetadataPrefs
with no extra overhead. Looks good.packages/loot-core/src/server/main.ts (2)
19-19
: Switched import toamountToInteger
No issues; this appears to be used for transaction or account-related logic.
2298-2298
: ExportinggetDefaultDocumentDir
Making this function exportable helps external modules retrieve default directory logic directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor cleanup tweak actually
7e5dfc8
to
66924d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🔭 Outside diff range comments (1)
packages/loot-core/src/server/preferences/app.ts (1)
49-59
: 🛠️ Refactor suggestionAdd error handling for database operations.
The function should handle potential database errors to prevent uncaught exceptions from propagating.
async function getSyncedPrefs(): Promise<SyncedPrefs> { + try { const prefs = (await db.all('SELECT id, value FROM preferences')) as Array<{ id: string; value: string; }>; return prefs.reduce<SyncedPrefs>((carry, { value, id }) => { carry[id as keyof SyncedPrefs] = value; return carry; }, {}); + } catch (error) { + console.error('Failed to get synced preferences:', error); + throw new Error(`Failed to retrieve preferences: ${error.message}`); + } }
🧹 Nitpick comments (1)
packages/loot-core/src/server/preferences/app.ts (1)
115-115
: Simplify boolean expression.The ternary operator for boolean conversion can be simplified.
- floatingSidebar: floatingSidebar === 'true' ? true : false, + floatingSidebar: floatingSidebar === 'true',🧰 Tools
🪛 Biome (1.9.4)
[error] 115-115: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with(lint/complexity/noUselessTernary)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
upcoming-release-notes/4420.md
is excluded by!**/*.md
📒 Files selected for processing (5)
packages/loot-core/src/server/main.ts
(1 hunks)packages/loot-core/src/server/preferences/app.ts
(2 hunks)packages/loot-core/src/server/preferences/types/handlers.d.ts
(0 hunks)packages/loot-core/src/types/handlers.d.ts
(1 hunks)packages/loot-core/src/types/server-handlers.d.ts
(0 hunks)
💤 Files with no reviewable changes (2)
- packages/loot-core/src/server/preferences/types/handlers.d.ts
- packages/loot-core/src/types/server-handlers.d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/loot-core/src/types/handlers.d.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/loot-core/src/server/preferences/app.ts
[error] 115-115: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with
(lint/complexity/noUselessTernary)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: Visual regression
- GitHub Check: Functional
- GitHub Check: build (macos-latest)
- GitHub Check: build (windows-latest)
- GitHub Check: build (ubuntu-latest)
- GitHub Check: Analyze
🔇 Additional comments (1)
packages/loot-core/src/server/main.ts (1)
1511-1520
: LGTM!The function is well-documented and properly handles platform-specific paths while maintaining backward compatibility.
async function saveSyncedPrefs({ | ||
id, | ||
value, | ||
}: { | ||
id: keyof SyncedPrefs; | ||
value: string | undefined; | ||
}) => { | ||
}) { | ||
await db.update('preferences', { id, value }); | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for database operations.
The function should handle potential database errors to prevent uncaught exceptions from propagating.
async function saveSyncedPrefs({
id,
value,
}: {
id: keyof SyncedPrefs;
value: string | undefined;
}) {
+ try {
await db.update('preferences', { id, value });
+ } catch (error) {
+ console.error('Failed to save synced preferences:', error);
+ throw new Error(`Failed to save preference ${id}: ${error.message}`);
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async function saveSyncedPrefs({ | |
id, | |
value, | |
}: { | |
id: keyof SyncedPrefs; | |
value: string | undefined; | |
}) => { | |
}) { | |
await db.update('preferences', { id, value }); | |
}; | |
} | |
async function saveSyncedPrefs({ | |
id, | |
value, | |
}: { | |
id: keyof SyncedPrefs; | |
value: string | undefined; | |
}) { | |
try { | |
await db.update('preferences', { id, value }); | |
} catch (error) { | |
console.error('Failed to save synced preferences:', error); | |
throw new Error(`Failed to save preference ${id}: ${error.message}`); | |
} | |
} |
async function saveMetadataPrefs(prefsToSet: MetadataPrefs) { | ||
const { cloudFileId } = _getMetadataPrefs(); | ||
|
||
// Need to sync the budget name on the server as well | ||
if (prefsToSet.budgetName && cloudFileId) { | ||
const userToken = await asyncStorage.getItem('user-token'); | ||
|
||
const syncServer = getServer()?.SYNC_SERVER; | ||
if (!syncServer) { | ||
throw new Error('No sync server set'); | ||
} | ||
|
||
await post(syncServer + '/update-user-filename', { | ||
token: userToken, | ||
fileId: cloudFileId, | ||
name: prefsToSet.budgetName, | ||
}); | ||
} | ||
|
||
await _saveMetadataPrefs(prefsToSet); | ||
return 'ok'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for network operations.
The function should handle potential network errors during server communication.
async function saveMetadataPrefs(prefsToSet: MetadataPrefs) {
+ try {
const { cloudFileId } = _getMetadataPrefs();
// Need to sync the budget name on the server as well
if (prefsToSet.budgetName && cloudFileId) {
const userToken = await asyncStorage.getItem('user-token');
const syncServer = getServer()?.SYNC_SERVER;
if (!syncServer) {
throw new Error('No sync server set');
}
await post(syncServer + '/update-user-filename', {
token: userToken,
fileId: cloudFileId,
name: prefsToSet.budgetName,
});
}
await _saveMetadataPrefs(prefsToSet);
return 'ok';
+ } catch (error) {
+ if (error.message === 'No sync server set') {
+ throw error;
+ }
+ console.error('Failed to save metadata preferences:', error);
+ throw new Error(`Failed to save metadata preferences: ${error.message}`);
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async function saveMetadataPrefs(prefsToSet: MetadataPrefs) { | |
const { cloudFileId } = _getMetadataPrefs(); | |
// Need to sync the budget name on the server as well | |
if (prefsToSet.budgetName && cloudFileId) { | |
const userToken = await asyncStorage.getItem('user-token'); | |
const syncServer = getServer()?.SYNC_SERVER; | |
if (!syncServer) { | |
throw new Error('No sync server set'); | |
} | |
await post(syncServer + '/update-user-filename', { | |
token: userToken, | |
fileId: cloudFileId, | |
name: prefsToSet.budgetName, | |
}); | |
} | |
await _saveMetadataPrefs(prefsToSet); | |
return 'ok'; | |
} | |
async function saveMetadataPrefs(prefsToSet: MetadataPrefs) { | |
try { | |
const { cloudFileId } = _getMetadataPrefs(); | |
// Need to sync the budget name on the server as well | |
if (prefsToSet.budgetName && cloudFileId) { | |
const userToken = await asyncStorage.getItem('user-token'); | |
const syncServer = getServer()?.SYNC_SERVER; | |
if (!syncServer) { | |
throw new Error('No sync server set'); | |
} | |
await post(syncServer + '/update-user-filename', { | |
token: userToken, | |
fileId: cloudFileId, | |
name: prefsToSet.budgetName, | |
}); | |
} | |
await _saveMetadataPrefs(prefsToSet); | |
return 'ok'; | |
} catch (error) { | |
if (error.message === 'No sync server set') { | |
throw error; | |
} | |
console.error('Failed to save metadata preferences:', error); | |
throw new Error(`Failed to save metadata preferences: ${error.message}`); | |
} | |
} |
async function saveGlobalPrefs(prefs: GlobalPrefs) { | ||
if ('maxMonths' in prefs) { | ||
await asyncStorage.setItem('max-months', '' + prefs.maxMonths); | ||
} | ||
if ('documentDir' in prefs) { | ||
if (prefs.documentDir && (await fs.exists(prefs.documentDir))) { | ||
await asyncStorage.setItem('document-dir', prefs.documentDir); | ||
} | ||
} | ||
if ('floatingSidebar' in prefs) { | ||
await asyncStorage.setItem('floating-sidebar', '' + prefs.floatingSidebar); | ||
} | ||
if ('language' in prefs) { | ||
await asyncStorage.setItem('language', prefs.language); | ||
} | ||
if ('theme' in prefs) { | ||
await asyncStorage.setItem('theme', prefs.theme); | ||
} | ||
if ('preferredDarkTheme' in prefs) { | ||
await asyncStorage.setItem( | ||
'preferred-dark-theme', | ||
prefs.preferredDarkTheme, | ||
); | ||
} | ||
if ('serverSelfSignedCert' in prefs) { | ||
await asyncStorage.setItem( | ||
'server-self-signed-cert', | ||
prefs.serverSelfSignedCert, | ||
); | ||
} | ||
return 'ok'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for async storage operations.
The function should handle potential storage errors to prevent uncaught exceptions from propagating.
async function saveGlobalPrefs(prefs: GlobalPrefs) {
+ try {
if ('maxMonths' in prefs) {
await asyncStorage.setItem('max-months', '' + prefs.maxMonths);
}
if ('documentDir' in prefs) {
if (prefs.documentDir && (await fs.exists(prefs.documentDir))) {
await asyncStorage.setItem('document-dir', prefs.documentDir);
}
}
if ('floatingSidebar' in prefs) {
await asyncStorage.setItem('floating-sidebar', '' + prefs.floatingSidebar);
}
if ('language' in prefs) {
await asyncStorage.setItem('language', prefs.language);
}
if ('theme' in prefs) {
await asyncStorage.setItem('theme', prefs.theme);
}
if ('preferredDarkTheme' in prefs) {
await asyncStorage.setItem(
'preferred-dark-theme',
prefs.preferredDarkTheme,
);
}
if ('serverSelfSignedCert' in prefs) {
await asyncStorage.setItem(
'server-self-signed-cert',
prefs.serverSelfSignedCert,
);
}
return 'ok';
+ } catch (error) {
+ console.error('Failed to save global preferences:', error);
+ throw new Error(`Failed to save global preferences: ${error.message}`);
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async function saveGlobalPrefs(prefs: GlobalPrefs) { | |
if ('maxMonths' in prefs) { | |
await asyncStorage.setItem('max-months', '' + prefs.maxMonths); | |
} | |
if ('documentDir' in prefs) { | |
if (prefs.documentDir && (await fs.exists(prefs.documentDir))) { | |
await asyncStorage.setItem('document-dir', prefs.documentDir); | |
} | |
} | |
if ('floatingSidebar' in prefs) { | |
await asyncStorage.setItem('floating-sidebar', '' + prefs.floatingSidebar); | |
} | |
if ('language' in prefs) { | |
await asyncStorage.setItem('language', prefs.language); | |
} | |
if ('theme' in prefs) { | |
await asyncStorage.setItem('theme', prefs.theme); | |
} | |
if ('preferredDarkTheme' in prefs) { | |
await asyncStorage.setItem( | |
'preferred-dark-theme', | |
prefs.preferredDarkTheme, | |
); | |
} | |
if ('serverSelfSignedCert' in prefs) { | |
await asyncStorage.setItem( | |
'server-self-signed-cert', | |
prefs.serverSelfSignedCert, | |
); | |
} | |
return 'ok'; | |
} | |
async function saveGlobalPrefs(prefs: GlobalPrefs) { | |
try { | |
if ('maxMonths' in prefs) { | |
await asyncStorage.setItem('max-months', '' + prefs.maxMonths); | |
} | |
if ('documentDir' in prefs) { | |
if (prefs.documentDir && (await fs.exists(prefs.documentDir))) { | |
await asyncStorage.setItem('document-dir', prefs.documentDir); | |
} | |
} | |
if ('floatingSidebar' in prefs) { | |
await asyncStorage.setItem('floating-sidebar', '' + prefs.floatingSidebar); | |
} | |
if ('language' in prefs) { | |
await asyncStorage.setItem('language', prefs.language); | |
} | |
if ('theme' in prefs) { | |
await asyncStorage.setItem('theme', prefs.theme); | |
} | |
if ('preferredDarkTheme' in prefs) { | |
await asyncStorage.setItem( | |
'preferred-dark-theme', | |
prefs.preferredDarkTheme, | |
); | |
} | |
if ('serverSelfSignedCert' in prefs) { | |
await asyncStorage.setItem( | |
'server-self-signed-cert', | |
prefs.serverSelfSignedCert, | |
); | |
} | |
return 'ok'; | |
} catch (error) { | |
console.error('Failed to save global preferences:', error); | |
throw new Error(`Failed to save global preferences: ${error.message}`); | |
} | |
} |
async function loadMetadataPrefs(): Promise<MetadataPrefs> { | ||
return _getMetadataPrefs(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for metadata preferences retrieval.
The function should handle potential errors from _getMetadataPrefs.
async function loadMetadataPrefs(): Promise<MetadataPrefs> {
+ try {
return _getMetadataPrefs();
+ } catch (error) {
+ console.error('Failed to load metadata preferences:', error);
+ throw new Error(`Failed to load metadata preferences: ${error.message}`);
+ }
}
Committable suggestion skipped: line range outside the PR's diff.
async function loadGlobalPrefs() { | ||
const [ | ||
[, floatingSidebar], | ||
[, maxMonths], | ||
[, documentDir], | ||
[, encryptKey], | ||
[, language], | ||
[, theme], | ||
[, preferredDarkTheme], | ||
[, serverSelfSignedCert], | ||
] = await asyncStorage.multiGet([ | ||
'floating-sidebar', | ||
'max-months', | ||
'document-dir', | ||
'encrypt-key', | ||
'language', | ||
'theme', | ||
'preferred-dark-theme', | ||
'server-self-signed-cert', | ||
] as const); | ||
return { | ||
floatingSidebar: floatingSidebar === 'true' ? true : false, | ||
maxMonths: stringToInteger(maxMonths || ''), | ||
documentDir: documentDir || getDefaultDocumentDir(), | ||
keyId: encryptKey && JSON.parse(encryptKey).id, | ||
language, | ||
theme: | ||
theme === 'light' || | ||
theme === 'dark' || | ||
theme === 'auto' || | ||
theme === 'development' || | ||
theme === 'midnight' | ||
? theme | ||
: 'auto', | ||
preferredDarkTheme: | ||
preferredDarkTheme === 'dark' || preferredDarkTheme === 'midnight' | ||
? preferredDarkTheme | ||
: 'dark', | ||
serverSelfSignedCert: serverSelfSignedCert || undefined, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for async storage operations.
The function should handle potential storage errors to prevent uncaught exceptions from propagating.
async function loadGlobalPrefs() {
+ try {
const [
[, floatingSidebar],
[, maxMonths],
[, documentDir],
[, encryptKey],
[, language],
[, theme],
[, preferredDarkTheme],
[, serverSelfSignedCert],
] = await asyncStorage.multiGet([
'floating-sidebar',
'max-months',
'document-dir',
'encrypt-key',
'language',
'theme',
'preferred-dark-theme',
'server-self-signed-cert',
] as const);
return {
floatingSidebar: floatingSidebar === 'true',
maxMonths: stringToInteger(maxMonths || ''),
documentDir: documentDir || getDefaultDocumentDir(),
keyId: encryptKey && JSON.parse(encryptKey).id,
language,
theme:
theme === 'light' ||
theme === 'dark' ||
theme === 'auto' ||
theme === 'development' ||
theme === 'midnight'
? theme
: 'auto',
preferredDarkTheme:
preferredDarkTheme === 'dark' || preferredDarkTheme === 'midnight'
? preferredDarkTheme
: 'dark',
serverSelfSignedCert: serverSelfSignedCert || undefined,
};
+ } catch (error) {
+ console.error('Failed to load global preferences:', error);
+ throw new Error(`Failed to load global preferences: ${error.message}`);
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async function loadGlobalPrefs() { | |
const [ | |
[, floatingSidebar], | |
[, maxMonths], | |
[, documentDir], | |
[, encryptKey], | |
[, language], | |
[, theme], | |
[, preferredDarkTheme], | |
[, serverSelfSignedCert], | |
] = await asyncStorage.multiGet([ | |
'floating-sidebar', | |
'max-months', | |
'document-dir', | |
'encrypt-key', | |
'language', | |
'theme', | |
'preferred-dark-theme', | |
'server-self-signed-cert', | |
] as const); | |
return { | |
floatingSidebar: floatingSidebar === 'true' ? true : false, | |
maxMonths: stringToInteger(maxMonths || ''), | |
documentDir: documentDir || getDefaultDocumentDir(), | |
keyId: encryptKey && JSON.parse(encryptKey).id, | |
language, | |
theme: | |
theme === 'light' || | |
theme === 'dark' || | |
theme === 'auto' || | |
theme === 'development' || | |
theme === 'midnight' | |
? theme | |
: 'auto', | |
preferredDarkTheme: | |
preferredDarkTheme === 'dark' || preferredDarkTheme === 'midnight' | |
? preferredDarkTheme | |
: 'dark', | |
serverSelfSignedCert: serverSelfSignedCert || undefined, | |
}; | |
} | |
async function loadGlobalPrefs() { | |
try { | |
const [ | |
[, floatingSidebar], | |
[, maxMonths], | |
[, documentDir], | |
[, encryptKey], | |
[, language], | |
[, theme], | |
[, preferredDarkTheme], | |
[, serverSelfSignedCert], | |
] = await asyncStorage.multiGet([ | |
'floating-sidebar', | |
'max-months', | |
'document-dir', | |
'encrypt-key', | |
'language', | |
'theme', | |
'preferred-dark-theme', | |
'server-self-signed-cert', | |
] as const); | |
return { | |
floatingSidebar: floatingSidebar === 'true', | |
maxMonths: stringToInteger(maxMonths || ''), | |
documentDir: documentDir || getDefaultDocumentDir(), | |
keyId: encryptKey && JSON.parse(encryptKey).id, | |
language, | |
theme: | |
theme === 'light' || | |
theme === 'dark' || | |
theme === 'auto' || | |
theme === 'development' || | |
theme === 'midnight' | |
? theme | |
: 'auto', | |
preferredDarkTheme: | |
preferredDarkTheme === 'dark' || preferredDarkTheme === 'midnight' | |
? preferredDarkTheme | |
: 'dark', | |
serverSelfSignedCert: serverSelfSignedCert || undefined, | |
}; | |
} catch (error) { | |
console.error('Failed to load global preferences:', error); | |
throw new Error(`Failed to load global preferences: ${error.message}`); | |
} | |
} |
🧰 Tools
🪛 Biome (1.9.4)
[error] 115-115: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with
(lint/complexity/noUselessTernary)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Related to #1113