Updated Comments UI to use new endpoint

refs https://linear.app/tryghost/issue/ENG-676/

Now we have the case that there is no filter param, the simple string
approach fails. Instead we build up a URLSearchParams object which
makes it easier to handle conditional params & stringify it at the end.
This commit is contained in:
Fabien O'Carroll 2024-02-27 19:28:40 -05:00 committed by Fabien 'egg' O'Carroll
parent 2c6321472c
commit a291914fc4
2 changed files with 27 additions and 24 deletions

View File

@ -122,17 +122,22 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}: {site
return json;
},
browse({page, postId}: {page: number, postId: string}) {
let filterString = `post_id:'${postId}'`;
let filter = null;
if (firstCommentCreatedAt) {
filterString += `+created_at:<=${firstCommentCreatedAt}`;
filter = `created_at:<=${firstCommentCreatedAt}`;
}
const filter = encodeURIComponent(filterString);
const order = encodeURIComponent('created_at DESC, id DESC');
const order = 'created_at DESC, id DESC';
const url = endpointFor({type: 'members', resource: 'comments', params: `?limit=5&order=${order}&filter=${filter}&page=${page}`});
const params = new URLSearchParams();
params.set('limit', '5');
params.set('order', order);
if (filter) {
params.set('filter', filter);
}
params.set('page', page.toString());
const url = endpointFor({type: 'members', resource: `comments/post/${postId}`, params: `?${params.toString()}`});
const response = makeRequest({
url,
method: 'GET',

View File

@ -166,7 +166,6 @@ export class MockedApi {
});
await page.route(`${path}/members/api/comments/*`, async (route) => {
if (route.request().method() === 'POST') {
const payload = JSON.parse(route.request().postData());
this.#lastCommentDate = new Date();
@ -182,13 +181,13 @@ export class MockedApi {
]
})
});
}
});
await page.route(`${path}/members/api/comments/post/*/*`, async (route) => {
const url = new URL(route.request().url());
const p = parseInt(url.searchParams.get('page') ?? '1');
const limit = parseInt(url.searchParams.get('limit') ?? '5');
const order = url.searchParams.get('order') ?? '';
const filter = url.searchParams.get('filter') ?? '';
await route.fulfill({
@ -196,7 +195,6 @@ export class MockedApi {
body: JSON.stringify(this.browseComments({
page: p,
limit,
order,
filter
}))
});