Skip to content

Commit

Permalink
Merge pull request #78 from animalnots/dev
Browse files Browse the repository at this point in the history
v1.14.0
  • Loading branch information
animalnots authored Nov 5, 2024
2 parents 8c768cd + 42edc0d commit ac5050c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "better-chatgpt",
"private": true,
"version": "1.13.0",
"version": "1.14.0",
"type": "module",
"homepage": "./",
"main": "electron/index.cjs",
Expand Down
45 changes: 24 additions & 21 deletions src/components/Chat/ChatContent/Message/View/ContentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
ChatInterface,
ContentInterface,
ImageContentInterface,
TextContentInterface,
isImageContent,
isTextContent,
} from '@type/chat';

import { codeLanguageSubset } from '@constants/chat';
Expand Down Expand Up @@ -106,9 +107,9 @@ const ContentView = memo(
setChats(updatedChats);
handleSubmit();
};

const currentTextContent = isTextContent(content[0]) ? content[0].text : '';
const handleCopy = () => {
navigator.clipboard.writeText((content[0] as TextContentInterface).text);
navigator.clipboard.writeText(currentTextContent);
};

const handleImageClick = (imageUrl: string) => {
Expand All @@ -118,7 +119,9 @@ const ContentView = memo(
const handleCloseZoom = () => {
setZoomedImage(null);
};

const validImageContents = content
.slice(1)
.filter(isImageContent) as ImageContentInterface[];
return (
<>
<div className='markdown prose w-full md:max-w-full break-words dark:prose-invert dark share-gpt-message'>
Expand Down Expand Up @@ -146,27 +149,27 @@ const ContentView = memo(
}}
>
{inlineLatex
? preprocessLaTeX((content[0] as TextContentInterface).text)
: (content[0] as TextContentInterface).text}
? preprocessLaTeX(currentTextContent)
: currentTextContent}
</ReactMarkdown>
) : (
<span className='whitespace-pre-wrap'>
{(content[0] as TextContentInterface).text}
</span>
<span className='whitespace-pre-wrap'>{currentTextContent}</span>
)}
</div>
<div className='flex gap-4'>
{(content.slice(1) as ImageContentInterface[]).map((image, index) => (
<div key={index} className='image-container'>
<img
src={image.image_url.url}
alt={`uploaded-${index}`}
className='h-20 cursor-pointer'
onClick={() => handleImageClick(image.image_url.url)}
/>
</div>
))}
</div>
{validImageContents.length > 0 && (
<div className='flex gap-4'>
{validImageContents.map((image, index) => (
<div key={index} className='image-container'>
<img
src={image.image_url.url}
alt={`uploaded-${index}`}
className='h-20 cursor-pointer'
onClick={() => handleImageClick(image.image_url.url)}
/>
</div>
))}
</div>
)}
{zoomedImage && (
<PopupModal
title=''
Expand Down
9 changes: 5 additions & 4 deletions src/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export function strToTextContent(ob: string): TextContentInterface {
};
}

export function isTextContent(ob: ContentInterface): ob is TextContentInterface {
return (ob as TextContentInterface).text !== undefined;
export function isTextContent(ob: ContentInterface | undefined): ob is TextContentInterface {
return ob !== undefined && ob !== null && (ob as TextContentInterface).text !== undefined;
}
export function isImageContent(ob: ContentInterface): ob is ImageContentInterface {
return (ob as ImageContentInterface).image_url !== undefined;

export function isImageContent(ob: ContentInterface | undefined): ob is ImageContentInterface {
return ob !== undefined && ob !== null && (ob as ImageContentInterface).image_url !== undefined;
}

export interface ContentInterface {
Expand Down

0 comments on commit ac5050c

Please sign in to comment.