Skip to content

feat: Threads sidebar #1454

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

Merged
merged 174 commits into from
Mar 19, 2025
Merged
Changes from 1 commit
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
4d6e252
wip: better liveblocks support
YousefED Nov 14, 2024
dcd7c72
Merge remote-tracking branch 'origin/main' into feature/liveblocks-v2
YousefED Nov 18, 2024
c659253
misc fixes
YousefED Nov 18, 2024
a03d33f
misc
YousefED Nov 19, 2024
85521df
revert minimal
YousefED Nov 19, 2024
e43741a
simplify setup
YousefED Nov 20, 2024
e0c7f0f
update config
YousefED Nov 20, 2024
d747238
fix
YousefED Nov 20, 2024
6ce69ea
fix
YousefED Nov 20, 2024
a3028c1
markview
YousefED Dec 14, 2024
15c7520
cleanup
YousefED Dec 14, 2024
b8a8d49
Merge remote-tracking branch 'origin/main' into feature/liveblocks-v2
YousefED Jan 8, 2025
1b44296
wip
YousefED Jan 10, 2025
23275a0
wip
YousefED Jan 13, 2025
721a4e9
wip
YousefED Jan 14, 2025
e824c42
wip
YousefED Jan 15, 2025
f2d4bb8
misc
YousefED Jan 16, 2025
434eafa
add threadstore tests
YousefED Jan 16, 2025
9d35f72
document recommended auth rules
YousefED Jan 16, 2025
58ed7c0
resolve
YousefED Jan 16, 2025
b761e1e
basic userstore impl
YousefED Jan 16, 2025
5f52147
user auth
YousefED Jan 16, 2025
060708d
Big comments UX WIP
matthewlipski Jan 24, 2025
5c6f45b
Merge branch 'main' into feature/comments
matthewlipski Jan 28, 2025
16c6a7a
Merge branch 'main' into feature/comments
matthewlipski Jan 28, 2025
a5e07c0
Updated reactions UX
matthewlipski Jan 28, 2025
b42047f
change reaction implementation
YousefED Feb 10, 2025
43a1eb0
reactions improvements
YousefED Feb 10, 2025
306c335
small cleanup
YousefED Feb 10, 2025
99d9d21
cleanups + mark some todos
YousefED Feb 10, 2025
4501af4
comments
YousefED Feb 11, 2025
eadb49d
fix locales
YousefED Feb 11, 2025
b81bab0
Merge remote-tracking branch 'upstream/main' into feature/comments
YousefED Feb 11, 2025
9f40651
fix build
YousefED Feb 11, 2025
7ae2b7f
cleanup + sample
YousefED Feb 11, 2025
748a183
fix build
YousefED Feb 11, 2025
e93b53b
fix lint
YousefED Feb 11, 2025
be9dd46
disable liveblocks for now
YousefED Feb 11, 2025
3e93d1e
lint
YousefED Feb 11, 2025
40269a5
fix linkify warning + make toggle editable comment
YousefED Feb 11, 2025
62a8944
fix content reset bug
YousefED Feb 11, 2025
22fdde6
Implemented PR feedback
matthewlipski Feb 11, 2025
c293fdf
Merge remote-tracking branch 'origin/feature/comments' into feature/c…
matthewlipski Feb 11, 2025
c0d1bd5
fix placeholder
YousefED Feb 12, 2025
311881c
Merge branch 'feature/comments' of github.com:TypeCellOS/BlockNote in…
YousefED Feb 12, 2025
a71fc69
clean comment editor
YousefED Feb 12, 2025
4d498de
fix build
YousefED Feb 12, 2025
c5a6a0c
fix placeholders
YousefED Feb 12, 2025
3f7828d
- Adjusted comment spacing
matthewlipski Feb 13, 2025
d2c9f34
Implemented PR feedback
matthewlipski Feb 14, 2025
6df6886
fix build
YousefED Feb 14, 2025
5b7e3d4
implement TipTapThreadStore
YousefED Feb 14, 2025
3ef17e5
address feedback
YousefED Feb 14, 2025
db7d339
add comment
YousefED Feb 17, 2025
6067a2b
Merge remote-tracking branch 'origin/main' into feature/liveblocks-v2
YousefED Feb 17, 2025
298ba46
Merge branch 'feature/liveblocks-v2' into feature/comments
YousefED Feb 17, 2025
c007f84
wip
YousefED Feb 17, 2025
99c599c
Merge branch 'main' into feature/comments
YousefED Feb 18, 2025
c0c848a
add autofocus
YousefED Feb 18, 2025
9576cfe
Simplified tooltip + popover interaction
matthewlipski Feb 18, 2025
9fa9d07
wip
YousefED Feb 19, 2025
44b2dca
feat: ShadCN comments (#1445)
matthewlipski Feb 20, 2025
6c6b017
change reaction auth
YousefED Feb 20, 2025
97f1f0a
Merge branch 'feature/comments' of github.com:TypeCellOS/BlockNote in…
YousefED Feb 20, 2025
5decc46
make emoji optional
YousefED Feb 20, 2025
4cb7af0
fix bug
YousefED Feb 20, 2025
27a2523
Extracted reaction badge WIP
matthewlipski Feb 20, 2025
b27db16
Merge remote-tracking branch 'origin/feature/comments' into feature/c…
matthewlipski Feb 20, 2025
65dfc20
fix useUsers
YousefED Feb 20, 2025
2fe1052
Fixed formatting toolbar not showing up when editor is non-editable
matthewlipski Feb 20, 2025
e3291d0
Merge remote-tracking branch 'origin/feature/comments' into feature/c…
matthewlipski Feb 20, 2025
165a014
Fixed reaction badge tooltip line breaks and made leaving comment not…
matthewlipski Feb 20, 2025
d11053c
Merge remote-tracking branch 'origin/feature/comments' into feature/c…
YousefED Feb 20, 2025
807d8d1
Improved badge UX and made reactions hide when editing
matthewlipski Feb 20, 2025
3fada1a
wip
YousefED Feb 21, 2025
4d3d2ff
refactor: add renderEditor boolean to BlockNoteView
YousefED Feb 21, 2025
42cdbd1
Merge branch 'refactor/blocknoteview' into feature/comments-streamview
YousefED Feb 21, 2025
e3e5867
Fixed new comments sometimes not being selectable
matthewlipski Feb 21, 2025
bcd375d
fix unnecessary rerender
YousefED Feb 21, 2025
6bdbf15
remove unused files
YousefED Feb 21, 2025
ec26b30
Improved UX/UI
matthewlipski Feb 21, 2025
a2b9e30
Merge remote-tracking branch 'origin/feature/comments-streamview' int…
matthewlipski Feb 21, 2025
d0b3f39
rest thread store
YousefED Feb 22, 2025
cfd94eb
fix copy/paste
YousefED Feb 22, 2025
ac6a17c
add shift
YousefED Feb 22, 2025
f200646
add docs
YousefED Feb 22, 2025
7c0746e
Merge remote-tracking branch 'origin/main' into feature/comments
YousefED Feb 22, 2025
4d293ef
update docs
YousefED Feb 22, 2025
85f0f9f
Merge branch 'feature/comments' into feature/comments-streamview
YousefED Feb 22, 2025
f35a66a
revert liveblocks, will be separate PR
YousefED Feb 23, 2025
8d9d542
clean lockfile
YousefED Feb 23, 2025
0f1e019
fix some todos
YousefED Feb 23, 2025
490291f
adress number of comments
YousefED Feb 23, 2025
11d9ee6
address more comments
YousefED Feb 23, 2025
7d4b64e
address some comments
YousefED Feb 23, 2025
8ec3e50
clean commentsplugin
YousefED Feb 23, 2025
fa1e5a7
ForceSelectionVisible
YousefED Feb 23, 2025
f2f29e7
fix floatingcomposercontroller
YousefED Feb 23, 2025
e97985e
fix unit test
YousefED Feb 23, 2025
c7b1f85
Merge branch 'feature/comments' into feature/comments-streamview
YousefED Feb 23, 2025
a4a90b8
close threads on esc
YousefED Feb 23, 2025
df1d6a0
Merge remote-tracking branch 'origin/main' into feature/comments
YousefED Feb 23, 2025
7b128dc
remove debugger
YousefED Feb 23, 2025
9ae74bd
small fix
YousefED Feb 24, 2025
953aefa
Fixed badge styles on docs
matthewlipski Feb 25, 2025
46101a0
Fixed badge click handler
matthewlipski Feb 25, 2025
ab00b5d
Added remaining UX fixes from Mantine to Ariakit/ShadCN
matthewlipski Feb 25, 2025
38a670d
Externalized strings
matthewlipski Feb 26, 2025
8d8ebec
Small styling fix
matthewlipski Feb 26, 2025
6744b26
Merge branch 'main' into feature/comments
matthewlipski Feb 26, 2025
a7a5656
Small styling fix
matthewlipski Feb 26, 2025
ebfb4da
Fix lint
matthewlipski Feb 26, 2025
9944ca7
Fixed side menu regression issue
matthewlipski Feb 26, 2025
30003d7
Implemented PR feedback
matthewlipski Feb 27, 2025
f1557b1
Implemented PR feedback
matthewlipski Feb 27, 2025
a647ec3
Updated emoji picker screenshots
matthewlipski Feb 28, 2025
065c74d
Revert "Updated emoji picker screenshots"
matthewlipski Feb 28, 2025
f26edd3
Merge branch 'main' into feature/comments
matthewlipski Feb 28, 2025
ae534b4
Updated `package-lock.json`
matthewlipski Feb 28, 2025
9a12826
Merge branch 'main' into feature/comments
matthewlipski Feb 28, 2025
828d13e
Fixed `no` locale
matthewlipski Feb 28, 2025
46836e5
Updated `package-lock.json`
matthewlipski Feb 28, 2025
641a6b8
Added temp test pass
matthewlipski Feb 28, 2025
f13a43c
Merged main
matthewlipski Mar 3, 2025
c4a4819
Fixed merge issues
matthewlipski Mar 3, 2025
95da229
Merge branch 'feature/comments' into feature/comments-streamview
matthewlipski Mar 3, 2025
4313177
Fixed issues and build
matthewlipski Mar 3, 2025
290834e
Separated open and resolved comments
matthewlipski Mar 3, 2025
6f5575d
Merge branch 'main' into feature/comments-streamview
matthewlipski Mar 5, 2025
2b0dd0b
Small fixes
matthewlipski Mar 5, 2025
615b5cd
BlockNoteView changes and major UX improvements
matthewlipski Mar 5, 2025
8b3b0fc
Small user select change
matthewlipski Mar 5, 2025
f83207c
- Renamed `ThreadStreamView` to `ThreadsSidebar`
matthewlipski Mar 6, 2025
b5fb0e7
Small cleanup
matthewlipski Mar 6, 2025
1978fa9
Fix build and cleanup
matthewlipski Mar 6, 2025
0ead24d
Merge branch 'main' into feature/comments-streamview
matthewlipski Mar 6, 2025
1c987e2
`BlockNoteView` fix
matthewlipski Mar 6, 2025
b12de1a
WIP feedback TODOs
matthewlipski Mar 11, 2025
150251a
WIP feedback
matthewlipski Mar 11, 2025
8ea7ae2
Small fix
matthewlipski Mar 11, 2025
1c39781
Small fix
matthewlipski Mar 11, 2025
d706b60
WIP feedback
matthewlipski Mar 11, 2025
89eda3b
WIP feedback
matthewlipski Mar 11, 2025
1851f1c
WIP feedback
matthewlipski Mar 12, 2025
250f823
WIP feedback
matthewlipski Mar 12, 2025
502627b
Shrunk emoji picker
matthewlipski Mar 12, 2025
495b793
Fixed build
matthewlipski Mar 13, 2025
4890967
Fixed lint
matthewlipski Mar 13, 2025
f9e8bc2
Small styling fix
matthewlipski Mar 13, 2025
65a4c72
Fixed docs build
matthewlipski Mar 13, 2025
41b6177
Merge branch 'main' into feature/comments-streamview
matthewlipski Mar 13, 2025
d072e66
Updated `Thread` and `Comment` props + small changes
matthewlipski Mar 13, 2025
80bb337
Implemented PR feedback
matthewlipski Mar 13, 2025
e49a066
Merge branch 'main' into feature/comments-streamview
matthewlipski Mar 13, 2025
27a33da
Updated demo styles
matthewlipski Mar 13, 2025
a8d46ac
Added file name extensions to examples
matthewlipski Mar 13, 2025
49aa06b
Added docs & minor changes
matthewlipski Mar 17, 2025
8db2f1a
Fixed i18n
matthewlipski Mar 17, 2025
ef94c80
Styling changes
matthewlipski Mar 17, 2025
c532ac2
Fixed lint/build
matthewlipski Mar 17, 2025
5209c2d
improve commentplugin state
YousefED Mar 17, 2025
dc8c7f7
Merge branch 'feature/comments-streamview' of github.com:TypeCellOS/B…
YousefED Mar 17, 2025
184977a
clean threadssidebar and fix performance
YousefED Mar 17, 2025
d25fe2c
Implemented PR feedback
matthewlipski Mar 17, 2025
d4f7a09
Moved styles
matthewlipski Mar 18, 2025
ed07f0e
Reverted doc ID
matthewlipski Mar 18, 2025
9fe3cf5
Resolved remaining feedback
matthewlipski Mar 18, 2025
5c369c4
Small fix
matthewlipski Mar 18, 2025
a49d236
Fixed TODOs
matthewlipski Mar 18, 2025
eba834d
Small fix
matthewlipski Mar 18, 2025
35edf21
Implemented remaining TODO
matthewlipski Mar 18, 2025
f9d85a5
Implemented PR feedback
matthewlipski Mar 18, 2025
123e8e2
Small examples update
matthewlipski Mar 19, 2025
79e2f77
Small styling fix
matthewlipski Mar 19, 2025
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
160 changes: 102 additions & 58 deletions packages/react/src/components/Comments/ThreadsSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
import { BlockNoteEditor, UnreachableCaseError } from "@blocknote/core";
import { ThreadData } from "@blocknote/core/comments";
import { useMemo } from "react";
import React, { useCallback, useMemo } from "react";
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
import { useUIPluginState } from "../../hooks/useUIPluginState.js";
import { Thread } from "./Thread.js";
import { useThreads } from "./useThreads.js";

type ThreadItemProps = {
thread: ThreadData;
selectedThreadId?: string;
editor: BlockNoteEditor<any, any, any>;
maxCommentsBeforeCollapse?: number;
referenceText: string;
};

/**
* This component is memoized because it's a child of the ThreadsSidebar component,
* which rerenders on every document update.
*/
const ThreadItem = React.memo(
({
thread,
selectedThreadId,
editor,
maxCommentsBeforeCollapse,
referenceText,
}: ThreadItemProps) => {
const onFocus = useCallback(() => {
editor.comments?.selectThread(thread.id);
}, [editor.comments, thread.id]);

const onBlur = useCallback(
(event: React.FocusEvent) => {
const targetElement =
event.target instanceof Node ? event.target : null;
const parentThreadElement =
event.relatedTarget instanceof Node
? event.relatedTarget.closest(".bn-thread")
: null;

// When you focus the editor (reply composer), we don't want to unselect the thread
// This check prevents that. But we still want to unselect the thread when it gets blurred in all other cases
if (
!targetElement ||
!parentThreadElement ||
!parentThreadElement.contains(targetElement)
) {
editor.comments?.selectThread(undefined);
}
},
[editor.comments]
);

return (
<Thread
thread={thread}
selected={thread.id === selectedThreadId}
referenceText={referenceText}
maxCommentsBeforeCollapse={maxCommentsBeforeCollapse}
onFocus={onFocus}
onBlur={onBlur}
tabIndex={0}
/>
);
}
);

function sortThreads(
threads: ThreadData[],
sort: "position" | "recent-activity" | "oldest",
Expand Down Expand Up @@ -100,15 +160,18 @@ export function ThreadsSidebar(props: {
throw new Error("Comments plugin not found");
}

// Note: because "threadPositions" is part of the state,
// this will potentially trigger a re-render on every document update
// this means we need to be mindful of children memoization
const state = useUIPluginState(
editor.comments.onUpdate.bind(editor.comments)
);

const selectedThreadId = state?.selectedThreadId;

const threads = useThreads(editor);

// memo needed?
const threadElements = useMemo(() => {
const filteredAndSortedThreads = useMemo(() => {
const threadsArray = Array.from(threads.values());

const sortedThreads = sortThreads(
Expand All @@ -117,66 +180,47 @@ export function ThreadsSidebar(props: {
state?.threadPositions
);

const openThreads: ThreadData[] = [];
const resolvedThreads: ThreadData[] = [];
const ret: Array<{ thread: ThreadData; referenceText: string }> = [];

for (const thread of sortedThreads) {
if (!thread.resolved) {
openThreads.push(thread);
if (props.filter === "open" || props.filter === "all") {
ret.push({
thread,
referenceText: getReferenceText(
editor,
state?.threadPositions.get(thread.id)
),
});
}
} else {
resolvedThreads.push(thread);
if (props.filter === "resolved" || props.filter === "all") {
ret.push({
thread,
referenceText: getReferenceText(
editor,
state?.threadPositions.get(thread.id)
),
});
}
}
}

const threadDataToElement = (thread: ThreadData) => (
<Thread
key={thread.id}
thread={thread}
selected={thread.id === selectedThreadId}
referenceText={getReferenceText(
editor,
state?.threadPositions.get(thread.id)
)}
maxCommentsBeforeCollapse={props.maxCommentsBeforeCollapse}
onFocus={() => editor.comments?.selectThread(thread.id)}
onBlur={(event) => {
const targetElement =
event.target instanceof Node ? event.target : null;
const parentThreadElement =
event.relatedTarget instanceof Node
? event.relatedTarget.closest(".bn-thread")
: null;

if (
!targetElement ||
!parentThreadElement ||
!parentThreadElement.contains(targetElement)
) {
editor.comments?.selectThread(undefined);
}
}}
tabIndex={0}
/>
);

if (props.filter === "open") {
return openThreads.map(threadDataToElement);
}

if (props.filter === "resolved") {
return resolvedThreads.map(threadDataToElement);
}

return [...openThreads, ...resolvedThreads].map(threadDataToElement);
}, [
editor,
props.filter,
props.sort,
props.maxCommentsBeforeCollapse,
selectedThreadId,
state?.threadPositions,
threads,
]);

return <div className={"bn-threads-sidebar"}>{threadElements}</div>;
return ret;
}, [threads, state?.threadPositions, props.filter, props.sort, editor]);

return (
<div className={"bn-threads-sidebar"}>
{filteredAndSortedThreads.map((thread) => (
<ThreadItem
key={thread.thread.id}
thread={thread.thread}
selectedThreadId={selectedThreadId}
editor={editor}
referenceText={thread.referenceText}
maxCommentsBeforeCollapse={props.maxCommentsBeforeCollapse}
/>
))}
</div>
);
}
Loading