Skip to content

Commit

Permalink
fix: display source list to confirm on /add just like source list on …
Browse files Browse the repository at this point in the history
…/list
  • Loading branch information
sparky-raccoon committed Jan 15, 2024
1 parent f887ae3 commit f632434
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/utils/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { blockQuote } from "discord.js";
import { Source, SourceCreation } from "@/bdd/models/source";
import { Tag, TagCreation } from "@/bdd/models/tag";
import { isSource, isTag } from "./types";
import { isSource, isSourceCreation, isTag } from "./types";

const formatSourceToBlockQuote = (source: Source | SourceCreation): `>>> ${string}` => {
const { type, name, url } = source;
Expand All @@ -22,12 +22,12 @@ const formatSourceListToBlockQuotes = (list: (Source | SourceCreation)[]): strin
return blockQuote(description);
};

const formatFullListToDescription = (list: (Source | Tag)[]): string => {
const formatFullListToDescription = (list: (Source | SourceCreation | Tag)[]): string => {
let description = "";
type ByTypeSourceList = { [type: string]: { name: string; url: string }[] };

const byTypeSourceList = list.reduce((acc: ByTypeSourceList, sourceOrTag) => {
if (isSource(sourceOrTag)) {
if (isSource(sourceOrTag) || isSourceCreation(sourceOrTag)) {
const { type, name, url } = sourceOrTag;
const formattedType = `Flux ${type?.toUpperCase() || "RSS"}`;
if (!acc[formattedType]) acc[formattedType] = [];
Expand Down
6 changes: 3 additions & 3 deletions src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ const getMessage = (type: Message, data?: MessageData) => {
if (isSourceCreationList(toAdd) && isSourceList(existing)) {
title += ADD_SOURCE_TITLE;
description =
"Tu es sur le point d'ajouter le.s source.s suivante.s :\n\n" +
formatSourceListToBlockQuotes(toAdd) +
`Tu es sur le point d'ajouter la.s source.s suivante.s :\n\n` +
formatFullListToDescription(toAdd) +
(existing.length > 0
? "\nLe.s source.s suivante.s ont déjà été configuré.es :\n\n" +
formatSourceListToBlockQuotes(existing)
formatFullListToDescription(existing)
: "");
component = confirmOrCancelButton();
} else if (isTagCreationList(toAdd) && isTagList(existing)) {
Expand Down

0 comments on commit f632434

Please sign in to comment.