Skip to content

Commit

Permalink
fix: Changed the timestamp in the OSSGPT dialog to the correct format (
Browse files Browse the repository at this point in the history
…#822)

* fix: modify the timestamp format of oss-gpt

* add yarn.lock file
  • Loading branch information
wj23027 authored May 27, 2024
1 parent a07fc4b commit 6ae3577
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"github-url-detection": "^8.1.0",
"jquery": "^3.6.0",
"lodash-es": "^4.17.21",
"moment": "^2.30.1",
"react": "^17.0.2",
"react-chat-widget": "^3.1.4",
"react-dom": "^17.0.2",
Expand Down
25 changes: 25 additions & 0 deletions src/pages/ContentScripts/features/oss-gpt/view.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState, useEffect, useRef } from 'react';
import $ from 'jquery';
import moment from 'moment';
import {
Widget,
addResponseMessage,
deleteMessages,
toggleMsgLoader,
toggleInputDisabled,
renderCustomComponent,
} from 'react-chat-widget';

import { getAnswer } from './service';
Expand All @@ -23,21 +25,40 @@ interface Props {
currentDocsName: string | null;
}

const ResponseTimeStamp: React.FC = () => {
return (
<div style={{ fontSize: '11px', marginLeft: '50px' }}>
{moment().format('LT')}
</div>
);
};

const UserTimeStamp: React.FC = () => {
return (
<div style={{ fontSize: '11px', textAlign: 'right', width: '100%' }}>
{moment().format('LT')}
</div>
);
};

const displayWelcome = (repoName: string, locale: string) => {
addResponseMessage(
getMessageByLocale('OSS_GPT_welcome', locale).replace('%v', repoName)
);
renderCustomComponent(ResponseTimeStamp, {});
};

const displayNotAvailable = (repoName: string, locale: string) => {
addResponseMessage(
getMessageByLocale('OSS_GPT_notAvailable', locale).replace('%v', repoName)
);
renderCustomComponent(ResponseTimeStamp, {});
};

// Due to cost reasons, backend is not available now. This part can be removed when the backend is restored.
const backendNotAvailable = (locale: string) => {
addResponseMessage(getMessageByLocale('OSS_GPT_errorMessage', locale));
renderCustomComponent(ResponseTimeStamp, {});
};

const View = ({ theme, currentRepo, currentDocsName }: Props): JSX.Element => {
Expand Down Expand Up @@ -132,6 +153,7 @@ const View = ({ theme, currentRepo, currentDocsName }: Props): JSX.Element => {
).replace('%v', currentRepo);

const handleNewUserMessage = async (newMessage: string) => {
renderCustomComponent(UserTimeStamp, {});
toggleMsgLoader();
toggleInputDisabled();

Expand All @@ -141,6 +163,8 @@ const View = ({ theme, currentRepo, currentDocsName }: Props): JSX.Element => {
backendNotAvailable(options.locale);
} else {
addResponseMessage(answer);
renderCustomComponent(ResponseTimeStamp, {});

setHistory([newMessage, answer]); // update history
}
} else {
Expand All @@ -160,6 +184,7 @@ const View = ({ theme, currentRepo, currentDocsName }: Props): JSX.Element => {
handleNewUserMessage={handleNewUserMessage}
showBadge={false}
profileAvatar={chrome.runtime.getURL('main.png')}
showTimeStamp={false}
/>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4162,6 +4162,11 @@ mkdirp@^1.0.4:
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

moment@^2.30.1:
version "2.30.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==

mri@^1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz#6721480fec2a11a4889861115a48b6cbe7cc8f0b"
Expand Down

0 comments on commit 6ae3577

Please sign in to comment.