Skip to content

Commit

Permalink
Replace console.error calls with logger.error
Browse files Browse the repository at this point in the history
  • Loading branch information
patosullivan committed Jan 9, 2025
1 parent bfc7c7b commit 7c90d15
Showing 1 changed file with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createDevLogger } from '@tloncorp/shared';
import * as db from '@tloncorp/shared/db';
import { omit } from 'lodash';
import { useCallback, useEffect, useMemo, useState } from 'react';
Expand All @@ -13,6 +14,8 @@ import { ScreenHeader } from '../ScreenHeader';
import { CreateChannelSheet } from './CreateChannelSheet';
import { EditSectionNameSheet } from './EditSectionNameSheet';

const logger = createDevLogger('ManageChannelsScreenView', false);

export type Section = {
id: string;
title: string;
Expand Down Expand Up @@ -62,7 +65,7 @@ function ChannelItem({
const handleMoveUp = useCallback(() => {
if (isFirst) {
if (isFirstSection) {
console.error(
logger.error(
`Channel "${channel.title}" is already at the top of the first section`
);
return;
Expand All @@ -85,7 +88,7 @@ function ChannelItem({
const handleMoveDown = useCallback(() => {
if (isLast) {
if (isLastSection) {
console.error(
logger.error(
`Channel "${channel.title}" is already at the bottom of the last section`
);
return;
Expand Down Expand Up @@ -343,7 +346,7 @@ export function ManageChannelsScreenView({
);

if (!navSection) {
console.error(`Section not found: ${sectionId} (for update operation)`);
logger.error(`Section not found: ${sectionId} (for update operation)`);
return;
}

Expand All @@ -363,7 +366,7 @@ export function ManageChannelsScreenView({
} catch (e) {
// Restore original state on error
setSections(originalSections);
console.error('Failed to update section:', e);
logger.error('Failed to update section:', e);
}
},
[groupNavSectionsWithChannels, updateNavSection, sections]
Expand All @@ -376,7 +379,7 @@ export function ManageChannelsScreenView({
);

if (!navSection) {
console.error(`Section not found: ${sectionId} (for deletion)`);
logger.error(`Section not found: ${sectionId} (for deletion)`);
return;
}

Expand All @@ -393,7 +396,7 @@ export function ManageChannelsScreenView({
} catch (e) {
// Restore original state on error
setSections(originalSections);
console.error('Failed to delete section:', e);
logger.error('Failed to delete section:', e);
}
},
[deleteNavSection, groupNavSectionsWithChannels, sections]
Expand All @@ -403,7 +406,7 @@ export function ManageChannelsScreenView({
async (sectionId: string) => {
const index = sections.findIndex((s) => s.id === sectionId);
if (index === 0) {
console.error(
logger.error(
`Section "${sections[index].title}" is already at the top`
);
return;
Expand All @@ -425,7 +428,7 @@ export function ManageChannelsScreenView({
} catch (e) {
// Restore original state on error
setSections(originalSections);
console.error('Failed to move section up:', e);
logger.error('Failed to move section up:', e);
}
},
[sections, moveNavSection]
Expand All @@ -435,7 +438,7 @@ export function ManageChannelsScreenView({
async (sectionId: string) => {
const index = sections.findIndex((s) => s.id === sectionId);
if (index === sections.length - 1) {
console.error(
logger.error(
`Section "${sections[index].title}" is already at the bottom`
);
return;
Expand All @@ -457,7 +460,7 @@ export function ManageChannelsScreenView({
} catch (e) {
// Restore original state on error
setSections(originalSections);
console.error('Failed to move section down:', e);
logger.error('Failed to move section down:', e);
}
},
[sections, moveNavSection]
Expand All @@ -467,23 +470,23 @@ export function ManageChannelsScreenView({
async (channelId: string, sectionId: string, newIndex: number) => {
const sectionIndex = sections.findIndex((s) => s.id === sectionId);
if (sectionIndex === -1) {
console.error('Invalid section ID:', sectionId);
logger.error('Invalid section ID:', sectionId);
return;
}

const channelIndex = sections[sectionIndex].channels.findIndex(
(c) => c.id === channelId
);
if (channelIndex === -1) {
console.error(
logger.error(
`Channel not found: ${channelId} (expected in section ${sectionId})`
);
return;
}

// Validate newIndex is within bounds
if (newIndex < 0 || newIndex >= sections[sectionIndex].channels.length) {
console.error(
logger.error(
'Invalid new index:',
newIndex,
'for section with',
Expand Down Expand Up @@ -514,7 +517,7 @@ export function ManageChannelsScreenView({
} catch (e) {
// Restore original state on error
setSections(originalSections);
console.error('Failed to move channel within section:', e);
logger.error('Failed to move channel within section:', e);
}
},
[sections, moveChannelWithinNavSection]
Expand All @@ -531,13 +534,13 @@ export function ManageChannelsScreenView({
);

if (previousSectionIndex === -1) {
console.error('Invalid previous section ID:', previousSectionId);
logger.error('Invalid previous section ID:', previousSectionId);
return;
}

// Prevent moving to the same section
if (newSectionId === previousSectionId) {
console.error(
logger.error(
`Cannot move channel to section "${sections[previousSectionIndex].title}" as it is already there`
);
return;
Expand All @@ -548,15 +551,15 @@ export function ManageChannelsScreenView({
);

if (!channel) {
console.error(
logger.error(
`Channel not found: ${channelId} (expected in section ${previousSectionId})`
);
return;
}

const sectionIndex = sections.findIndex((s) => s.id === newSectionId);
if (sectionIndex === -1) {
console.error('Invalid new section ID:', newSectionId);
logger.error('Invalid new section ID:', newSectionId);
return;
}

Expand Down Expand Up @@ -599,7 +602,7 @@ export function ManageChannelsScreenView({
} catch (e) {
// Restore original state on error
setSections(originalSections);
console.error('Failed to move channel to new section:', e);
logger.error('Failed to move channel to new section:', e);
}
},
[sections, moveChannelToNavSection]
Expand Down Expand Up @@ -706,7 +709,7 @@ export function ManageChannelsScreenView({
title,
});
} catch (e) {
console.error('Failed to create section:', e);
logger.error('Failed to create section:', e);
// Note: We don't need state rollback here since the section
// hasn't been added to local state yet - the UI will update
// via the useEffect when groupNavSectionsWithChannels changes
Expand Down

0 comments on commit 7c90d15

Please sign in to comment.