File size: 1,089 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import { QueryKey } from '@tanstack/react-query';
import { PluginQueryOptions } from './types';
import { MarketplaceReviewResponse } from './use-marketplace-reviews';
const PLUGINS_CACHE_VERSION = 1;
export const getPluginsListKey = (
key: QueryKey,
options: PluginQueryOptions,
infinite?: boolean
): QueryKey => {
const keyParams = [
options.category || '',
options.searchTerm || '',
options.pageSize || '',
options.locale || '',
options.page || '',
infinite ? 'infinite' : '',
options.tag && ! options.searchTerm ? options.tag : '',
];
return [ ...key, PLUGINS_CACHE_VERSION.toString(), ...keyParams ];
};
/**
* Get a single avatar URL from a given review.
* Tries to get a picture with the biggest resolution possible.
* @param {MarketplaceReviewResponse} review the review object
* @returns {string|undefined} the avatar URL when found
*/
export const getAvatarURL = ( review: MarketplaceReviewResponse ) => {
return (
review.author_avatar_urls[ '96' ] ??
review.author_avatar_urls[ '48' ] ??
review.author_avatar_urls[ '24' ] ??
undefined
);
};
|