Skip to content

Commit a3945b0

Browse files
authored
chore: use log instead of console log (#188)
1 parent fdb9b37 commit a3945b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+201
-147
lines changed

src/application/awareness/dispatch.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Editor } from 'slate';
55
import { Awareness } from 'y-protocols/awareness';
66

77
import { getUserIconUrl } from '@/application/user-metadata';
8+
import { Log } from '@/utils/log';
89
import { useCurrentUser, useService } from '@/components/main/app.hooks';
910

1011
import { AwarenessMetadata, AwarenessState } from './types';
@@ -49,7 +50,7 @@ export function useDispatchUserAwareness(awareness?: Awareness) {
4950
awareness.setLocalState(awarenessState);
5051

5152
// Log successful user awareness dispatch
52-
console.debug('📡 User awareness dispatched:', awarenessState);
53+
Log.debug('📡 User awareness dispatched:', awarenessState);
5354
},
5455
[awareness]
5556
);
@@ -100,7 +101,7 @@ export function useDispatchCursorAwareness(awareness?: Awareness) {
100101
awareness.setLocalState(awarenessState);
101102

102103
// Log successful cursor awareness sync
103-
console.debug('🎯 Cursor awareness synced:', awarenessState);
104+
Log.debug('🎯 Cursor awareness synced:', awarenessState);
104105
} catch (error) {
105106
// Log conversion errors for debugging
106107
console.warn('⚠️ Cursor awareness sync failed:', error);
@@ -149,7 +150,7 @@ export function useDispatchClearAwareness(awareness?: Awareness) {
149150
});
150151

151152
// Log awareness clear
152-
console.debug('🚫 Awareness cleared for current user');
153+
Log.debug('🚫 Awareness cleared for current user');
153154
}, [awareness, service, currentUser]);
154155

155156
const clearCursor = useCallback((workspaceAvatar?: string | null) => {
@@ -171,7 +172,7 @@ export function useDispatchClearAwareness(awareness?: Awareness) {
171172
}),
172173
});
173174

174-
console.debug('🚫 Cursor awareness cleared for current user');
175+
Log.debug('🚫 Cursor awareness cleared for current user');
175176
}, [awareness, service, currentUser]);
176177

177178
return { clearAwareness, clearCursor };

src/application/awareness/selector.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useSlate } from 'slate-react';
44
import { Awareness } from 'y-protocols/awareness';
55

66
import { useService } from '@/components/main/app.hooks';
7+
import { Log } from '@/utils/log';
78

89
import { AwarenessMetadata, AwarenessState, AwarenessUser, Cursor } from './types';
910
import { convertAwarenessSelection } from './utils';
@@ -92,7 +93,7 @@ export function useRemoteSelectionsSelector(awareness?: Awareness) {
9293
timestamp: state.timestamp,
9394
});
9495
} else {
95-
console.debug(`🎯 No selection found for client ${clientId}`);
96+
Log.debug(`🎯 No selection found for client ${clientId}`);
9697
}
9798
});
9899

@@ -120,7 +121,7 @@ export function useRemoteSelectionsSelector(awareness?: Awareness) {
120121
};
121122
});
122123

123-
console.debug('🎯 Final cursors array:', result);
124+
Log.debug('🎯 Final cursors array:', result);
124125
return result;
125126
}, [cursors, editor]);
126127

src/application/database-yjs/dispatch.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useCallback, useMemo } from 'react';
55
import { v4 as uuidv4 } from 'uuid';
66
import * as Y from 'yjs';
77

