Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

refactor(frontend): use Boolean() and descriptive callback names

spacesdriveb1a294553902
diff --git a/frontend/src/docs/useTableOfContents.js b/frontend/src/docs/useTableOfContents.js
index 6383c53..7617800 100644
--- a/frontend/src/docs/useTableOfContents.js
+++ b/frontend/src/docs/useTableOfContents.js
@@ -16,7 +16,7 @@ export function useTableOfContents(articleRef, pathname) {
// pages are lazy-loaded, so headings can appear after the first render
const mutations = new MutationObserver(() => { headings = collect(); observeAll(); });
const spy = new IntersectionObserver(entries => {
- const visible = entries.filter(e => e.isIntersecting).sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top);
+ const visible = entries.filter(entry => entry.isIntersecting).sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top);
if (visible[0]) setActive(visible[0].target.id);
}, { rootMargin: '-120px 0px -65% 0px' });
function observeAll() { spy.disconnect(); headings.forEach(heading => spy.observe(heading)); }
diff --git a/frontend/src/features/accounts/AccountManager.jsx b/frontend/src/features/accounts/AccountManager.jsx
index 415f3c8..db37cfb 100644
--- a/frontend/src/features/accounts/AccountManager.jsx
+++ b/frontend/src/features/accounts/AccountManager.jsx
@@ -65,7 +65,7 @@ export default function AccountManager() {
<AddAccountDialog flow={addFlow} />
<ConfirmDialog
- open={!!pendingDelete}
+ open={Boolean(pendingDelete)}
onOpenChange={open => { if (!open) setPendingDelete(null); }}
title={pendingDelete ? `Remove ${accountName(pendingDelete)}?` : 'Remove account?'}
description="Its cached analytics are deleted. Scheduled posts for this account are removed with it. You can add the account again later."
diff --git a/frontend/src/features/analytics/reddit/RedditPostFilters.jsx b/frontend/src/features/analytics/reddit/RedditPostFilters.jsx
index 012def9..7884f7c 100644
--- a/frontend/src/features/analytics/reddit/RedditPostFilters.jsx
+++ b/frontend/src/features/analytics/reddit/RedditPostFilters.jsx
@@ -25,14 +25,14 @@ export default function RedditPostFilters({ query, onQuery, sort, onSort, subred
label="Account"
value={accountId}
onChange={onAccount}
- items={[{ value: 'all', label: 'All accounts' }, ...accounts.map(a => ({ value: a.id, label: `u/${a.username}` }))]}
+ items={[{ value: 'all', label: 'All accounts' }, ...accounts.map(account => ({ value: account.id, label: `u/${account.username}` }))]}
/>
)}
<FilterSelect
label="Subreddit"
value={subreddit}
onChange={onSubreddit}
- items={[{ value: 'all', label: 'All subreddits' }, ...subreddits.map(s => ({ value: s, label: `r/${s}` }))]}
+ items={[{ value: 'all', label: 'All subreddits' }, ...subreddits.map(subredditName => ({ value: subredditName, label: `r/${subredditName}` }))]}
/>
<FilterSelect label="Sort" value={sort} onChange={onSort} items={REDDIT_SORT_OPTIONS} className="w-full sm:w-44" />
</div>
diff --git a/frontend/src/features/analytics/shorts/ShortsFilters.jsx b/frontend/src/features/analytics/shorts/ShortsFilters.jsx
index 5bc3141..1c38841 100644
--- a/frontend/src/features/analytics/shorts/ShortsFilters.jsx
+++ b/frontend/src/features/analytics/shorts/ShortsFilters.jsx
@@ -15,13 +15,13 @@ export default function ShortsFilters({
<Select
value={channelFilter}
onValueChange={onChannelChange}
- items={[{ value: 'all', label: 'All channels' }, ...channels.map(c => ({ value: c.id, label: c.title }))]}
+ items={[{ value: 'all', label: 'All channels' }, ...channels.map(channel => ({ value: channel.id, label: channel.title }))]}
>
<SelectTrigger className="w-48" aria-label="Channel"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="all">All channels</SelectItem>
- {channels.map(c => <SelectItem key={c.id} value={c.id}>{c.title}</SelectItem>)}
+ {channels.map(channel => <SelectItem key={channel.id} value={channel.id}>{channel.title}</SelectItem>)}
</SelectGroup>
</SelectContent>
</Select>
@@ -30,7 +30,7 @@ export default function ShortsFilters({
<SelectTrigger className="w-44" aria-label="Sort"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectGroup>
- {sortOptions.map(o => <SelectItem key={o.value} value={o.value}>{o.label}</SelectItem>)}
+ {sortOptions.map(option => <SelectItem key={option.value} value={option.value}>{option.label}</SelectItem>)}
</SelectGroup>
</SelectContent>
</Select>
diff --git a/frontend/src/features/analytics/tracked/EditTrackedDialog.jsx b/frontend/src/features/analytics/tracked/EditTrackedDialog.jsx
index 440a866..2a7a377 100644
--- a/frontend/src/features/analytics/tracked/EditTrackedDialog.jsx
+++ b/frontend/src/features/analytics/tracked/EditTrackedDialog.jsx
@@ -11,7 +11,7 @@ export default function EditTrackedDialog({ editor, categories }) {
const { editItem, fields, setField, saving } = editor;
const showRedditFields = editItem && isRedditItem(editItem);
return (
- <Dialog open={!!editItem} onOpenChange={open => !open && editor.setEditItem(null)}>
+ <Dialog open={Boolean(editItem)} onOpenChange={open => !open && editor.setEditItem(null)}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Edit tracked item</DialogTitle>
diff --git a/frontend/src/features/analytics/tracked/TrackedContent.jsx b/frontend/src/features/analytics/tracked/TrackedContent.jsx
index d3b4992..2b4fc58 100644
--- a/frontend/src/features/analytics/tracked/TrackedContent.jsx
+++ b/frontend/src/features/analytics/tracked/TrackedContent.jsx
@@ -99,7 +99,7 @@ export default function TrackedContent() {
<EditTrackedDialog editor={editor} categories={filters.categories} />
<ConfirmDialog
- open={!!removal.deleteItem}
+ open={Boolean(removal.deleteItem)}
onOpenChange={open => { if (!open) removal.setDeleteItem(null); }}
title="Stop tracking this content?"
description={deleteDescription(removal.deleteItem)}
diff --git a/frontend/src/features/analytics/tracked/useTrackedEditor.js b/frontend/src/features/analytics/tracked/useTrackedEditor.js
index 3cdcc63..ca5e402 100644
--- a/frontend/src/features/analytics/tracked/useTrackedEditor.js
+++ b/frontend/src/features/analytics/tracked/useTrackedEditor.js
@@ -15,7 +15,7 @@ function useTrackedImage({ cloudConfig, showToast }) {
const handleImageSelect = async e => {
const file = e.target.files?.[0];
if (!file) return;
- const error = imageFileError(file, !!cloudConfig);
+ const error = imageFileError(file, Boolean(cloudConfig));
if (error) { showToast(error, 'error'); return; }
setUploading(true);
try {
diff --git a/frontend/src/features/publishing/ScheduledPostDialogs.jsx b/frontend/src/features/publishing/ScheduledPostDialogs.jsx
index 0a139b5..4b6565d 100644
--- a/frontend/src/features/publishing/ScheduledPostDialogs.jsx
+++ b/frontend/src/features/publishing/ScheduledPostDialogs.jsx
@@ -17,7 +17,7 @@ export default function ScheduledPostDialogs({ removal }) {
/>
<ConfirmDialog
- open={!!pendingDelete}
+ open={Boolean(pendingDelete)}
onOpenChange={open => { if (!open) removal.setPendingDelete(null); }}
title={isPublished ? 'Remove this record?' : 'Delete this scheduled post?'}
description={isPublished
diff --git a/frontend/src/features/publishing/useBulkPublish.js b/frontend/src/features/publishing/useBulkPublish.js
index 9f86ffe..571afdd 100644
--- a/frontend/src/features/publishing/useBulkPublish.js
+++ b/frontend/src/features/publishing/useBulkPublish.js
@@ -69,7 +69,7 @@ export function useBulkPublish({ queue, settings, cloudConfig, showToast, onSche
// the queue and settings are read once, as they are at the moment of the click
const handleBulkProcess = async () => {
- const error = bulkStartError({ settings, fileCount: queue.files.length, hasCloudConfig: !!cloudConfig, now: new Date() });
+ const error = bulkStartError({ settings, fileCount: queue.files.length, hasCloudConfig: Boolean(cloudConfig), now: new Date() });
if (error) {
showToast(error, 'error');
return;
diff --git a/frontend/src/features/publishing/useSinglePostForm.js b/frontend/src/features/publishing/useSinglePostForm.js
index 5aaed22..c17cc10 100644
--- a/frontend/src/features/publishing/useSinglePostForm.js
+++ b/frontend/src/features/publishing/useSinglePostForm.js
@@ -37,7 +37,7 @@ export function useSinglePostForm() {
};
const scheduleIncomplete = fields.scheduleMode && (!fields.scheduleDate || !fields.scheduleTime);
- const canPublish = !!media.file && !!contentType && !!selectedAccount && !scheduleIncomplete;
+ const canPublish = Boolean(media.file) && Boolean(contentType) && Boolean(selectedAccount) && !scheduleIncomplete;
return {
...media, selectedAccount, setSelectedAccount, contentType, changeContentType,
diff --git a/frontend/src/features/publishing/useSinglePublish.js b/frontend/src/features/publishing/useSinglePublish.js
index 13c7b7d..7585c2d 100644
--- a/frontend/src/features/publishing/useSinglePublish.js
+++ b/frontend/src/features/publishing/useSinglePublish.js
@@ -55,7 +55,7 @@ export function useSinglePublish({ form, cloudConfig, showToast, onScheduled })
// reads the form as it is at the moment of the click
const handlePublish = async () => {
- const error = singlePostError({ ...form, hasCloudConfig: !!cloudConfig, now: new Date() });
+ const error = singlePostError({ ...form, hasCloudConfig: Boolean(cloudConfig), now: new Date() });
if (error) {
showToast(error, 'error');
return;
diff --git a/frontend/src/features/settings/SchedulingSetupSteps.jsx b/frontend/src/features/settings/SchedulingSetupSteps.jsx
index a543c7d..e26784d 100644
--- a/frontend/src/features/settings/SchedulingSetupSteps.jsx
+++ b/frontend/src/features/settings/SchedulingSetupSteps.jsx
@@ -16,7 +16,7 @@ export default function SchedulingSetupSteps({ done, toggle, base }) {
number={1}
icon={GitFork}
title="Make your own copy of Twiligent on GitHub"
- done={!!done.fork}
+ done={Boolean(done.fork)}
onToggle={toggle('fork')}
check="you see the twiligent repository under your own GitHub username."
>
@@ -28,7 +28,7 @@ export default function SchedulingSetupSteps({ done, toggle, base }) {
number={2}
icon={KeyRound}
title="Copy two values from Supabase"
- done={!!done.supabase}
+ done={Boolean(done.supabase)}
onToggle={toggle('supabase')}
check="you have the project URL and the secret key ready to paste."
>
@@ -45,7 +45,7 @@ export default function SchedulingSetupSteps({ done, toggle, base }) {
number={3}
icon={Lock}
title="Save the two values as secrets in your copy"
- done={!!done.secrets}
+ done={Boolean(done.secrets)}
onToggle={toggle('secrets')}
check="both names appear in the Repository secrets list."
>
@@ -61,7 +61,7 @@ export default function SchedulingSetupSteps({ done, toggle, base }) {
number={4}
icon={Power}
title="Switch on the publisher"
- done={!!done.enable}
+ done={Boolean(done.enable)}
onToggle={toggle('enable')}
check="Instagram Scheduled Publisher is listed on the left with no disabled warning."
>
@@ -73,7 +73,7 @@ export default function SchedulingSetupSteps({ done, toggle, base }) {
number={5}
icon={PlayCircle}
title="Run it once to test"
- done={!!done.test}
+ done={Boolean(done.test)}
onToggle={toggle('test')}
check="the run shows a green tick after about a minute. The log saying “No posts due for publishing” is fine."
>
diff --git a/frontend/src/lib/library.js b/frontend/src/lib/library.js
index d0cb6f6..29c1170 100644
--- a/frontend/src/lib/library.js
+++ b/frontend/src/lib/library.js
@@ -54,5 +54,5 @@ export function pageSlice(items, page, perPage) {
export function matchesText(values, query) {
const needle = query.trim().toLowerCase();
if (!needle) return true;
- return values.some(v => typeof v === 'string' && v.toLowerCase().includes(needle));
+ return values.some(value => typeof value === 'string' && value.toLowerCase().includes(needle));
}