File size: 1,920 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import page from '@automattic/calypso-router';
import { addQueryArgs } from '@wordpress/url';
import { makeLayout, render as clientRender, redirectIfDuplicatedView } from 'calypso/controller';
import { siteSelection, navigation, sites } from 'calypso/my-sites/controller';
import { clearCommentNotices, comment, postComments, redirect, siteComments } from './controller';

const redirectToCommentIfDuplicatedView = ( url ) => ( context, next ) => {
	if ( context.params.status !== 'all' ) {
		url = addQueryArgs( url, {
			comment_status: context.params.status === 'pending' ? 'moderated' : context.params.status,
		} );
	}

	if ( context.params.comment ) {
		url = addQueryArgs( url, { c: context.params.comment } );
	}

	redirectIfDuplicatedView( url )( context, next );
};

export default function () {
	// Site View
	page(
		'/comments/:status(all|pending|approved|spam|trash)/:site',
		siteSelection,
		redirectToCommentIfDuplicatedView( 'edit-comments.php' ),
		navigation,
		siteComments,
		makeLayout,
		clientRender
	);

	// Post View
	page(
		'/comments/:status(all|pending|approved|spam|trash)/:site/:post',
		siteSelection,
		redirectToCommentIfDuplicatedView( 'edit-comments.php' ),
		navigation,
		postComments,
		makeLayout,
		clientRender
	);

	// Comment View
	page(
		'/comment/:site/:comment',
		siteSelection,
		redirectToCommentIfDuplicatedView( 'comment.php?action=editcomment' ),
		navigation,
		comment,
		makeLayout,
		clientRender
	);

	// Redirect
	page(
		'/comments/:status(all|pending|approved|spam|trash)',
		siteSelection,
		sites,
		makeLayout,
		clientRender
	);
	page( '/comments/*', siteSelection, redirect );
	page( '/comments', siteSelection, redirect );
	page( '/comment/*', siteSelection, redirect );
	page( '/comment', siteSelection, redirect );

	// Leaving Comment Management
	page.exit( '/comments/*', clearCommentNotices );
	page.exit( '/comment/*', clearCommentNotices );
}