Skip to content

Commit

Permalink
refactor: use common function for segment count
Browse files Browse the repository at this point in the history
  • Loading branch information
ajohn25 committed Feb 14, 2024
1 parent 0985768 commit 9f97f8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/components/MessageLengthInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { getCharCount } from "@trt2/gsm-charset-utils";
import PropTypes from "prop-types";
import React from "react";

import { replaceEasyGsmWins } from "../lib/charset-utils";
import { getSpokeCharCount } from "../lib/charset-utils";

const MessageLengthInfo: React.SFC<{ messageText: string }> = ({
messageText
}) => {
const { charCount, msgCount, charsPerSegment } = getCharCount(
replaceEasyGsmWins(messageText)
const { charCount, msgCount, charsPerSegment } = getSpokeCharCount(
messageText
);
const segmentInfo = msgCount === 1 ? "(1 segment)" : `(${msgCount} segments)`;

Expand Down
5 changes: 2 additions & 3 deletions src/components/ScriptEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { withApollo } from "@apollo/client/react/hoc";
import { blue, green, grey, orange, red } from "@material-ui/core/colors";
import type { CampaignVariable } from "@spoke/spoke-codegen";
import { IsValidAttachmentDocument } from "@spoke/spoke-codegen";
import { getCharCount } from "@trt2/gsm-charset-utils";
import type { ContentBlock } from "draft-js";
import {
CompositeDecorator,
Expand All @@ -14,7 +13,7 @@ import {
import escapeRegExp from "lodash/escapeRegExp";
import React from "react";

import { replaceEasyGsmWins } from "../lib/charset-utils";
import { getSpokeCharCount, replaceEasyGsmWins } from "../lib/charset-utils";
import { delimit, getAttachmentLink, getMessageType } from "../lib/scripts";
import baseTheme from "../styles/theme";
import Chip from "./Chip";
Expand Down Expand Up @@ -369,7 +368,7 @@ class ScriptEditor extends React.Component<Props, State> {

render() {
const text = this.state.editorState.getCurrentContent().getPlainText();
const info = getCharCount(replaceEasyGsmWins(text));
const info = getSpokeCharCount(text);
const messageType = getMessageType(text);

return (
Expand Down
5 changes: 5 additions & 0 deletions src/lib/charset-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getCharCount } from "@trt2/gsm-charset-utils";

const gsmReplacements = [
["‘", "'"],
["’", "'"],
Expand All @@ -13,5 +15,8 @@ export const replaceEasyGsmWins = (text: string) =>
text
);

export const getSpokeCharCount = (text: string) =>
getCharCount(replaceEasyGsmWins(text));

export const replaceCurlyApostrophes = (rawText: string) =>
rawText.replace(/[\u2018\u2019]/g, "'");

0 comments on commit 9f97f8d

Please sign in to comment.