8+
import { Log } from '@/utils/log';
89
import { parseYDatabaseDateTimeCellToCell } from '@/application/database-yjs/cell.parse';
910
import {
1011
useCreateRow,
@@ -2002,7 +2003,7 @@ function updateDateCell(
20022003
}
20032004

20042005
if (payload.includeTime !== undefined) {
2005-
console.debug('includeTime', payload.includeTime);
2006+
Log.debug('includeTime', payload.includeTime);
20062007
cell.set(YjsDatabaseKey.include_time, payload.includeTime);
20072008
}
20082009

@@ -3737,7 +3738,7 @@ export function useUpdateFileMediaTypeOption(fieldId: string) {
37373738
);
37383739
typeOptionMap.set(String(FieldType.FileMedia), newTypeOption);
37393740
} else {
3740-
console.debug('Updating file media type option', typeOption.toJSON());
3741+
Log.debug('Updating file media type option', typeOption.toJSON());
37413742
typeOption.set(
37423743
YjsDatabaseKey.content,
37433744
JSON.stringify({

src/application/db/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IndexeddbPersistence } from 'y-indexeddb';
33
import * as Y from 'yjs';
44

55
import { databasePrefix } from '@/application/constants';
6+
import { Log } from '@/utils/log';
67
import { rowSchema, rowTable } from '@/application/db/tables/rows';
78
import { userSchema, UserTable } from '@/application/db/tables/users';
89
import { viewMetasSchema, ViewMetasTable } from '@/application/db/tables/view_metas';
@@ -106,7 +107,7 @@ export async function clearData() {
106107
const deleteRequest = indexedDB.deleteDatabase(dbName);
107108

108109
deleteRequest.onsuccess = () => {
109-
console.debug(`Database ${dbName} deleted successfully`);
110+
Log.debug(`Database ${dbName} deleted successfully`);
110111
resolve(true);
111112
};
112113

src/application/services/js-services/cache/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getRowKey } from '@/application/database-yjs/row_meta';
22
import { closeCollabDB, db, openCollabDB } from '@/application/db';
33
import { Fetcher, StrategyType } from '@/application/services/js-services/cache/types';
4+
import { Log } from '@/utils/log';
45
import {
56
DatabaseId,
67
PublishViewMetaData,
@@ -390,7 +391,7 @@ export async function deleteViewMeta(name: string) {
390391
}
391392

392393
export async function deleteView(name: string) {
393-
console.debug('deleteView', name);
394+
Log.debug('deleteView', name);
394395
await deleteViewMeta(name);
395396
await closeCollabDB(name);
396397

src/application/services/js-services/http/http_api.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { omit } from 'lodash-es';
44
import { nanoid } from 'nanoid';
55

66
import { GlobalComment, Reaction } from '@/application/comment.type';
7+
import { Log } from '@/utils/log';
78
import { ERROR_CODE } from '@/application/constants';
89
import { initGrantService, refreshToken } from '@/application/services/js-services/http/gotrue';
910
import { parseGoTrueErrorFromUrl } from '@/application/services/js-services/http/gotrue-error';
@@ -155,7 +156,7 @@ async function executeAPIRequest<TResponseData = unknown>(
155156

156157
const method = response.config?.method?.toUpperCase() || 'UNKNOWN';
157158

158-
console.debug('[executeAPIRequest]', { method, url: requestUrl });
159+
Log.debug('[executeAPIRequest]', { method, url: requestUrl });
159160

160161
if (!response.data) {
161162
console.error('[executeAPIRequest] No response data received', response);
@@ -238,7 +239,7 @@ export function initAPIService(config: AFCloudConfig) {
238239
const token = getTokenParsed();
239240

240241
if (!token) {
241-
console.debug('[initAPIService][request] no token found, sending request without auth header', {
242+
Log.debug('[initAPIService][request] no token found, sending request without auth header', {
242243
url: config.url,
243244
});
244245
return config;
@@ -359,7 +360,7 @@ export async function signInWithUrl(url: string) {
359360
const hadOldToken = !!localStorage.getItem('token');
360361

361362
if (hadOldToken) {
362-
console.debug('[signInWithUrl] Clearing old token before processing OAuth callback to prevent race condition');
363+
Log.debug('[signInWithUrl] Clearing old token before processing OAuth callback to prevent race condition');
363364
localStorage.removeItem('token');
364365
}
365366

@@ -1400,7 +1401,7 @@ export async function uploadImportFile(presignedUrl: string, file: File, onProgr
14001401
onUploadProgress: (progressEvent) => {
14011402
const { progress = 0 } = progressEvent;
14021403

1403-
console.debug(`Upload progress: ${progress * 100}%`);
1404+
Log.debug(`Upload progress: ${progress * 100}%`);
14041405
onProgress(progress);
14051406
},
14061407
headers: {
@@ -1425,7 +1426,7 @@ export async function createDatabaseView(
14251426
) {
14261427
const url = `/api/workspace/${workspaceId}/page-view/${viewId}/database-view`;
14271428

1428-
console.debug('[createDatabaseView]', { url, workspaceId, viewId, payload });
1429+
Log.debug('[createDatabaseView]', { url, workspaceId, viewId, payload });
14291430

14301431
return executeAPIRequest<CreateDatabaseViewResponse>(() =>
14311432
axiosInstance?.post<APIResponse<CreateDatabaseViewResponse>>(url, {

src/application/services/js-services/sync-protocol.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as awarenessProtocol from 'y-protocols/awareness';
33
import * as Y from 'yjs';
44

55
import { Types } from '@/application/types';
6+
import { Log } from '@/utils/log';
67
import { collab, messages } from '@/proto/messages';
78

89
/**
@@ -61,7 +62,7 @@ const handleAccessChanged = (ctx: SyncContext, message: collab.IAccessChanged):
6162

6263
const handleAwarenessUpdate = (ctx: SyncContext, message: collab.IAwarenessUpdate): void => {
6364
if (!ctx.awareness) {
64-
console.debug(`No awareness instance found in SyncContext for objectId ${ctx.doc.guid}`);
65+
Log.debug(`No awareness instance found in SyncContext for objectId ${ctx.doc.guid}`);
6566
} else {
6667
awarenessProtocol.applyAwarenessUpdate(ctx.awareness, message.payload!, 'remote');
6768
}
@@ -81,12 +82,12 @@ const handleUpdate = (ctx: SyncContext, message: collab.IUpdate): void => {
8182
throw new Error(`Unknown update flags: ${message.flags} at ${message.messageId?.timestamp}`);
8283
}
8384

84-
console.debug(`applied update to doc ${doc.guid}`);
85+
Log.debug(`applied update to doc ${doc.guid}`);
8586
ctx.lastMessageId = message.messageId || ctx.lastMessageId;
8687

8788
// check if there are any missing update data
8889
if (doc.store.pendingStructs || doc.store.pendingDs) {
89-
console.debug(`Doc ${doc.guid} has missing dependencies. Sending sync request...`);
90+
Log.debug(`Doc ${doc.guid} has missing dependencies. Sending sync request...`);
9091
emit({
9192
collabMessage: {
9293
objectId: doc.guid,
@@ -117,7 +118,7 @@ export const initSync = (ctx: SyncContext) => {
117118
throw new Error('SyncContext must have a Y.Doc instance.');
118119
}
119120

120-
console.debug(`Initializing sync for objectId ${doc.guid} with collabType ${collabType}`);
121+
Log.debug(`Initializing sync for objectId ${doc.guid} with collabType ${collabType}`);
121122

122123
let onAwarenessChange;
123124
const updates: Uint8Array[] = [];

src/application/slate-yjs/utils/applyTextToSlate.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Editor, Element, Operation, Path, Text } from 'slate';
33
import * as Y from 'yjs';
44

55
import { YjsEditor } from '@/application/slate-yjs';
6+
import { Log } from '@/utils/log';
67

78
interface Delta {
89
retain?: number;
@@ -30,7 +31,7 @@ function applyTextYEvent(editor: YjsEditor, textId: string, event: Y.YTextEvent)
3031
const [targetElement, textPath] = entry as [Element, number[]];
3132
const delta = event.delta as Delta[];
3233

33-
console.debug('📝 Applying YText event', {
34+
Log.debug('📝 Applying YText event', {
3435
textId,
3536
delta,
3637
targetPath: textPath,
@@ -39,10 +40,10 @@ function applyTextYEvent(editor: YjsEditor, textId: string, event: Y.YTextEvent)
3940
Editor.withoutNormalizing(editor, () => {
4041
const operations = applyDelta(targetElement, textPath, delta);
4142

42-
console.debug(`🔄 Generated ${operations.length} operations from delta:`, operations);
43+
Log.debug(`🔄 Generated ${operations.length} operations from delta:`, operations);
4344

4445
operations.forEach((op, index) => {
45-
console.debug(`Applying operation ${index + 1}/${operations.length}:`, op);
46+
Log.debug(`Applying operation ${index + 1}/${operations.length}:`, op);
4647
editor.apply(op);
4748
});
4849
});
@@ -121,7 +122,7 @@ function handleAttributeChange(
121122
): Operation[] {
122123
const ops: Operation[] = [];
123124

124-
console.debug(`🎨 Applying attributes from offset ${startOffset} to ${endOffset}:`, attributes);
125+
Log.debug(`🎨 Applying attributes from offset ${startOffset} to ${endOffset}:`, attributes);
125126

126127
// Convert Y offsets to Slate path/text offsets
127128
const [startPathOffset, startTextOffset] = yOffsetToSlateOffsets(node, startOffset);
@@ -210,7 +211,7 @@ function handleAttributeChange(
210211
function handleDelete(node: Element, slatePath: Path, startOffset: number, endOffset: number): Operation[] {
211212
const ops: Operation[] = [];
212213

213-
console.debug(`➖ Deleting from offset ${startOffset} to ${endOffset}`);
214+
Log.debug(`➖ Deleting from offset ${startOffset} to ${endOffset}`);
214215

215216
const [startPathOffset, startTextOffset] = yOffsetToSlateOffsets(node, startOffset);
216217
const [endPathOffset, endTextOffset] = yOffsetToSlateOffsets(node, endOffset, { assoc: -1 });
@@ -282,7 +283,7 @@ function handleInsert(
282283
): Operation[] {
283284
const ops: Operation[] = [];
284285

285-
console.debug(`➕ Inserting at offset ${offset}:`, insert, attributes);
286+
Log.debug(`➕ Inserting at offset ${offset}:`, insert, attributes);
286287

287288
const [pathOffset, textOffset] = yOffsetToSlateOffsets(node, offset, { insert: true });
288289

src/application/slate-yjs/utils/applyToSlate.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,42 @@ interface YBlockChange {
2727
* @param events - Array of Yjs events to process
2828
*/
2929
export function translateYEvents(editor: YjsEditor, events: Array<YEvent>) {
30-
console.debug('=== Translating Yjs events to Slate operations ===', {
30+
Log.debug('=== Translating Yjs events to Slate operations ===', {
3131
eventCount: events.length,
3232
eventTypes: events.map((e) => e.path.join('.')),
3333
timestamp: new Date().toISOString(),
3434
});
3535

3636
events.forEach((event, index) => {
37-
console.debug(`Processing event ${index + 1}/${events.length}:`, {
37+
Log.debug(`Processing event ${index + 1}/${events.length}:`, {
3838
path: event.path,
3939
type: event.constructor.name,
4040
});
4141

4242
// Handle block-level changes (document.blocks)
4343
if (isEqual(event.path, ['document', 'blocks'])) {
44-
console.debug('→ Applying block map changes');
44+
Log.debug('→ Applying block map changes');
4545
applyBlocksYEvent(editor, event as BlockMapEvent);
4646
}
4747

4848
// Handle individual block updates (document.blocks[blockId])
4949
if (isEqual(event.path, ['document', 'blocks', event.path[2]])) {
5050
const blockId = event.path[2] as string;
5151

52-
console.debug(`→ Applying block update for blockId: ${blockId}`);
52+
Log.debug(`→ Applying block update for blockId: ${blockId}`);
5353
applyUpdateBlockYEvent(editor, blockId, event as YMapEvent<unknown>);
5454
}
5555

5656
// Handle text content changes (document.meta.text_map[textId])
5757
if (isEqual(event.path, ['document', 'meta', 'text_map', event.path[3]])) {
5858
const textId = event.path[3] as string;
5959

60-
console.debug(`→ Applying text content changes for textId: ${textId}`);
60+
Log.debug(`→ Applying text content changes for textId: ${textId}`);
6161
applyTextYEvent(editor, textId, event as YTextEvent);
6262
}
6363
});
6464

65-
console.debug('=== Yjs events translation completed ===');
65+
Log.debug('=== Yjs events translation completed ===');
6666
}
6767

6868
/**
@@ -91,7 +91,7 @@ function applyUpdateBlockYEvent(editor: YjsEditor, blockId: string, event: YMapE
9191
const [node, path] = entry;
9292
const oldData = node.data as Record<string, unknown>;
9393

94-
console.debug(`✅ Updating block data for blockId: ${blockId}`, {
94+
Log.debug(`✅ Updating block data for blockId: ${blockId}`, {
9595
path,
9696
oldDataKeys: Object.keys(oldData),
9797
newDataKeys: Object.keys(newData),
@@ -121,7 +121,7 @@ function applyBlocksYEvent(editor: YjsEditor, event: BlockMapEvent) {
121121
const { changes, keysChanged } = event;
122122
const { keys } = changes;
123123

124-
console.debug('🔄 Processing block map changes:', {
124+
Log.debug('🔄 Processing block map changes:', {
125125
keysChangedCount: keysChanged?.size ?? 0,
126126
keysChanged: Array.from(keysChanged ?? []),
127127
changes: Array.from(keys.entries()).map(([key, value]) => ({

src/application/slate-yjs/utils/applyToYjs.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'slate';
1212
import * as Y from 'yjs';
1313

14+
import { Log } from '@/utils/log';
1415
import { EditorMarkFormat } from '@/application/slate-yjs/types';
1516
import { getNodeAtPath } from '@/application/slate-yjs/utils/editor';
1617
import { calculateOffsetRelativeToParent } from '@/application/slate-yjs/utils/positions';
@@ -102,7 +103,7 @@ function insertText(
102103
yText.insert(relativeOffset, text, attributes);
103104
}
104105

105-
console.debug('insertText', attributes, yText.toDelta());
106+
Log.debug('insertText', attributes, yText.toDelta());
106107
}
107108

108109
function applyInsertText(ydoc: Y.Doc, editor: Editor, op: InsertTextOperation, slateContent: Descendant[]) {
@@ -158,7 +159,7 @@ function applyRemoveText(ydoc: Y.Doc, editor: Editor, op: RemoveTextOperation, s
158159

159160
yText.delete(relativeOffset, text.length);
160161

161-
console.debug('applyRemoveText', op, yText.toDelta());
162+
Log.debug('applyRemoveText', op, yText.toDelta());
162163
}
163164

164165
function applySetNode(ydoc: Y.Doc, editor: Editor, op: SetNodeOperation, slateContent: Descendant[]) {
@@ -171,7 +172,7 @@ function applySetNode(ydoc: Y.Doc, editor: Editor, op: SetNodeOperation, slateCo
171172
const isData = Object.keys(newProperties).some((prop: string) => prop === 'data');
172173
const sharedRoot = ydoc.getMap(YjsEditorKey.data_section) as YSharedRoot;
173174

174-
console.debug('applySetNode isLeaf', isLeaf, op);
175+
Log.debug('applySetNode isLeaf', isLeaf, op);
175176
if (isLeaf) {
176177
const node = getNodeAtPath(slateContent, path.slice(0, -1)) as Element;
177178
const textId = node.textId;

0 commit comments

Comments
 (0)