Skip to content

Commit

Permalink
fix(chat): fix downloading without extension and name of code block (…
Browse files Browse the repository at this point in the history
…Issue #2867, #2868) (#2869)
  • Loading branch information
IlyaBondar authored Dec 24, 2024
1 parent f41850e commit 4a368cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions apps/chat/src/components/Markdown/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export const CodeBlock: FC<Props> = memo(
}, 2000);
});
}, [value]);

const displayLanguage = languageNameMapping[language] || language;
const lowercaseLanguage = language.toLowerCase();
const displayLanguage =
languageNameMapping[lowercaseLanguage] || lowercaseLanguage;

const downloadAsFile = useCallback(() => {
// languageExtensionMapping allows set empty extension
Expand All @@ -80,7 +81,7 @@ export const CodeBlock: FC<Props> = memo(
return;
}

const blob = new Blob([value], { type: 'text/plain' });
const blob = new Blob([value], { type: 'attachment/plain' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.download = fileName;
Expand All @@ -107,7 +108,7 @@ export const CodeBlock: FC<Props> = memo(
: 'border-secondary bg-layer-1',
)}
>
<span className="lowercase">{displayLanguage}</span>
<span>{lowercaseLanguage}</span>

{!isLastMessageStreaming && (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const rootSelector = (state: RootState): ConversationsState =>
state.conversations;

export const selectConversations = (state: RootState): ConversationInfo[] =>
state.conversations.conversations;
rootSelector(state).conversations;

export const selectNotExternalConversations = createSelector(
[selectConversations],
Expand Down
4 changes: 2 additions & 2 deletions apps/chat/src/utils/app/folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const getNextDefaultName = (
parentFolderId?: string,
): string => {
const prefix = `${defaultName} `;
const regex = new RegExp(`^${escapeRegExp(prefix)}(\\d+)$`);
const regex = new RegExp(`^${escapeRegExp(prefix)}(\\d{1,7})$`);

if (!entities.length && !index) {
return !startWithEmptyPostfix ? `${prefix}${1 + index}` : defaultName;
Expand Down Expand Up @@ -165,7 +165,7 @@ export const generateNextName = (
entities: ShareEntity[],
index = 0,
) => {
const regex = new RegExp(`^${defaultName} (\\d+)$`);
const regex = new RegExp(`^${defaultName} (\\d{1,7})$`);
return currentName.match(regex)
? getNextDefaultName(defaultName, entities, index)
: getNextDefaultName(currentName, entities, index, true);
Expand Down

0 comments on commit 4a368cf

Please sign in to comment.