profile-plus
Version:
### IOS
40 lines • 2.33 kB
JavaScript
import React from 'react';
import style from './Avatar.module.css';
import { linkedComponent } from '../package.js';
import { Person } from '../shapes/Person.js';
import { useStyles } from 'lincd/utils/Hooks';
import { replaceLocalhostWithSiteRoot } from '../utils/helper.js';
import { getResizedImagePath } from 'lincd-server-utils/utils/ImageResize';
import { asset } from 'lincd/utils/LinkedFileStorage';
const DEFAULT_IMAGE = asset('/images/no-profile-picture.png');
const query = Person.query((person) => {
var _a, _b, _c, _d;
return ({
profilePictureCropped: (_b = (_a = person.profilePicture) === null || _a === void 0 ? void 0 : _a.cropped) === null || _b === void 0 ? void 0 : _b.contentUrl,
profilePictureFull: (_d = (_c = person.profilePicture) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.contentUrl,
givenName: person.givenName,
});
});
export const Avatar = linkedComponent(query, ({ profilePictureCropped, profilePictureFull, givenName, source, size = 'medium', className, fallback, overwriteSource, _refresh, ...restProps }) => {
var _a, _b;
restProps = useStyles(restProps, [style.root, style[size], className]);
let thumbnailSize = size === 'small' ? 64 : size === 'medium' ? 95 : 128;
let src = overwriteSource ||
((_a = profilePictureCropped === null || profilePictureCropped === void 0 ? void 0 : profilePictureCropped.cropped) === null || _a === void 0 ? void 0 : _a.contentUrl) ||
((_b = profilePictureFull === null || profilePictureFull === void 0 ? void 0 : profilePictureFull.image) === null || _b === void 0 ? void 0 : _b.contentUrl) ||
DEFAULT_IMAGE;
if (src && src !== DEFAULT_IMAGE) {
src = getResizedImagePath(replaceLocalhostWithSiteRoot(src), thumbnailSize * 2);
}
// android development path fix
const croppedImageSrc = replaceLocalhostWithSiteRoot(src);
if (src === DEFAULT_IMAGE && fallback) {
return fallback;
}
return (React.createElement("div", { ...restProps },
React.createElement("figure", { className: style.wrap },
React.createElement("img", { src: croppedImageSrc, alt: givenName }))));
});
//register all components in this file
// registerPackageModule(module);
//# sourceMappingURL=Avatar.js.map