-
-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <[email protected]>
- Loading branch information
Showing
8 changed files
with
126 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getCurrentNoteData } from '~/providers/note/CurrentNoteDataProvider' | ||
import { getGlobalCurrentPostData } from '~/providers/post/CurrentPostDataProvider' | ||
|
||
import { isServerSide } from './env' | ||
|
||
export const getCurrentPageId = () => { | ||
if (isServerSide) return | ||
const pathname = window.location.pathname | ||
|
||
if (pathname.startsWith('/notes/')) { | ||
const noteId = getCurrentNoteData() | ||
|
||
return noteId?.data.id | ||
} | ||
|
||
if (pathname.startsWith('/posts/')) { | ||
return getGlobalCurrentPostData().id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const buildCommentsQueryKey = (refId: string) => ['comments', refId] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './comment' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { BusinessEvents } from '@mx-space/webhook' | ||
|
||
export const buildSocketEventType = (type: string) => | ||
`ws_event:${type}` as const | ||
|
||
export class WsEvent extends Event { | ||
constructor( | ||
type: BusinessEvents, | ||
public data: unknown, | ||
) { | ||
super(buildSocketEventType(type)) | ||
} | ||
|
||
static on( | ||
type: BusinessEvents, | ||
|
||
cb: (data: unknown) => void, | ||
) { | ||
const _cb = (e: any) => { | ||
cb(e.data) | ||
} | ||
document.addEventListener(buildSocketEventType(type), _cb) | ||
|
||
return () => { | ||
document.removeEventListener(buildSocketEventType(type), _cb) | ||
} | ||
} | ||
|
||
static emit(type: BusinessEvents, data: unknown) { | ||
document.dispatchEvent(new WsEvent(type, data)) | ||
} | ||
} |