From adf4f6165859c3a50a771c781c25a652a21d75bb Mon Sep 17 00:00:00 2001 From: Kris Urbas <605420+krzysu@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:57:05 +0200 Subject: [PATCH 1/2] react: useAddProfileInterests and useRemoveProfileInterests --- .changeset/quick-onions-guess.md | 8 ++ examples/web/src/App.tsx | 2 + examples/web/src/profiles/ProfilesPage.tsx | 5 + .../web/src/profiles/UseProfileInterests.tsx | 122 ++++++++++++++++++ examples/web/src/profiles/index.ts | 1 + .../profile/ManageProfileInterests.ts | 32 +++++ .../domain/src/use-cases/profile/index.ts | 1 + .../adapters/ProfileInterestsGateway.ts | 43 ++++++ .../adapters/ProfileInterestsPresenter.ts | 29 +++++ .../adapters/useProfileInterestsController.ts | 30 +++++ packages/react/src/profile/index.ts | 2 + .../src/profile/useAddProfileInterests.ts | 61 +++++++++ .../src/profile/useRemoveProfileInterests.ts | 65 ++++++++++ 13 files changed, 401 insertions(+) create mode 100644 .changeset/quick-onions-guess.md create mode 100644 examples/web/src/profiles/UseProfileInterests.tsx create mode 100644 packages/domain/src/use-cases/profile/ManageProfileInterests.ts create mode 100644 packages/react/src/profile/adapters/ProfileInterestsGateway.ts create mode 100644 packages/react/src/profile/adapters/ProfileInterestsPresenter.ts create mode 100644 packages/react/src/profile/adapters/useProfileInterestsController.ts create mode 100644 packages/react/src/profile/useAddProfileInterests.ts create mode 100644 packages/react/src/profile/useRemoveProfileInterests.ts diff --git a/.changeset/quick-onions-guess.md b/.changeset/quick-onions-guess.md new file mode 100644 index 000000000..f03afbb2a --- /dev/null +++ b/.changeset/quick-onions-guess.md @@ -0,0 +1,8 @@ +--- +"@lens-protocol/domain": minor +"@lens-protocol/react": minor +"@lens-protocol/react-native": minor +"@lens-protocol/react-web": minor +--- + +**feat:** added hooks to manage profile interests: useAddProfileInterests and useRemoveProfileInterests diff --git a/examples/web/src/App.tsx b/examples/web/src/App.tsx index e46ca615d..d3c5afd7d 100644 --- a/examples/web/src/App.tsx +++ b/examples/web/src/App.tsx @@ -51,6 +51,7 @@ import { UseProfileActionHistory, UseProfileFollowers, UseProfileFollowing, + UseProfileInterests, UseProfileManagers, UseProfiles, UseRecommendProfileToggle, @@ -151,6 +152,7 @@ export function App() { } /> } /> } /> + } /> diff --git a/examples/web/src/profiles/ProfilesPage.tsx b/examples/web/src/profiles/ProfilesPage.tsx index d89f75f7a..1fd499ff3 100644 --- a/examples/web/src/profiles/ProfilesPage.tsx +++ b/examples/web/src/profiles/ProfilesPage.tsx @@ -96,6 +96,11 @@ const profileHooks = [ description: 'Recommend a profile.', path: '/profiles/useRecommendProfileToggle', }, + { + label: 'useProfileInterests', + description: 'Add and remove profile interests.', + path: '/profiles/useProfileInterests', + }, ]; export function ProfilesPage() { diff --git a/examples/web/src/profiles/UseProfileInterests.tsx b/examples/web/src/profiles/UseProfileInterests.tsx new file mode 100644 index 000000000..38e7b1787 --- /dev/null +++ b/examples/web/src/profiles/UseProfileInterests.tsx @@ -0,0 +1,122 @@ +import { + useAddProfileInterests, + useRemoveProfileInterests, + ProfileInterestTypes, + Profile, +} from '@lens-protocol/react-web'; +import { Fragment, useMemo } from 'react'; + +import { RequireProfileSession } from '../components/auth'; + +// Capitalizes each word in a string +function capitalize(label: string): string { + return label.toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase()); +} + +type Interest = { + parent: string; + value: ProfileInterestTypes; + label: string; +}; + +// Processes raw interest types into structured interests array +function createInterests(categories: ProfileInterestTypes[]): Interest[] { + return categories.map((item) => { + const [parent, subcategory] = item.split('__'); + const label = capitalize( + subcategory ? subcategory.replace(/_/g, ' ') : parent.replace(/_/g, ' '), + ); + return { parent, value: item, label }; + }); +} + +type ButtonProps = { + isActive: boolean; + onClick: () => void; + children: React.ReactNode; +}; + +function ToggleButton({ isActive, onClick, children }: ButtonProps) { + const normalStyle = { + backgroundColor: 'transparent', + border: '1px solid grey', + color: '#111', + outline: 'none', + }; + + const activeStyle = { + ...normalStyle, + backgroundColor: '#333', + color: '#eee', + }; + + return ( + + ); +} + +function UseProfileInterestsInner({ profile }: { profile: Profile }) { + const { execute: addInterests } = useAddProfileInterests(); + const { execute: removeInterests } = useRemoveProfileInterests(); + + const groupedInterests = useMemo(() => { + const interests = createInterests(Object.values(ProfileInterestTypes)); + + // Group interests by category + return interests.reduce((acc, interest) => { + acc[interest.parent] = acc[interest.parent] || []; + acc[interest.parent].push(interest); + return acc; + }, {} as Record); + }, []); + + const handleClick = async (interest: ProfileInterestTypes) => { + const request = { + interests: [interest], + }; + + if (profile.interests.includes(interest)) { + await removeInterests(request); + } else { + await addInterests(request); + } + }; + + return ( +
+ {Object.entries(groupedInterests).map(([category, items]) => ( +
+

{capitalize(category.replace(/_/g, ' '))}

+
+ {items.map((item) => ( + + handleClick(item.value)} + isActive={profile.interests.includes(item.value)} + > + {item.label} + {' '} + + ))} +
+
+ ))} +
+ ); +} + +export function UseProfileInterests() { + return ( +
+

+ useAddProfileInterests & useRemoveProfileInterests +

+ + + {({ profile }) => } + +
+ ); +} diff --git a/examples/web/src/profiles/index.ts b/examples/web/src/profiles/index.ts index 315246fd1..999f42aca 100644 --- a/examples/web/src/profiles/index.ts +++ b/examples/web/src/profiles/index.ts @@ -10,6 +10,7 @@ export * from './UseProfile'; export * from './UseProfileActionHistory'; export * from './UseProfileFollowers'; export * from './UseProfileFollowing'; +export * from './UseProfileInterests'; export * from './UseProfileManagers'; export * from './UseProfiles'; export * from './UseRecommendProfileToggle'; diff --git a/packages/domain/src/use-cases/profile/ManageProfileInterests.ts b/packages/domain/src/use-cases/profile/ManageProfileInterests.ts new file mode 100644 index 000000000..93ce9e9a0 --- /dev/null +++ b/packages/domain/src/use-cases/profile/ManageProfileInterests.ts @@ -0,0 +1,32 @@ +import { ProfileId } from '../../entities'; + +export type ProfileInterestsRequest = { + profileId: ProfileId; +}; + +export interface IProfileInterestsGateway { + add(request: ProfileInterestsRequest): Promise; + remove(request: ProfileInterestsRequest): Promise; +} + +export interface IProfileInterestsPresenter { + add(request: ProfileInterestsRequest): Promise; + remove(request: ProfileInterestsRequest): Promise; +} + +export class ManageProfileInterests { + constructor( + private readonly gateway: IProfileInterestsGateway, + private readonly presenter: IProfileInterestsPresenter, + ) {} + + async add(request: ProfileInterestsRequest) { + void this.gateway.add(request); + await this.presenter.add(request); + } + + async remove(request: ProfileInterestsRequest) { + void this.gateway.remove(request); + await this.presenter.remove(request); + } +} diff --git a/packages/domain/src/use-cases/profile/index.ts b/packages/domain/src/use-cases/profile/index.ts index 50a870255..1c3156114 100644 --- a/packages/domain/src/use-cases/profile/index.ts +++ b/packages/domain/src/use-cases/profile/index.ts @@ -5,6 +5,7 @@ export * from './DismissRecommendedProfiles'; export * from './FollowPolicy'; export * from './FollowProfile'; export * from './LinkHandle'; +export * from './ManageProfileInterests'; export * from './ReportProfile'; export * from './SetProfileMetadata'; export * from './ToggleProfileProperty'; diff --git a/packages/react/src/profile/adapters/ProfileInterestsGateway.ts b/packages/react/src/profile/adapters/ProfileInterestsGateway.ts new file mode 100644 index 000000000..aa710c73d --- /dev/null +++ b/packages/react/src/profile/adapters/ProfileInterestsGateway.ts @@ -0,0 +1,43 @@ +import { + AddProfileInterestsData, + AddProfileInterestsDocument, + AddProfileInterestsVariables, + ProfileInterestTypes, + RemoveProfileInterestsData, + RemoveProfileInterestsDocument, + RemoveProfileInterestsVariables, + SafeApolloClient, +} from '@lens-protocol/api-bindings'; +import { ProfileId } from '@lens-protocol/domain/entities'; +import { IProfileInterestsGateway } from '@lens-protocol/domain/use-cases/profile'; + +export type ProfileInterestsRequest = { + profileId: ProfileId; + interests: ProfileInterestTypes[]; +}; + +export class ProfileInterestsGateway implements IProfileInterestsGateway { + constructor(private apolloClient: SafeApolloClient) {} + + async add(request: ProfileInterestsRequest) { + await this.apolloClient.mutate({ + mutation: AddProfileInterestsDocument, + variables: { + request: { + interests: request.interests, + }, + }, + }); + } + + async remove(request: ProfileInterestsRequest) { + await this.apolloClient.mutate({ + mutation: RemoveProfileInterestsDocument, + variables: { + request: { + interests: request.interests, + }, + }, + }); + } +} diff --git a/packages/react/src/profile/adapters/ProfileInterestsPresenter.ts b/packages/react/src/profile/adapters/ProfileInterestsPresenter.ts new file mode 100644 index 000000000..f0a0b7406 --- /dev/null +++ b/packages/react/src/profile/adapters/ProfileInterestsPresenter.ts @@ -0,0 +1,29 @@ +import { ProfileInterestTypes } from '@lens-protocol/api-bindings'; +import { IProfileInterestsPresenter } from '@lens-protocol/domain/use-cases/profile'; + +import { IProfileCacheManager } from './IProfileCacheManager'; +import { ProfileInterestsRequest } from './ProfileInterestsGateway'; + +export class ProfileInterestsPresenter implements IProfileInterestsPresenter { + constructor(private readonly profileCacheManager: IProfileCacheManager) {} + + async add(request: ProfileInterestsRequest) { + this.profileCacheManager.update(request.profileId, (current) => { + return { + ...current, + interests: [...current.interests, ...request.interests], + }; + }); + } + + async remove(request: ProfileInterestsRequest) { + this.profileCacheManager.update(request.profileId, (current) => { + return { + ...current, + interests: current.interests.filter( + (interest) => !request.interests.includes(interest as ProfileInterestTypes), + ), + }; + }); + } +} diff --git a/packages/react/src/profile/adapters/useProfileInterestsController.ts b/packages/react/src/profile/adapters/useProfileInterestsController.ts new file mode 100644 index 000000000..a8b92122d --- /dev/null +++ b/packages/react/src/profile/adapters/useProfileInterestsController.ts @@ -0,0 +1,30 @@ +import { ManageProfileInterests } from '@lens-protocol/domain/use-cases/profile'; + +import { useSharedDependencies } from '../../shared'; +import { ProfileInterestsGateway, ProfileInterestsRequest } from './ProfileInterestsGateway'; +import { ProfileInterestsPresenter } from './ProfileInterestsPresenter'; + +export function useProfileInterestsController() { + const { apolloClient, profileCacheManager } = useSharedDependencies(); + + const add = async (request: ProfileInterestsRequest) => { + const presenter = new ProfileInterestsPresenter(profileCacheManager); + const gateway = new ProfileInterestsGateway(apolloClient); + const manageInterests = new ManageProfileInterests(gateway, presenter); + + await manageInterests.add(request); + }; + + const remove = async (request: ProfileInterestsRequest) => { + const presenter = new ProfileInterestsPresenter(profileCacheManager); + const gateway = new ProfileInterestsGateway(apolloClient); + const manageInterests = new ManageProfileInterests(gateway, presenter); + + await manageInterests.remove(request); + }; + + return { + add, + remove, + }; +} diff --git a/packages/react/src/profile/index.ts b/packages/react/src/profile/index.ts index d5d0ebb4e..ae06b6d71 100644 --- a/packages/react/src/profile/index.ts +++ b/packages/react/src/profile/index.ts @@ -1,6 +1,7 @@ /** * Hooks */ +export * from './useAddProfileInterests'; export * from './useBlockedProfiles'; export * from './useLazyProfile'; export * from './useLazyProfiles'; @@ -12,6 +13,7 @@ export * from './useProfileFollowing'; export * from './useProfileManagers'; export * from './useProfiles'; export * from './useRecommendProfileToggle'; +export * from './useRemoveProfileInterests'; export * from './useReportProfile'; export * from './useWhoActedOnPublication'; diff --git a/packages/react/src/profile/useAddProfileInterests.ts b/packages/react/src/profile/useAddProfileInterests.ts new file mode 100644 index 000000000..d8649e19f --- /dev/null +++ b/packages/react/src/profile/useAddProfileInterests.ts @@ -0,0 +1,61 @@ +import { ProfileInterestTypes } from '@lens-protocol/api-bindings'; +import { invariant, success } from '@lens-protocol/shared-kernel'; + +import { SessionType, useSession } from '../authentication'; +import { UseDeferredTask, useDeferredTask } from '../helpers/tasks'; +import { useProfileInterestsController } from './adapters/useProfileInterestsController'; + +export { ProfileInterestTypes }; + +export type AddProfileInterestsArgs = { + interests: ProfileInterestTypes[]; +}; + +/** + * Add profile interests. + * + * You MUST be authenticated via {@link useLogin} to use this hook. + * + * @example + * ```tsx + * function ProfileInterests({ profile }: { profile: Profile }) { + * const { execute: addInterests } = useAddProfileInterests(); + * const { execute: removeInterests } = useRemoveProfileInterests(); + * + * const handleClick = async (interest: ProfileInterestTypes) => { + * const request = { + * interests: [interest], + * }; + * + * if (profile.interests.includes(interest)) { + * await removeInterests(request); + * } else { + * await addInterests(request); + * } + * }; + * + * return ; + * } + * ``` + * + * @category Profiles + * @group Hooks + */ +export function useAddProfileInterests(): UseDeferredTask { + const { data: session } = useSession(); + const { add } = useProfileInterestsController(); + + return useDeferredTask(async (request) => { + invariant( + session?.type === SessionType.WithProfile, + 'You must be authenticated with a profile to use this hook. Use `useLogin` hook to authenticate.', + ); + + await add({ + profileId: session.profile.id, + interests: request.interests, + }); + + return success(); + }); +} diff --git a/packages/react/src/profile/useRemoveProfileInterests.ts b/packages/react/src/profile/useRemoveProfileInterests.ts new file mode 100644 index 000000000..6fcc6e686 --- /dev/null +++ b/packages/react/src/profile/useRemoveProfileInterests.ts @@ -0,0 +1,65 @@ +import { ProfileInterestTypes } from '@lens-protocol/api-bindings'; +import { invariant, success } from '@lens-protocol/shared-kernel'; + +import { SessionType, useSession } from '../authentication'; +import { UseDeferredTask, useDeferredTask } from '../helpers/tasks'; +import { useProfileInterestsController } from './adapters/useProfileInterestsController'; + +export { ProfileInterestTypes }; + +export type RemoveProfileInterestsArgs = { + interests: ProfileInterestTypes[]; +}; + +/** + * Remove profile interests. + * + * You MUST be authenticated via {@link useLogin} to use this hook. + * + * @example + * ```tsx + * function ProfileInterests({ profile }: { profile: Profile }) { + * const { execute: addInterests } = useAddProfileInterests(); + * const { execute: removeInterests } = useRemoveProfileInterests(); + * + * const handleClick = async (interest: ProfileInterestTypes) => { + * const request = { + * interests: [interest], + * }; + * + * if (profile.interests.includes(interest)) { + * await removeInterests(request); + * } else { + * await addInterests(request); + * } + * }; + * + * return ; + * } + * ``` + * + * @category Profiles + * @group Hooks + */ +export function useRemoveProfileInterests(): UseDeferredTask< + void, + never, + RemoveProfileInterestsArgs +> { + const { data: session } = useSession(); + const { remove } = useProfileInterestsController(); + + return useDeferredTask(async (request) => { + invariant( + session?.type === SessionType.WithProfile, + 'You must be authenticated with a profile to use this hook. Use `useLogin` hook to authenticate.', + ); + + await remove({ + profileId: session.profile.id, + interests: request.interests, + }); + + return success(); + }); +} From 25205fc834f70900601aac86593e54ae9c17a145 Mon Sep 17 00:00:00 2001 From: Kris Urbas <605420+krzysu@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:30:21 +0200 Subject: [PATCH 2/2] code review --- .../profile/ManageProfileInterests.ts | 28 +++++++++---------- .../adapters/ProfileInterestsGateway.ts | 4 +-- .../adapters/ProfileInterestsPresenter.ts | 12 +++++--- .../adapters/useProfileInterestsController.ts | 17 +++++++++-- .../src/profile/useAddProfileInterests.ts | 10 +------ .../src/profile/useRemoveProfileInterests.ts | 10 +------ 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/packages/domain/src/use-cases/profile/ManageProfileInterests.ts b/packages/domain/src/use-cases/profile/ManageProfileInterests.ts index 93ce9e9a0..6bebae3ba 100644 --- a/packages/domain/src/use-cases/profile/ManageProfileInterests.ts +++ b/packages/domain/src/use-cases/profile/ManageProfileInterests.ts @@ -1,31 +1,29 @@ -import { ProfileId } from '../../entities'; - -export type ProfileInterestsRequest = { - profileId: ProfileId; +export type ProfileInterestsRequest = { + interests: T[]; }; -export interface IProfileInterestsGateway { - add(request: ProfileInterestsRequest): Promise; - remove(request: ProfileInterestsRequest): Promise; +export interface IProfileInterestsGateway { + add(request: ProfileInterestsRequest): Promise; + remove(request: ProfileInterestsRequest): Promise; } -export interface IProfileInterestsPresenter { - add(request: ProfileInterestsRequest): Promise; - remove(request: ProfileInterestsRequest): Promise; +export interface IProfileInterestsPresenter { + add(request: ProfileInterestsRequest): Promise; + remove(request: ProfileInterestsRequest): Promise; } -export class ManageProfileInterests { +export class ManageProfileInterests { constructor( - private readonly gateway: IProfileInterestsGateway, - private readonly presenter: IProfileInterestsPresenter, + private readonly gateway: IProfileInterestsGateway, + private readonly presenter: IProfileInterestsPresenter, ) {} - async add(request: ProfileInterestsRequest) { + async add(request: ProfileInterestsRequest) { void this.gateway.add(request); await this.presenter.add(request); } - async remove(request: ProfileInterestsRequest) { + async remove(request: ProfileInterestsRequest) { void this.gateway.remove(request); await this.presenter.remove(request); } diff --git a/packages/react/src/profile/adapters/ProfileInterestsGateway.ts b/packages/react/src/profile/adapters/ProfileInterestsGateway.ts index aa710c73d..38292cca0 100644 --- a/packages/react/src/profile/adapters/ProfileInterestsGateway.ts +++ b/packages/react/src/profile/adapters/ProfileInterestsGateway.ts @@ -8,15 +8,13 @@ import { RemoveProfileInterestsVariables, SafeApolloClient, } from '@lens-protocol/api-bindings'; -import { ProfileId } from '@lens-protocol/domain/entities'; import { IProfileInterestsGateway } from '@lens-protocol/domain/use-cases/profile'; export type ProfileInterestsRequest = { - profileId: ProfileId; interests: ProfileInterestTypes[]; }; -export class ProfileInterestsGateway implements IProfileInterestsGateway { +export class ProfileInterestsGateway implements IProfileInterestsGateway { constructor(private apolloClient: SafeApolloClient) {} async add(request: ProfileInterestsRequest) { diff --git a/packages/react/src/profile/adapters/ProfileInterestsPresenter.ts b/packages/react/src/profile/adapters/ProfileInterestsPresenter.ts index f0a0b7406..ba275ead4 100644 --- a/packages/react/src/profile/adapters/ProfileInterestsPresenter.ts +++ b/packages/react/src/profile/adapters/ProfileInterestsPresenter.ts @@ -1,14 +1,18 @@ import { ProfileInterestTypes } from '@lens-protocol/api-bindings'; +import { ProfileId } from '@lens-protocol/domain/entities'; import { IProfileInterestsPresenter } from '@lens-protocol/domain/use-cases/profile'; import { IProfileCacheManager } from './IProfileCacheManager'; import { ProfileInterestsRequest } from './ProfileInterestsGateway'; -export class ProfileInterestsPresenter implements IProfileInterestsPresenter { - constructor(private readonly profileCacheManager: IProfileCacheManager) {} +export class ProfileInterestsPresenter implements IProfileInterestsPresenter { + constructor( + private readonly profileCacheManager: IProfileCacheManager, + private readonly profileId: ProfileId, + ) {} async add(request: ProfileInterestsRequest) { - this.profileCacheManager.update(request.profileId, (current) => { + this.profileCacheManager.update(this.profileId, (current) => { return { ...current, interests: [...current.interests, ...request.interests], @@ -17,7 +21,7 @@ export class ProfileInterestsPresenter implements IProfileInterestsPresenter { } async remove(request: ProfileInterestsRequest) { - this.profileCacheManager.update(request.profileId, (current) => { + this.profileCacheManager.update(this.profileId, (current) => { return { ...current, interests: current.interests.filter( diff --git a/packages/react/src/profile/adapters/useProfileInterestsController.ts b/packages/react/src/profile/adapters/useProfileInterestsController.ts index a8b92122d..caef2029a 100644 --- a/packages/react/src/profile/adapters/useProfileInterestsController.ts +++ b/packages/react/src/profile/adapters/useProfileInterestsController.ts @@ -1,14 +1,22 @@ import { ManageProfileInterests } from '@lens-protocol/domain/use-cases/profile'; +import { invariant } from '@lens-protocol/shared-kernel'; +import { SessionType, useSession } from '../../authentication'; import { useSharedDependencies } from '../../shared'; import { ProfileInterestsGateway, ProfileInterestsRequest } from './ProfileInterestsGateway'; import { ProfileInterestsPresenter } from './ProfileInterestsPresenter'; export function useProfileInterestsController() { const { apolloClient, profileCacheManager } = useSharedDependencies(); + const { data: session } = useSession(); const add = async (request: ProfileInterestsRequest) => { - const presenter = new ProfileInterestsPresenter(profileCacheManager); + invariant( + session?.type === SessionType.WithProfile, + 'You must be authenticated with a profile to use this hook. Use `useLogin` hook to authenticate.', + ); + + const presenter = new ProfileInterestsPresenter(profileCacheManager, session.profile.id); const gateway = new ProfileInterestsGateway(apolloClient); const manageInterests = new ManageProfileInterests(gateway, presenter); @@ -16,7 +24,12 @@ export function useProfileInterestsController() { }; const remove = async (request: ProfileInterestsRequest) => { - const presenter = new ProfileInterestsPresenter(profileCacheManager); + invariant( + session?.type === SessionType.WithProfile, + 'You must be authenticated with a profile to use this hook. Use `useLogin` hook to authenticate.', + ); + + const presenter = new ProfileInterestsPresenter(profileCacheManager, session.profile.id); const gateway = new ProfileInterestsGateway(apolloClient); const manageInterests = new ManageProfileInterests(gateway, presenter); diff --git a/packages/react/src/profile/useAddProfileInterests.ts b/packages/react/src/profile/useAddProfileInterests.ts index d8649e19f..6a5d6fe8f 100644 --- a/packages/react/src/profile/useAddProfileInterests.ts +++ b/packages/react/src/profile/useAddProfileInterests.ts @@ -1,7 +1,6 @@ import { ProfileInterestTypes } from '@lens-protocol/api-bindings'; -import { invariant, success } from '@lens-protocol/shared-kernel'; +import { success } from '@lens-protocol/shared-kernel'; -import { SessionType, useSession } from '../authentication'; import { UseDeferredTask, useDeferredTask } from '../helpers/tasks'; import { useProfileInterestsController } from './adapters/useProfileInterestsController'; @@ -42,17 +41,10 @@ export type AddProfileInterestsArgs = { * @group Hooks */ export function useAddProfileInterests(): UseDeferredTask { - const { data: session } = useSession(); const { add } = useProfileInterestsController(); return useDeferredTask(async (request) => { - invariant( - session?.type === SessionType.WithProfile, - 'You must be authenticated with a profile to use this hook. Use `useLogin` hook to authenticate.', - ); - await add({ - profileId: session.profile.id, interests: request.interests, }); diff --git a/packages/react/src/profile/useRemoveProfileInterests.ts b/packages/react/src/profile/useRemoveProfileInterests.ts index 6fcc6e686..5c23f8969 100644 --- a/packages/react/src/profile/useRemoveProfileInterests.ts +++ b/packages/react/src/profile/useRemoveProfileInterests.ts @@ -1,7 +1,6 @@ import { ProfileInterestTypes } from '@lens-protocol/api-bindings'; -import { invariant, success } from '@lens-protocol/shared-kernel'; +import { success } from '@lens-protocol/shared-kernel'; -import { SessionType, useSession } from '../authentication'; import { UseDeferredTask, useDeferredTask } from '../helpers/tasks'; import { useProfileInterestsController } from './adapters/useProfileInterestsController'; @@ -46,17 +45,10 @@ export function useRemoveProfileInterests(): UseDeferredTask< never, RemoveProfileInterestsArgs > { - const { data: session } = useSession(); const { remove } = useProfileInterestsController(); return useDeferredTask(async (request) => { - invariant( - session?.type === SessionType.WithProfile, - 'You must be authenticated with a profile to use this hook. Use `useLogin` hook to authenticate.', - ); - await remove({ - profileId: session.profile.id, interests: request.interests, });