Skip to content

Commit

Permalink
Refactor showScoreAlert, preserve line breaks in alert
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Jun 29, 2023
1 parent 2855437 commit 2f9d8ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/features/user/Scores.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,25 @@ export default function Scores({ aggregates, accountCreated }: ScoreProps) {

const postScore = aggregates.post_score;
const commentScore = aggregates.comment_score;
const totalScore = postScore + commentScore;

const showScoreAlert = async (focus: "post" | "comment") => {
const subHeader = `${focus === "post" ? commentScore : postScore} ${
focus === "post" ? "Comment" : "Post"
} Points`;
const message = `${postScore + commentScore} Total Points`;
const postPointsLine = `${postScore.toLocaleString()} Post Points`;
const commentPointsLine = `${commentScore.toLocaleString()} Comment Points`;

const totalScoreLine = `${totalScore.toLocaleString()} Total Points`;

const header = focus === "post" ? postPointsLine : commentPointsLine;

const message = [
focus === "post" ? commentPointsLine : postPointsLine,
totalScoreLine,
];

await present({
header: `${focus === "post" ? postScore : commentScore} ${focus} points`,
htmlAttributes: { style: "white-space: pre-line;" },
subHeader,
message,
header,
cssClass: "preserve-newlines",
message: message.join("\n"),
buttons: [{ text: "OK" }],
});
};
Expand Down
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ ion-modal.small {
ion-modal.small ion-header ion-toolbar:first-of-type {
padding-top: 0px;
}

ion-alert.preserve-newlines {
white-space: pre-line;
}

0 comments on commit 2f9d8ca

Please sign in to comment.