Commit 51d8910d authored by aleclofabbro's avatar aleclofabbro

Merge branch...

Merge branch 'fix/search_follow_checks_and_programmatic_workaround_for_follow_button_link' into develop
parents 2a5ba56a f096c953
......@@ -68,13 +68,13 @@ export const SearchPageHOC = connectInfiniteHits(_SearchPageHOC);
const CollectionPreviewHit: React.FC<{ hit: CollectionHit }> = ({ hit }) => {
const isLocal = useIsLocal(hit);
const previewFragment = collectionHit2gql(hit, isLocal);
const toggleFollowFormik = useToggleFollowHitFormik(hit);
const { toggleFollowFormik } = useFollowHitHelper(hit);
const props =
previewFragment &&
collectionFragment2UIProps({
collection: previewFragment,
hideActions: false,
toggleFollowFormik: toggleFollowFormik
toggleFollowFormik
});
!props && console.warn(`Could not preview searchHit:`, hit);
// console.log(`Collection:`, props)
......@@ -84,14 +84,17 @@ const CollectionPreviewHit: React.FC<{ hit: CollectionHit }> = ({ hit }) => {
const CommunityPreviewHit: React.FC<{ hit: CommunityHit }> = ({ hit }) => {
const isLocal = useIsLocal(hit);
const previewFragment = communityHit2gql(hit, isLocal);
const toggleFollowFormik = useToggleFollowHitFormik(hit);
const {
toggleFollowFormik: toggleJoinFormik,
hitSearchFollow
} = useFollowHitHelper(hit);
const props =
previewFragment &&
communityFragment2UIProps({
community: previewFragment,
hideActions: false,
toggleJoinFormik: toggleFollowFormik,
isCreator: false //FIXME
toggleJoinFormik,
isCreator: !!hitSearchFollow?.isCreator
});
!props && console.warn(`Could not preview searchHit:`, hit);
// console.log(`Community:`, props)
......@@ -136,13 +139,13 @@ const useIsLocal = (hit: Hit) => {
// console.log(`---`)
return isLocal;
};
const useToggleFollowHitFormik = (hit: Hit) => {
const useFollowHitHelper = (hit: Hit) => {
const { data } = useSearchHostIndexAndMyFollowsQuery({
context: mnCtx({ noShowError: true })
});
const [follow, followResult] = useSearchFollowMutation();
const [unfollow, unfollowResult] = useSearchUnfollowMutation();
const myFollow = React.useMemo(
const hitSearchFollow = React.useMemo(
() =>
(data?.me?.searchFollows || []).find(
searchFollow => searchFollow.canonicalUrl === hit.canonicalUrl
......@@ -150,20 +153,34 @@ const useToggleFollowHitFormik = (hit: Hit) => {
[data, hit]
);
const canFollow = !hitSearchFollow?.followId;
const canUnfollow =
hitSearchFollow?.followId &&
!(hitSearchFollow.communityId && hitSearchFollow.isCreator);
const toggleFollowFormik = useFormik({
initialValues: {},
onSubmit: async () => {
if (!hit.canonicalUrl || followResult.loading || unfollowResult.loading) {
return;
}
return myFollow
? unfollow({
variables: {
contextId: myFollow.canonicalUrl /*FIXME with myFollow.followId */
}
})
: follow({ variables: { url: hit.canonicalUrl } });
if (hitSearchFollow && canUnfollow) {
return unfollow({
variables: {
contextId: hitSearchFollow.followId
}
});
} else if (canFollow) {
return follow({ variables: { url: hit.canonicalUrl } });
}
return;
}
});
return toggleFollowFormik;
return React.useMemo(
() => ({
toggleFollowFormik,
hitSearchFollow
}),
[toggleFollowFormik, hitSearchFollow]
);
};
......@@ -27,7 +27,7 @@ export type SearchMeFragment = (
{ __typename: 'Me' }
& { searchFollows: Array<(
{ __typename: 'SearchFollow' }
& Pick<Types.SearchFollow, 'canonicalUrl' | 'collectionId' | 'communityId'>
& Pick<Types.SearchFollow, 'canonicalUrl' | 'collectionId' | 'communityId' | 'followId' | 'isCreator'>
)> }
);
......@@ -65,6 +65,8 @@ export const SearchMeFragmentDoc = gql`
canonicalUrl
collectionId
communityId
followId
isCreator
}
}
`;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -188,7 +188,7 @@ export type CollectionThreadsArgs = {
export type CollectionInput = {
extraInfo?: Maybe<Scalars['Json']>,
name: Scalars['String'],
preferredUsername: Scalars['String'],
preferredUsername?: Maybe<Scalars['String']>,
summary?: Maybe<Scalars['String']>,
};
......@@ -387,7 +387,7 @@ export type CommunityThreadsArgs = {
export type CommunityInput = {
extraInfo?: Maybe<Scalars['Json']>,
name: Scalars['String'],
preferredUsername: Scalars['String'],
preferredUsername?: Maybe<Scalars['String']>,
summary?: Maybe<Scalars['String']>,
};
......@@ -751,84 +751,89 @@ export type ResourcesPage = {
export type RootMutationType = {
__typename?: 'RootMutationType',
/** Modify a comment */
updateComment?: Maybe<Comment>,
/** Create a collection */
createCollection?: Maybe<Collection>,
createRegisterEmailAccess: RegisterEmailAccess,
/** Fetch metadata from webpage */
fetchWebMetadata?: Maybe<WebMetadata>,
/** Like a comment, collection, or resource returning the like */
createLike?: Maybe<Like>,
/** Update a resource */
updateResource?: Maybe<Resource>,
/** Follow a community, collection or thread returning the follow */
createFollow?: Maybe<Follow>,
/** Close a flag */
resolveFlag?: Maybe<Flag>,
/** Update a community */
updateCommunity?: Maybe<Community>,
/** Reply to an existing comment in a thread */
createReply?: Maybe<Comment>,
/** Update a profile */
updateProfile?: Maybe<Me>,
createRegisterEmailDomainAccess: RegisterEmailDomainAccess,
/** Sends an email invite */
sendInvite?: Maybe<Scalars['Boolean']>,
/** Flag a user, community, collection, resource or comment, returning the flag */
createFlag?: Maybe<Flag>,
/** Feature a community, or collection, returning the feature */
createFeature?: Maybe<Feature>,
/** Follow a community, collection or a user by their canonical url returning the follow */
createFollowByUrl?: Maybe<Follow>,
deleteRegisterEmailAccess?: Maybe<RegisterEmailAccess>,
/** Create a user */
createUser?: Maybe<Me>,
/** Log out */
deleteSession?: Maybe<Scalars['Boolean']>,
/** Fetch metadata from webpage */
fetchWebMetadata?: Maybe<WebMetadata>,
/** Create a new thread */
createThread?: Maybe<Comment>,
deleteRegisterEmailDomainAccess?: Maybe<RegisterEmailDomainAccess>,
/** Follow a community, collection or thread returning the follow */
createFollow?: Maybe<Follow>,
/** Update a collection */
updateCollection?: Maybe<Collection>,
/** Log in */
createSession?: Maybe<AuthPayload>,
/** Create a resource */
createResource?: Maybe<Resource>,
/** Update a resource */
updateResource?: Maybe<Resource>,
/** Reply to an existing comment in a thread */
createReply?: Maybe<Comment>,
/** Deletes my account! */
deleteSelf?: Maybe<Scalars['Boolean']>,
createRegisterEmailDomainAccess: RegisterEmailDomainAccess,
/** Follow a community, collection or a user by their canonical url returning the follow */
createFollowByUrl?: Maybe<Follow>,
/** Reset password */
resetPassword?: Maybe<AuthPayload>,
/** Confirm email. Returns a login token. */
confirmEmail?: Maybe<AuthPayload>,
createRegisterEmailAccess: RegisterEmailAccess,
/** Create a community */
createCommunity?: Maybe<Community>,
/** Modify a comment */
updateComment?: Maybe<Comment>,
/** Copy a resource */
copyResource?: Maybe<Resource>,
/** Deactivate a remote user, blocking further activities from it */
deactivateUser?: Maybe<User>,
/** Create a user */
createUser?: Maybe<Me>,
/** Like a comment, collection, or resource returning the like */
createLike?: Maybe<Like>,
/** Flag a user, community, collection, resource or comment, returning the flag */
createFlag?: Maybe<Flag>,
deleteRegisterEmailAccess?: Maybe<RegisterEmailAccess>,
/** Sends an email invite */
sendInvite?: Maybe<Scalars['Boolean']>,
/** Reset password request */
resetPasswordRequest?: Maybe<Scalars['Boolean']>,
/** Create a community */
createCommunity?: Maybe<Community>,
/** Create a collection */
createCollection?: Maybe<Collection>,
deleteRegisterEmailDomainAccess?: Maybe<RegisterEmailDomainAccess>,
/** Log in */
createSession?: Maybe<AuthPayload>,
/** Update a community */
updateCommunity?: Maybe<Community>,
/** Update a collection */
updateCollection?: Maybe<Collection>,
/** Create a resource */
createResource?: Maybe<Resource>,
/** Update a profile */
updateProfile?: Maybe<Me>,
/** Delete more or less anything */
delete?: Maybe<DeleteContext>,
/** Feature a community, or collection, returning the feature */
createFeature?: Maybe<Feature>,
/** Confirm email. Returns a login token. */
confirmEmail?: Maybe<AuthPayload>,
/** Copy a resource */
copyResource?: Maybe<Resource>,
/** Reset password */
resetPassword?: Maybe<AuthPayload>,
};
export type RootMutationTypeUpdateCommentArgs = {
comment: CommentInput,
commentId: Scalars['String']
export type RootMutationTypeFetchWebMetadataArgs = {
url: Scalars['String']
};
export type RootMutationTypeCreateCollectionArgs = {
collection: CollectionInput,
communityId: Scalars['String'],
icon?: Maybe<UploadInput>
export type RootMutationTypeCreateLikeArgs = {
contextId: Scalars['String']
};
export type RootMutationTypeCreateRegisterEmailAccessArgs = {
email: Scalars['String']
export type RootMutationTypeUpdateResourceArgs = {
content?: Maybe<UploadInput>,
icon?: Maybe<UploadInput>,
resource: ResourceInput,
resourceId: Scalars['String']
};
export type RootMutationTypeCreateFollowArgs = {
contextId: Scalars['String']
};
......@@ -837,96 +842,88 @@ export type RootMutationTypeResolveFlagArgs = {
};
export type RootMutationTypeUpdateCommunityArgs = {
community: CommunityUpdateInput,
communityId: Scalars['String'],
icon?: Maybe<UploadInput>,
image?: Maybe<UploadInput>
export type RootMutationTypeCreateRegisterEmailDomainAccessArgs = {
domain: Scalars['String']
};
export type RootMutationTypeCreateReplyArgs = {
comment: CommentInput,
inReplyToId: Scalars['String'],
threadId: Scalars['String']
export type RootMutationTypeSendInviteArgs = {
email: Scalars['String']
};
export type RootMutationTypeUpdateProfileArgs = {
icon?: Maybe<UploadInput>,
image?: Maybe<UploadInput>,
profile: UpdateProfileInput
export type RootMutationTypeCreateFlagArgs = {
contextId: Scalars['String'],
message: Scalars['String']
};
export type RootMutationTypeFetchWebMetadataArgs = {
url: Scalars['String']
export type RootMutationTypeCreateFeatureArgs = {
contextId: Scalars['String']
};
export type RootMutationTypeCreateThreadArgs = {
comment: CommentInput,
contextId: Scalars['String']
export type RootMutationTypeCreateFollowByUrlArgs = {
url: Scalars['String']
};
export type RootMutationTypeDeleteRegisterEmailDomainAccessArgs = {
export type RootMutationTypeDeleteRegisterEmailAccessArgs = {
id: Scalars['String']
};
export type RootMutationTypeCreateFollowArgs = {
contextId: Scalars['String']
export type RootMutationTypeCreateUserArgs = {
icon?: Maybe<UploadInput>,
image?: Maybe<UploadInput>,
user: RegistrationInput
};
export type RootMutationTypeUpdateCollectionArgs = {
collection: CollectionUpdateInput,
collectionId: Scalars['String'],
icon?: Maybe<UploadInput>
export type RootMutationTypeCreateThreadArgs = {
comment: CommentInput,
contextId: Scalars['String']
};
export type RootMutationTypeCreateSessionArgs = {
email: Scalars['String'],
password: Scalars['String']
export type RootMutationTypeCreateReplyArgs = {
comment: CommentInput,
inReplyToId: Scalars['String'],
threadId: Scalars['String']
};
export type RootMutationTypeCreateResourceArgs = {
collectionId: Scalars['String'],
content: UploadInput,
icon?: Maybe<UploadInput>,
resource: ResourceInput
export type RootMutationTypeDeleteSelfArgs = {
iAmSure: Scalars['Boolean']
};
export type RootMutationTypeUpdateResourceArgs = {
content?: Maybe<UploadInput>,
icon?: Maybe<UploadInput>,
resource: ResourceInput,
resourceId: Scalars['String']
export type RootMutationTypeConfirmEmailArgs = {
token: Scalars['String']
};
export type RootMutationTypeDeleteSelfArgs = {
iAmSure: Scalars['Boolean']
export type RootMutationTypeCreateRegisterEmailAccessArgs = {
email: Scalars['String']
};
export type RootMutationTypeCreateRegisterEmailDomainAccessArgs = {
domain: Scalars['String']
export type RootMutationTypeCreateCommunityArgs = {
community: CommunityInput,
icon?: Maybe<UploadInput>,
image?: Maybe<UploadInput>
};
export type RootMutationTypeCreateFollowByUrlArgs = {
url: Scalars['String']
export type RootMutationTypeUpdateCommentArgs = {
comment: CommentInput,
commentId: Scalars['String']
};
export type RootMutationTypeResetPasswordArgs = {
password: Scalars['String'],
token: Scalars['String']
export type RootMutationTypeCopyResourceArgs = {
collectionId: Scalars['String'],
resourceId: Scalars['String']
};
......@@ -935,66 +932,69 @@ export type RootMutationTypeDeactivateUserArgs = {
};
export type RootMutationTypeCreateUserArgs = {
icon?: Maybe<UploadInput>,
image?: Maybe<UploadInput>,
user: RegistrationInput
export type RootMutationTypeResetPasswordRequestArgs = {
email: Scalars['String']
};
export type RootMutationTypeCreateLikeArgs = {
contextId: Scalars['String']
export type RootMutationTypeCreateCollectionArgs = {
collection: CollectionInput,
communityId: Scalars['String'],
icon?: Maybe<UploadInput>
};
export type RootMutationTypeCreateFlagArgs = {
contextId: Scalars['String'],
message: Scalars['String']
export type RootMutationTypeDeleteRegisterEmailDomainAccessArgs = {
id: Scalars['String']
};
export type RootMutationTypeDeleteRegisterEmailAccessArgs = {
id: Scalars['String']
export type RootMutationTypeCreateSessionArgs = {
email: Scalars['String'],
password: Scalars['String']
};
export type RootMutationTypeSendInviteArgs = {
email: Scalars['String']
export type RootMutationTypeUpdateCommunityArgs = {
community: CommunityUpdateInput,
communityId: Scalars['String'],
icon?: Maybe<UploadInput>,
image?: Maybe<UploadInput>
};
export type RootMutationTypeResetPasswordRequestArgs = {
email: Scalars['String']
export type RootMutationTypeUpdateCollectionArgs = {
collection: CollectionUpdateInput,
collectionId: Scalars['String'],
icon?: Maybe<UploadInput>
};
export type RootMutationTypeCreateCommunityArgs = {
community: CommunityInput,
export type RootMutationTypeCreateResourceArgs = {
collectionId: Scalars['String'],
content: UploadInput,
icon?: Maybe<UploadInput>,
image?: Maybe<UploadInput>
resource: ResourceInput
};
export type RootMutationTypeDeleteArgs = {
contextId: Scalars['String']
export type RootMutationTypeUpdateProfileArgs = {
icon?: Maybe<UploadInput>,
image?: Maybe<UploadInput>,
profile: UpdateProfileInput
};
export type RootMutationTypeCreateFeatureArgs = {
export type RootMutationTypeDeleteArgs = {
contextId: Scalars['String']
};
export type RootMutationTypeConfirmEmailArgs = {
export type RootMutationTypeResetPasswordArgs = {
password: Scalars['String'],
token: Scalars['String']
};
export type RootMutationTypeCopyResourceArgs = {
collectionId: Scalars['String'],
resourceId: Scalars['String']
};
export type RootQueryType = {
__typename?: 'RootQueryType',
activity?: Maybe<Activity>,
......@@ -1223,82 +1223,82 @@ export type UploadInput = {
/** User profile information */
export type User = {
__typename?: 'User',
/** The likes a user has from other people */
likers?: Maybe<LikesPage>,
/** Whether an instance admin has disabled the user's account */
isDisabled: Scalars['Boolean'],
/** The last time the user did anything */
lastActivity?: Maybe<Scalars['String']>,
/** Whether the user has a public profile */
isPublic: Scalars['Boolean'],
/** A header background image url */
image?: Maybe<Content>,
/** Total number of likers, including those we can't see */
likerCount?: Maybe<Scalars['Int']>,
/** A valid URL */
website?: Maybe<Scalars['String']>,
/** The users a user is following, most recently followed first */
userFollows?: Maybe<FollowsPage>,
/** Total number of likes, including those we can't see */
likeCount?: Maybe<Scalars['Int']>,
/** The likes a user has created */
likes?: Maybe<LikesPage>,
/** Subscriptions users have to the collection */
follows?: Maybe<FollowsPage>,
/** The communities a user is following, most recently followed first */
communityFollows?: Maybe<FollowsPage>,
/** A url for the user, may be to a remote instance */
canonicalUrl?: Maybe<Scalars['String']>,
/** Total number of followers, including private follows */
followerCount?: Maybe<Scalars['Int']>,
/** When the user signed up */
createdAt: Scalars['String'],
/** The current user's follow of this user, if any */
myFollow?: Maybe<Follow>,
/** When the user last updated their profile */
updatedAt: Scalars['String'],
/** Total number of things the user follows, including privately */
followCount?: Maybe<Scalars['Int']>,
/** An avatar url */
icon?: Maybe<Content>,
/** Comments the user has made, most recently created first */
comments?: Maybe<CommentsPage>,
/** A preferred username + the host domain */
displayUsername: Scalars['String'],
/** An instance-unique identifier shared with communities and collections */
preferredUsername: Scalars['String'],
/** The communities a user is following, most recently followed first */
communityFollows?: Maybe<FollowsPage>,
/** Whether an instance admin has disabled the user's account */
isDisabled: Scalars['Boolean'],
/** Subscriptions users have to the collection */
follows?: Maybe<FollowsPage>,
/** When the user signed up */
createdAt: Scalars['String'],
/** The current user's flag of this user, if any */
myFlag?: Maybe<Flag>,
/** A JSON document containing more info beyond the default fields */
extraInfo?: Maybe<Scalars['Json']>,
/** Total number of things the user follows, including privately */
followCount?: Maybe<Scalars['Int']>,
/** An instance-local ULID identifying the user */
id: Scalars['ID'],
/**
* Activities of others the user is following, most recently created
* first. Only available to the current user under `me`
**/
inbox?: Maybe<ActivitiesPage>,
/** Possibly biographical information */
summary?: Maybe<Scalars['String']>,
/** The current user's flag of this user, if any */
myFlag?: Maybe<Flag>,
/** A name field */
name?: Maybe<Scalars['String']>,
/** Comments the user has made, most recently created first */
comments?: Maybe<CommentsPage>,
/** Activities of the user, most recently created first */
outbox?: Maybe<ActivitiesPage>,
/** An instance-unique identifier shared with communities and collections */
preferredUsername: Scalars['String'],
/** Total number of likers, including those we can't see */
likerCount?: Maybe<Scalars['Int']>,
/** The likes a user has created */
likes?: Maybe<LikesPage>,
/** Total number of likes, including those we can't see */
likeCount?: Maybe<Scalars['Int']>,
/** The collections a user is following, most recently followed first */
collectionFollows?: Maybe<FollowsPage>,
/** A name field */
name?: Maybe<Scalars['String']>,
/** Subscriptions users have to the collection */
followers?: Maybe<FollowsPage>,
/** A url for the user, may be to a remote instance */
canonicalUrl?: Maybe<Scalars['String']>,
/** The current user's like of this user, if any */
myLike?: Maybe<Like>,
/** Activities of the user, most recently created first */
outbox?: Maybe<ActivitiesPage>,
/** The likes a user has from other people */
likers?: Maybe<LikesPage>,
/** The users a user is following, most recently followed first */
userFollows?: Maybe<FollowsPage>,
/** The last time the user did anything */
lastActivity?: Maybe<Scalars['String']>,
/** The current user's follow of this user, if any */
myFollow?: Maybe<Follow>,
/** Whether the user is local to the instance */
isLocal: Scalars['Boolean'],
/** Possibly biographical information */
summary?: Maybe<Scalars['String']>,
/** Total number of followers, including private follows */
followerCount?: Maybe<Scalars['Int']>,
/** Free text */
location?: Maybe<Scalars['String']>,
/** An avatar url */
icon?: Maybe<Content>,
/** Whether the user has a public profile */
isPublic: Scalars['Boolean'],
/** The current user's like of this user, if any */
myLike?: Maybe<Like>,
/**
* Activities of others the user is following, most recently created
* first. Only available to the current user under `me`
**/
inbox?: Maybe<ActivitiesPage>,
/** When the user last updated their profile */
updatedAt: Scalars['String'],
};
/** User profile information */
export type UserLikersArgs = {
export type UserCommentsArgs = {
after?: Maybe<Array<Scalars['Cursor']>>,
before?: Maybe<Array<Scalars['Cursor']>>,
limit?: Maybe<Scalars['Int']>
......@@ -1306,7 +1306,7 @@ export type UserLikersArgs = {
/** User profile information */
export type UserUserFollowsArgs = {
export type UserCommunityFollowsArgs = {
after?: Maybe<Array<Scalars['Cursor']>>,
before?: Maybe<Array<Scalars['Cursor']>>,
limit?: Maybe<Scalars['Int']>
......@@ -1314,7 +1314,7 @@ export type UserUserFollowsArgs = {
/** User profile information */
export type UserLikesArgs = {
export type UserFollowsArgs = {
after?: Maybe<Array<Scalars['Cursor']>>,
before?: Maybe<Array<Scalars['Cursor']>>,
limit?: Maybe<Scalars['Int']>
......@@ -1322,7 +1322,7 @@ export type UserLikesArgs = {
/** User profile information */
export type UserFollowsArgs = {
export type UserLikesArgs = {
after?: Maybe<Array<Scalars['Cursor']>>,
before?: Maybe<Array<Scalars['Cursor']>>,
limit?: Maybe<Scalars['Int']>
......@@ -1330,7 +1330,7 @@ export type UserFollowsArgs = {
/** User profile information */
export type UserCommunityFollowsArgs = {
export type UserCollectionFollowsArgs = {
after?: Maybe<Array<Scalars['Cursor']>>,
before?: Maybe<Array<Scalars['Cursor']>>,
limit?: Maybe<Scalars['Int']>
......@@ -1338,7 +1338,7 @@ export type UserCommunityFollowsArgs = {
/** User profile information */
export type UserInboxArgs = {
export type UserFollowersArgs = {
after?: Maybe<Array<Scalars['Cursor']>>,
before?: Maybe<Array<Scalars['Cursor']>>,
limit?: Maybe<Scalars['Int']>
......@@ -1346,7 +1346,7 @@ export type UserInboxArgs = {
/** User profile information */
export type UserCommentsArgs = {
export type UserOutboxArgs = {
after?: Maybe<Array<Scalars['Cursor']>>,
before?: Maybe<Array<Scalars['Cursor']>>,
limit?: Maybe<Scalars['Int']>
......@@ -1354,7 +1354,7 @@ export type UserCommentsArgs = {
/** User profile information */
export type UserOutboxArgs = {
export type UserLikersArgs = {
after?: Maybe<Array<Scalars['Cursor']>>,
before?: Maybe<Array<Scalars['Cursor']>>,
limit?: Maybe<Scalars['Int']>
......@@ -1362,7 +1362,7 @@ export type UserOutboxArgs = {