Skip to content

Commit

Permalink
fixup! client: Add more type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Jul 29, 2023
1 parent aef4f13 commit 590f2f0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions client/js/sharers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import map from 'ramda/src/map.js';
import selfoss from './selfoss-base';
import * as icons from './icons';
import { Configuration } from './model/Configuration';

function materializeSharerIcon(sharer) {
type Sharer = {
label: string,
icon: string | JSX.Element,
action: (params: { url: string, title: string }) => void,
available?: boolean,
};

function materializeSharerIcon(sharer: Sharer): Sharer {
const { icon } = sharer;
return {
...sharer,
// We want to allow people to use <svg> or <img> in user.js
icon: typeof icon === 'string' && icon.includes('<') ? <span dangerouslySetInnerHTML={{ __html: icon }} /> : icon,
};
}

export function useSharers({ configuration, _ }) {
export function useSharers(
args: {
configuration: Configuration,
_: (identifier: string, params?: {[index: string]: string}) => string,
},
): Array<Sharer> {
const { configuration, _ } = args;

return useMemo(
() => {
const availableSharers = {
(): Array<Sharer> => {
const availableSharers: { [key: string]: Sharer } = {
'a': {
label: _('share_native_label'),
icon: <FontAwesomeIcon icon={icons.share} />,
Expand Down

0 comments on commit 590f2f0

Please sign in to comment.