|
|
import { get } from 'lodash'; |
|
|
import { addQueryArgs } from 'calypso/lib/route'; |
|
|
import { getEditedPost } from 'calypso/state/posts/selectors'; |
|
|
import getEditorUrl from 'calypso/state/selectors/get-editor-url'; |
|
|
import { getSiteSlug } from 'calypso/state/sites/selectors'; |
|
|
import type { AppState } from 'calypso/types'; |
|
|
|
|
|
import 'calypso/state/editor/init'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function getEditorPostId( state: AppState ): number | undefined { |
|
|
return state.editor.postId; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function getEditorDuplicatePostPath( |
|
|
state: AppState, |
|
|
siteId: number, |
|
|
postId: number, |
|
|
type = 'post' |
|
|
): string { |
|
|
return addQueryArgs( |
|
|
{ |
|
|
'jetpack-copy': postId, |
|
|
}, |
|
|
getEditorUrl( state, siteId, null, type ) |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function getEditorNewPostPath( state: AppState, siteId: number, type = 'post' ): string { |
|
|
let path; |
|
|
switch ( type ) { |
|
|
case 'post': |
|
|
path = '/post'; |
|
|
break; |
|
|
case 'page': |
|
|
path = '/page'; |
|
|
break; |
|
|
default: |
|
|
path = `/edit/${ type }`; |
|
|
break; |
|
|
} |
|
|
|
|
|
const siteSlug = getSiteSlug( state, siteId ); |
|
|
if ( siteSlug ) { |
|
|
path += `/${ siteSlug }`; |
|
|
} else { |
|
|
path += `/${ siteId }`; |
|
|
} |
|
|
|
|
|
return path; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function getEditorPath( |
|
|
state: AppState, |
|
|
siteId: number, |
|
|
postId: number | string, |
|
|
defaultType = 'post' |
|
|
): string { |
|
|
if ( ! siteId ) { |
|
|
return 'post'; |
|
|
} |
|
|
const editedPost = getEditedPost( state, siteId, postId ); |
|
|
const type = get( editedPost, 'type', defaultType ); |
|
|
let path = getEditorNewPostPath( state, siteId, type ); |
|
|
|
|
|
if ( postId ) { |
|
|
path += `/${ postId }`; |
|
|
} |
|
|
|
|
|
return path; |
|
|
} |
|
|
|