import { parseQuery , stringifyQuery } from "coral-common/utils" ; import { buildURL } from "coral-framework/utils" ; import { Decorator } from "./types" ; function getCurrentCommentID ( ) { return parseQuery ( location . search ) . commentID ; } const withSetCommentID = ( pym ) => { pym . onMessage ( "setCommentID" , ( id ) => { const search = stringifyQuery ( { ... parseQuery ( location . search ) , commentID : id || undefined , } ) ; const url = buildURL ( { search } ) ; window . history . pushState ( { } , document . title , url ) ; } ) ; const sendSetCommentID = ( e ) => { const commentID = getCurrentCommentID ( ) ; pym . sendMessage ( "setCommentID" , commentID || "" ) ; } ; window . addEventListener ( "popstate" , sendSetCommentID ) ; return ( ) => { window . removeEventListener ( "popstate" , sendSetCommentID ) ; } ; } ; export default withSetCommentID ;