Skip to content
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

Fix liveblocks - Comments resolver functions #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 42 additions & 38 deletions liveblocks.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,45 @@ import { createRoomContext } from "@liveblocks/react";
const client = createClient({
throttle: 16,
publicApiKey: process.env.NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY!,
async resolveUsers({ userIds }) {
// Used only for Comments. Return a list of user information retrieved
// from `userIds`. This info is used in comments, mentions etc.

// const usersData = await __fetchUsersFromDB__(userIds);
//
// return usersData.map((userData) => ({
// name: userData.name,
// avatar: userData.avatar.src,
// }));

return userIds.map((userId) => ({
name: userId,
avatar: `https://ui-avatars.com/api/?name=${userId}&background=random`,
}));
},
async resolveMentionSuggestions({ text, roomId }) {
// Used only for Comments. Return a list of userIds that match `text`.
// These userIds are used to create a mention list when typing in the
// composer.
//
// For example when you type "@jo", `text` will be `"jo"`, and
// you should to return an array with John and Joanna's userIds:
// ["[email protected]", "[email protected]"]

// const userIds = await __fetchAllUserIdsFromDB__(roomId);
//
// Return all userIds if no `text`
// if (!text) {
// return userIds;
// }
//
// Otherwise, filter userIds for the search `text` and return
// return userIds.filter((userId) =>
// userId.toLowerCase().includes(text.toLowerCase())
// );

return [];
},
});

// Presence represents the properties that exist on every user in the Room
Expand Down Expand Up @@ -86,41 +125,6 @@ export const {
useAddReaction,
useRemoveReaction,
},
} = createRoomContext<Presence, Storage, UserMeta, RoomEvent, ThreadMetadata>(client, {
async resolveUsers({ userIds }) {
// Used only for Comments. Return a list of user information retrieved
// from `userIds`. This info is used in comments, mentions etc.

// const usersData = await __fetchUsersFromDB__(userIds);
//
// return usersData.map((userData) => ({
// name: userData.name,
// avatar: userData.avatar.src,
// }));

return [];
},
async resolveMentionSuggestions({ text, roomId }) {
// Used only for Comments. Return a list of userIds that match `text`.
// These userIds are used to create a mention list when typing in the
// composer.
//
// For example when you type "@jo", `text` will be `"jo"`, and
// you should to return an array with John and Joanna's userIds:
// ["[email protected]", "[email protected]"]

// const userIds = await __fetchAllUserIdsFromDB__(roomId);
//
// Return all userIds if no `text`
// if (!text) {
// return userIds;
// }
//
// Otherwise, filter userIds for the search `text` and return
// return userIds.filter((userId) =>
// userId.toLowerCase().includes(text.toLowerCase())
// );

return [];
},
});
} = createRoomContext<Presence, Storage, UserMeta, RoomEvent, ThreadMetadata>(
client
);
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"lint": "next lint"
},
"dependencies": {
"@liveblocks/client": "^1.9.7",
"@liveblocks/react": "^1.9.7",
"@liveblocks/react-comments": "^1.9.7",
"@liveblocks/client": "^1.11.0",
"@liveblocks/node": "^1.11.0",
"@liveblocks/react": "^1.11.0",
"@liveblocks/react-comments": "^1.11.0",
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-context-menu": "^2.1.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
Expand Down
Loading