@szymonpiatek/nextwordpress 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1349,6 +1349,76 @@ function useGQLPostBySlug(config, slug, swrOptions) {
1349
1349
  );
1350
1350
  }
1351
1351
 
1352
+ // src/integrations/restApi/wpulike/queries.ts
1353
+ function createWPULikeQueries(fetcher) {
1354
+ const { wpFetch, wpMutate } = fetcher;
1355
+ async function getLikeStats(params, tags) {
1356
+ return wpFetch(
1357
+ "/wp-json/wp-ulike/v1/stats",
1358
+ params,
1359
+ tags ?? ["wpulike", `wpulike-${params.id}`]
1360
+ );
1361
+ }
1362
+ async function checkLikeStatus(params, tags) {
1363
+ return wpFetch(
1364
+ "/wp-json/wp-ulike/v1/check",
1365
+ params,
1366
+ tags ?? ["wpulike", `wpulike-${params.id}`]
1367
+ );
1368
+ }
1369
+ async function vote(params, authToken) {
1370
+ return wpMutate(
1371
+ "/wp-json/wp-ulike/v1/vote",
1372
+ params,
1373
+ "POST",
1374
+ authToken
1375
+ );
1376
+ }
1377
+ return { getLikeStats, checkLikeStatus, vote };
1378
+ }
1379
+
1380
+ // src/hooks/wpulike/useWPULike.ts
1381
+ function useWPULikeStats(config, params, swrOptions) {
1382
+ const key = params ? ["wpulike-stats", config.clientURL, params.id, params.type ?? "post"] : null;
1383
+ return useSWR2__default.default(
1384
+ key,
1385
+ () => {
1386
+ const fetcher = createFetcher(config);
1387
+ return createWPULikeQueries(fetcher).getLikeStats(params);
1388
+ },
1389
+ swrOptions
1390
+ );
1391
+ }
1392
+ function useWPULikeCheck(config, params, swrOptions) {
1393
+ const key = params ? ["wpulike-check", config.clientURL, params.id, params.type ?? "post"] : null;
1394
+ return useSWR2__default.default(
1395
+ key,
1396
+ () => {
1397
+ const fetcher = createFetcher(config);
1398
+ return createWPULikeQueries(fetcher).checkLikeStatus(params);
1399
+ },
1400
+ swrOptions
1401
+ );
1402
+ }
1403
+ function useWPULike(config, params, swrOptions) {
1404
+ const key = params ? ["wpulike-stats", config.clientURL, params.id, params.type ?? "post"] : null;
1405
+ const { data, error, isLoading, mutate } = useSWR2__default.default(
1406
+ key,
1407
+ () => {
1408
+ const fetcher = createFetcher(config);
1409
+ return createWPULikeQueries(fetcher).getLikeStats(params);
1410
+ },
1411
+ swrOptions
1412
+ );
1413
+ async function vote(status, authToken) {
1414
+ const fetcher = createFetcher(config);
1415
+ const result = await createWPULikeQueries(fetcher).vote({ ...params, status }, authToken);
1416
+ await mutate();
1417
+ return result;
1418
+ }
1419
+ return { data, error, isLoading, vote };
1420
+ }
1421
+
1352
1422
  exports.AuthProvider = AuthProvider;
1353
1423
  exports.CartProvider = CartProvider;
1354
1424
  exports.WooCommerceCustomerProvider = WooCommerceCustomerProvider;
@@ -1368,5 +1438,8 @@ exports.useProductBySlug = useProductBySlug;
1368
1438
  exports.useProducts = useProducts;
1369
1439
  exports.useProductsPaginated = useProductsPaginated;
1370
1440
  exports.useWPGraphQL = useWPGraphQL;
1441
+ exports.useWPULike = useWPULike;
1442
+ exports.useWPULikeCheck = useWPULikeCheck;
1443
+ exports.useWPULikeStats = useWPULikeStats;
1371
1444
  //# sourceMappingURL=index.cjs.map
1372
1445
  //# sourceMappingURL=index.cjs.map