-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated activitypub search suggestions to be dynamic
refs [TryGhost/ActivityPub#60](TryGhost/ActivityPub#60) Updated activitypub search suggestions to be dynamic
- Loading branch information
Showing
4 changed files
with
101 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1091,4 +1091,41 @@ describe('ActivityPubAPI', function () { | |
expect(actual.following).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('getProfile', function () { | ||
test('It returns a profile', async function () { | ||
const handle = '@[email protected]'; | ||
|
||
const fakeFetch = Fetch({ | ||
'https://auth.api/': { | ||
response: JSONResponse({ | ||
identities: [{ | ||
token: 'fake-token' | ||
}] | ||
}) | ||
}, | ||
[`https://activitypub.api/.ghost/activitypub/profile/${handle}`]: { | ||
response: JSONResponse({ | ||
handle, | ||
name: 'Foo Bar' | ||
}) | ||
} | ||
}); | ||
|
||
const api = new ActivityPubAPI( | ||
new URL('https://activitypub.api'), | ||
new URL('https://auth.api'), | ||
'index', | ||
fakeFetch | ||
); | ||
|
||
const actual = await api.getProfile(handle); | ||
const expected = { | ||
handle, | ||
name: 'Foo Bar' | ||
}; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import MainNavigation from './navigation/MainNavigation'; | |
import NiceModal from '@ebay/nice-modal-react'; | ||
import ProfileSearchResultModal from './search/ProfileSearchResultModal'; | ||
|
||
import {useSearchForUser} from '../hooks/useActivityPubQueries'; | ||
import {useSearchForUser, useSuggestedProfiles} from '../hooks/useActivityPubQueries'; | ||
|
||
interface SearchResultItem { | ||
actor: ActorProperties; | ||
|
@@ -73,72 +73,8 @@ const SearchResult: React.FC<SearchResultProps> = ({result, update}) => { | |
|
||
const Search: React.FC<SearchProps> = ({}) => { | ||
// Initialise suggested profiles | ||
const [suggested, setSuggested] = useState<SearchResultItem[]>([ | ||
{ | ||
actor: { | ||
id: 'https://mastodon.social/@quillmatiq', | ||
name: 'Anuj Ahooja', | ||
preferredUsername: '@[email protected]', | ||
image: { | ||
url: 'https://anujahooja.com/assets/images/image12.jpg?v=601ebe30' | ||
}, | ||
icon: { | ||
url: 'https://anujahooja.com/assets/images/image12.jpg?v=601ebe30' | ||
} | ||
} as ActorProperties, | ||
handle: '@[email protected]', | ||
followerCount: 436, | ||
followingCount: 634, | ||
isFollowing: false, | ||
posts: [] | ||
}, | ||
{ | ||
actor: { | ||
id: 'https://flipboard.social/@miaq', | ||
name: 'Mia Quagliarello', | ||
preferredUsername: '@[email protected]', | ||
image: { | ||
url: 'https://m-cdn.flipboard.social/accounts/avatars/109/824/428/955/351/328/original/383f288b81ab280c.png' | ||
}, | ||
icon: { | ||
url: 'https://m-cdn.flipboard.social/accounts/avatars/109/824/428/955/351/328/original/383f288b81ab280c.png' | ||
} | ||
} as ActorProperties, | ||
handle: '@[email protected]', | ||
followerCount: 533, | ||
followingCount: 335, | ||
isFollowing: false, | ||
posts: [] | ||
}, | ||
{ | ||
actor: { | ||
id: 'https://techpolicy.social/@mallory', | ||
name: 'Mallory', | ||
preferredUsername: '@[email protected]', | ||
image: { | ||
url: 'https://techpolicy.social/system/accounts/avatars/109/378/338/180/403/396/original/20b043b0265cac73.jpeg' | ||
}, | ||
icon: { | ||
url: 'https://techpolicy.social/system/accounts/avatars/109/378/338/180/403/396/original/20b043b0265cac73.jpeg' | ||
} | ||
} as ActorProperties, | ||
handle: '@[email protected]', | ||
followerCount: 1100, | ||
followingCount: 11, | ||
isFollowing: false, | ||
posts: [] | ||
} | ||
]); | ||
|
||
const updateSuggested = (id: string, updated: Partial<SearchResultItem>) => { | ||
const index = suggested.findIndex(result => result.actor.id === id); | ||
|
||
setSuggested((current) => { | ||
const newSuggested = [...current]; | ||
newSuggested[index] = {...newSuggested[index], ...updated}; | ||
return newSuggested; | ||
}); | ||
}; | ||
const {suggestedProfilesQuery, updateSuggestedProfile} = useSuggestedProfiles('index', ['@[email protected]', '@[email protected]', '@[email protected]']); | ||
const {data: suggested = [], isLoading: isLoadingSuggested} = suggestedProfilesQuery; | ||
|
||
// Initialise search query | ||
const queryInputRef = useRef<HTMLInputElement>(null); | ||
|
@@ -220,11 +156,14 @@ const Search: React.FC<SearchProps> = ({}) => { | |
{showSuggested && ( | ||
<> | ||
<span className='mb-1 flex w-full max-w-[560px] font-semibold'>Suggested accounts</span> | ||
{isLoadingSuggested && ( | ||
<LoadingIndicator size='sm'/> | ||
)} | ||
{suggested.map(profile => ( | ||
<SearchResult | ||
key={profile.actor.id} | ||
result={profile} | ||
update={updateSuggested} | ||
key={(profile as SearchResultItem).actor.id} | ||
result={profile as SearchResultItem} | ||
update={updateSuggestedProfile} | ||
/> | ||
))} | ||
</> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters