2024-09-17 16:01:16 +02:00
|
|
|
import { Client } from "@notionhq/client";
|
2024-09-05 09:23:27 +02:00
|
|
|
import {
|
|
|
|
StatGroupDesc,
|
|
|
|
StatsType,
|
2024-09-17 13:54:59 +02:00
|
|
|
} from "../../../statistiques/v2/desc/StatsDesc";
|
2024-09-17 16:01:16 +02:00
|
|
|
import { createStatGroupChildrenListItemBlock } from "./createStatGroupListItemBlock";
|
|
|
|
import { updatePageContent } from "./updatePageContent";
|
|
|
|
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
|
2024-09-05 09:23:27 +02:00
|
|
|
|
|
|
|
export async function publishStatsToPage<D extends StatGroupDesc>(
|
|
|
|
notionClient: Client,
|
|
|
|
statsPageId: string,
|
2024-09-17 16:01:16 +02:00
|
|
|
pageHeader: string,
|
2024-09-05 09:23:27 +02:00
|
|
|
descriptor: D,
|
|
|
|
stats: StatsType<D>
|
|
|
|
) {
|
2024-09-17 16:01:16 +02:00
|
|
|
const statsBlocks = createStatGroupChildrenListItemBlock(descriptor, stats);
|
2024-09-05 09:23:27 +02:00
|
|
|
|
2024-09-17 16:01:16 +02:00
|
|
|
const textBlock = createParagraphBlock(pageHeader);
|
|
|
|
await updatePageContent(notionClient, statsPageId, [
|
|
|
|
textBlock,
|
|
|
|
...statsBlocks,
|
|
|
|
]);
|
2024-09-05 09:23:27 +02:00
|
|
|
}
|
|
|
|
|
2024-09-17 16:01:16 +02:00
|
|
|
type ParagraphBlockObjectRequest = Extract<
|
2024-09-05 09:23:27 +02:00
|
|
|
BlockObjectRequest,
|
2024-09-17 16:01:16 +02:00
|
|
|
{ paragraph: unknown }
|
2024-09-05 09:23:27 +02:00
|
|
|
>;
|
|
|
|
|
2024-09-17 16:01:16 +02:00
|
|
|
function createParagraphBlock(content: string): ParagraphBlockObjectRequest {
|
2024-09-05 09:23:27 +02:00
|
|
|
return {
|
2024-09-17 16:01:16 +02:00
|
|
|
paragraph: {
|
2024-09-05 09:23:27 +02:00
|
|
|
rich_text: [
|
|
|
|
{
|
|
|
|
text: {
|
2024-09-17 16:01:16 +02:00
|
|
|
content: content,
|
2024-09-05 09:23:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|