Skip to content

Commit

Permalink
fix liveblocks:comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hotlong committed Dec 14, 2024
1 parent 04f8ccc commit 624ae30
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
12 changes: 12 additions & 0 deletions packages/@steedos-widgets/liveblocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ yarn dev

```

集成到Steedos记录详情页

```json
{
"type": "rooms-comments",
"className": "flex flex-col m-3 gap-3",
"id": "u:bbb9a7d94945",
"roomId": "objects:${objectName}:{recordId}",
"baseUrl": "${context.rootUrl}"
}
```


## Steedos 加载资产包

Expand Down
12 changes: 7 additions & 5 deletions packages/@steedos-widgets/liveblocks/src/components/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export const AmisComments = (props: any) => {
const [config, setConfig] = useState(configJSON);
const [token, setToken] = useState(null);

const fixedBaseUrl = baseUrl || amisData.context?.rootUrl || `${window.location.protocol}//${window.location.host}`
console.log('liveblocks baseUrl:', fixedBaseUrl);

let onDataFilter = null;

if (typeof dataFilter === 'string') {

onDataFilter = new Function('config', 'data', 'return (async () => { ' + dataFilter + ' })()')
}

Expand All @@ -69,9 +71,9 @@ export const AmisComments = (props: any) => {
return (
<LiveblocksProvider
//@ts-ignore
baseUrl={baseUrl}
baseUrl={fixedBaseUrl}
authEndpoint={async (room) => {
const authEndpoint = `${baseUrl}/v2/c/auth`;
const authEndpoint = `${fixedBaseUrl}/v2/c/auth`;
const headers = {
"Content-Type": "application/json",
};
Expand All @@ -96,7 +98,7 @@ export const AmisComments = (props: any) => {
const searchParams = new URLSearchParams(
userIds.map((userId) => ["userIds", userId])
);
const response = await fetch(`${baseUrl}/v2/c/users?${searchParams}`, {
const response = await fetch(`${fixedBaseUrl}/v2/c/users?${searchParams}`, {
headers: {
"Authorization": `Bearer ${token}`
}
Expand All @@ -114,7 +116,7 @@ export const AmisComments = (props: any) => {
// Find a list of users that match the current search term
resolveMentionSuggestions={async ({ text = "" }) => {
const response = await fetch(
`${baseUrl}/v2/c/users/search?keyword=${encodeURIComponent(text)}`, {
`${fixedBaseUrl}/v2/c/users/search?keyword=${encodeURIComponent(text)}`, {
headers: {
"Authorization": `Bearer ${token}`
}
Expand Down
12 changes: 12 additions & 0 deletions packages/@steedos-widgets/liveblocks/src/metas/Comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ export default {
},
panelTitle: "设置",
panelControls: [
{
type: "text",
name: "baseUrl",
label: "Base URL",
value: "m-2 flex flex-col gap-y-2"
},
{
type: "text",
name: "roomId",
label: "Room Id",
value: "m-2 flex flex-col gap-y-2"
},
{
type: "text",
name: "className",
Expand Down

0 comments on commit 624ae30

Please sign in to comment.