+
+
+ { __( 'You have', 'farcaster-wp' ) }{ ' ' }
+ { subscriptions?.length }{ ' ' }
+ { __( 'subscriptions on your site:', 'farcaster-wp' ) }
+
+
+
+
{ JSON.stringify( subscriptions, null, 2 ) }
+
+ );
+};
diff --git a/src/hooks/use-subscriptions.ts b/src/hooks/use-subscriptions.ts
new file mode 100644
index 0000000..74b2f5f
--- /dev/null
+++ b/src/hooks/use-subscriptions.ts
@@ -0,0 +1,24 @@
+import apiFetch from '@wordpress/api-fetch';
+import { useCallback, useEffect, useState } from '@wordpress/element';
+import { Subscriptions } from '../utils/subscriptions';
+
+export const useSubscriptions = () => {
+ const [ subscriptions, setSubscriptions ] = useState< Subscriptions >();
+
+ const fetchSubscriptions = useCallback( () => {
+ apiFetch< Subscriptions >( {
+ path: '/farcaster-wp/v1/subscriptions',
+ } ).then( ( fetchedSubscriptions ) => {
+ setSubscriptions( fetchedSubscriptions );
+ } );
+ }, [] );
+
+ useEffect( () => {
+ fetchSubscriptions();
+ }, [ fetchSubscriptions ] );
+
+ return {
+ subscriptions,
+ fetchSubscriptions,
+ };
+};
diff --git a/src/utils/subscriptions.ts b/src/utils/subscriptions.ts
new file mode 100644
index 0000000..f4f79b3
--- /dev/null
+++ b/src/utils/subscriptions.ts
@@ -0,0 +1,7 @@
+export type Subscription = {
+ fid: number;
+ token: string;
+ url: string;
+};
+
+export type Subscriptions = Subscription[];