PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.1
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.1
1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / frontend / vue / data / repositories / pagesRepo.ts
hostinger-reach / frontend / vue / data / repositories Last commit date
amplitudeRepo.ts 3 months ago formsRepo.ts 6 months ago hostingRepo.ts 3 months ago index.ts 3 months ago pagesRepo.ts 10 months ago reachRepo.ts 1 month ago
pagesRepo.ts
88 lines
1 import { decode } from 'html-entities';
2
3 import { useGeneralDataStore } from '@/stores/generalDataStore';
4 import { Header } from '@/types/enums';
5 import type { AuthorizeRequestHeaders } from '@/types/models/httpModels';
6 import type { Page, WordPressPagesList } from '@/types/models/pagesModels';
7 import { generateCorrelationId } from '@/utils/helpers';
8 import httpService from '@/utils/services/httpService';
9
10 const URL = `${hostinger_reach_reach_data.rest_base_url}wp/v2`;
11
12 export interface PaginationParams {
13 page?: number;
14 perPage?: number;
15 }
16
17 export interface PaginatedResponse<T> {
18 data: T;
19 pagination: {
20 currentPage: number;
21 totalPages: number;
22 totalItems: number;
23 perPage: number;
24 };
25 }
26
27 export const pagesRepo = {
28 getPagesWithSubscriptionBlock: (paginationParams?: PaginationParams, headers?: AuthorizeRequestHeaders) => {
29 const { nonce, totalFormPages } = useGeneralDataStore();
30 const page = paginationParams?.page || 1;
31 const perPage = paginationParams?.perPage || 5;
32 const totalItems = totalFormPages || 0;
33 const totalPages = Math.ceil(totalItems / perPage);
34
35 const params = new URLSearchParams();
36 params.append('hostinger_reach_page_query', '1');
37 params.append('page', page.toString());
38 params.append('per_page', perPage.toString());
39
40 const config = {
41 headers: {
42 [Header.CORRELATION_ID]: headers?.[Header.CORRELATION_ID] || generateCorrelationId(),
43 [Header.WP_NONCE]: nonce
44 }
45 };
46
47 return httpService.get<WordPressPagesList>(`${URL}/pages?${params.toString()}`, config).then(([data, error]) => {
48 if (error) {
49 return [null, error];
50 }
51
52 const pages =
53 data?.map((page) => {
54 let pageUrl = `/wp-admin/post.php?post=${page.id}`;
55
56 if (!page.HostingerReachPluginHasSubscriptionBlock) {
57 pageUrl = `${pageUrl}&hostinger_reach_add_block=1`;
58 }
59
60 if (page.HostingerReachPluginIsElementor) {
61 pageUrl = `${pageUrl}&action=elementor`;
62 } else {
63 pageUrl = `${pageUrl}&action=edit`;
64 }
65
66 return {
67 id: page.id.toString(),
68 name: decode(page.title.rendered),
69 link: pageUrl,
70 isAdded: page.HostingerReachPluginHasSubscriptionBlock ?? false
71 };
72 }) || [];
73
74 const paginatedResponse: PaginatedResponse<Page[]> = {
75 data: pages,
76 pagination: {
77 currentPage: page,
78 totalPages,
79 totalItems,
80 perPage
81 }
82 };
83
84 return [paginatedResponse, null];
85 });
86 }
87 };
88