From 9e311f95aa8d6dff09a631e0cd273cb03cf7b998 Mon Sep 17 00:00:00 2001 From: fusagiko / takayamaki <24884114+takayamaki@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:11:22 +0900 Subject: [PATCH] [Glitch] simplify counters Port e0d230fb37848efd788eea54a83869a63ff0fb39 to glitch-soc Signed-off-by: Claire --- .../glitch/components/common_counter.jsx | 59 ------------------- .../flavours/glitch/components/counters.tsx | 45 ++++++++++++++ 2 files changed, 45 insertions(+), 59 deletions(-) delete mode 100644 app/javascript/flavours/glitch/components/common_counter.jsx create mode 100644 app/javascript/flavours/glitch/components/counters.tsx diff --git a/app/javascript/flavours/glitch/components/common_counter.jsx b/app/javascript/flavours/glitch/components/common_counter.jsx deleted file mode 100644 index 785907bd25..0000000000 --- a/app/javascript/flavours/glitch/components/common_counter.jsx +++ /dev/null @@ -1,59 +0,0 @@ -// @ts-check -import { FormattedMessage } from 'react-intl'; -/** - * Returns custom renderer for one of the common counter types - * @param {"statuses" | "following" | "followers"} counterType - * Type of the counter - * @param {boolean} isBold Whether display number must be displayed in bold - * @returns {(displayNumber: JSX.Element, pluralReady: number) => JSX.Element} - * Renderer function - * @throws If counterType is not covered by this function - */ -export function counterRenderer(counterType, isBold = true) { - /** - * @type {(displayNumber: JSX.Element) => JSX.Element} - */ - const renderCounter = isBold - ? (displayNumber) => {displayNumber} - : (displayNumber) => displayNumber; - - switch (counterType) { - case 'statuses': { - return (displayNumber, pluralReady) => ( - - ); - } - case 'following': { - return (displayNumber, pluralReady) => ( - - ); - } - case 'followers': { - return (displayNumber, pluralReady) => ( - - ); - } - default: throw Error(`Incorrect counter name: ${counterType}. Ensure it accepted by commonCounter function`); - } -} diff --git a/app/javascript/flavours/glitch/components/counters.tsx b/app/javascript/flavours/glitch/components/counters.tsx new file mode 100644 index 0000000000..e0c818f247 --- /dev/null +++ b/app/javascript/flavours/glitch/components/counters.tsx @@ -0,0 +1,45 @@ +import React from 'react'; + +import { FormattedMessage } from 'react-intl'; + +export const StatusesCounter = ( + displayNumber: React.ReactNode, + pluralReady: number +) => ( + {displayNumber}, + }} + /> +); + +export const FollowingCounter = ( + displayNumber: React.ReactNode, + pluralReady: number +) => ( + {displayNumber}, + }} + /> +); + +export const FollowersCounter = ( + displayNumber: React.ReactNode, + pluralReady: number +) => ( + {displayNumber}, + }} + /> +);