Add translation for chat section

This commit is contained in:
Nicola Benaglia 2025-05-16 19:03:08 +02:00
parent 30b5d1e36b
commit 0759994891
4 changed files with 56 additions and 39 deletions

View File

@ -1,4 +1,4 @@
import React, { useMemo, useRef, useState } from 'react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import TipTap from './TipTap'; import TipTap from './TipTap';
import { import {
AuthenticatedContainerInnerTop, AuthenticatedContainerInnerTop,
@ -8,7 +8,7 @@ import { Box, CircularProgress, useTheme } from '@mui/material';
import { objectToBase64 } from '../../qdn/encryption/group-encryption'; import { objectToBase64 } from '../../qdn/encryption/group-encryption';
import ShortUniqueId from 'short-unique-id'; import ShortUniqueId from 'short-unique-id';
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar'; import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
import { getBaseApi, getFee } from '../../background'; import { getFee } from '../../background';
import { import {
decryptPublishes, decryptPublishes,
getTempPublish, getTempPublish,
@ -24,6 +24,7 @@ import {
pauseAllQueues, pauseAllQueues,
resumeAllQueues, resumeAllQueues,
} from '../../App'; } from '../../App';
import { useTranslation } from 'react-i18next';
const tempKey = 'accouncement-comment'; const tempKey = 'accouncement-comment';
@ -39,10 +40,10 @@ export const AnnouncementDiscussion = ({
isPrivate, isPrivate,
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(['auth', 'core', 'group']);
const [isSending, setIsSending] = useState(false); const [isSending, setIsSending] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [isFocusedParent, setIsFocusedParent] = useState(false); const [isFocusedParent, setIsFocusedParent] = useState(false);
const [comments, setComments] = useState([]); const [comments, setComments] = useState([]);
const [tempPublishedList, setTempPublishedList] = useState([]); const [tempPublishedList, setTempPublishedList] = useState([]);
const firstMountRef = useRef(false); const firstMountRef = useRef(false);
@ -100,7 +101,12 @@ export const AnnouncementDiscussion = ({
rej(response.error); rej(response.error);
}) })
.catch((error) => { .catch((error) => {
rej(error.message || 'An error occurred'); rej(
error.message ||
t('core:message.error.generic', {
postProcess: 'capitalizeFirst',
})
);
}); });
}); });
} catch (error) { } catch (error) {
@ -131,9 +137,13 @@ export const AnnouncementDiscussion = ({
pauseAllQueues(); pauseAllQueues();
const fee = await getFee('ARBITRARY'); const fee = await getFee('ARBITRARY');
await show({ await show({
message: 'Would you like to perform a ARBITRARY transaction?', message: t('core:question.perform_transaction', {
action: 'ARBITRARY',
postProcess: 'capitalizeFirst',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
if (isSending) return; if (isSending) return;
if (editorRef.current) { if (editorRef.current) {
const htmlContent = editorRef.current.getHTML(); const htmlContent = editorRef.current.getHTML();
@ -155,10 +165,11 @@ export const AnnouncementDiscussion = ({
: await encryptChatMessage(message64, secretKeyObject); : await encryptChatMessage(message64, secretKeyObject);
const randomUid = uid.rnd(); const randomUid = uid.rnd();
const identifier = `cm-${selectedAnnouncement.identifier}-${randomUid}`; const identifier = `cm-${selectedAnnouncement.identifier}-${randomUid}`;
const res = await publishAnc({ const res = await publishAnc({
encryptedData: encryptSingle, encryptedData: encryptSingle,
identifier, identifier,
}); }); // TODO remove unused?
const dataToSaveToStorage = { const dataToSaveToStorage = {
name: myName, name: myName,
@ -168,12 +179,13 @@ export const AnnouncementDiscussion = ({
created: Date.now(), created: Date.now(),
announcementId: selectedAnnouncement.identifier, announcementId: selectedAnnouncement.identifier,
}; };
await saveTempPublish({ data: dataToSaveToStorage, key: tempKey }); await saveTempPublish({ data: dataToSaveToStorage, key: tempKey });
setTempData(); setTempData();
clearEditorContent(); clearEditorContent();
} }
// send chat message // TODO send chat message
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {
@ -182,14 +194,12 @@ export const AnnouncementDiscussion = ({
} }
}; };
const getComments = React.useCallback( const getComments = useCallback(
async (selectedAnnouncement, isPrivate) => { async (selectedAnnouncement, isPrivate) => {
try { try {
setIsLoading(true); setIsLoading(true);
const offset = 0; const offset = 0;
// dispatch(setIsLoadingGlobal(true))
const identifier = `cm-${selectedAnnouncement.identifier}`; const identifier = `cm-${selectedAnnouncement.identifier}`;
const url = `${getBaseApiReact()}${getArbitraryEndpointReact()}?mode=ALL&service=DOCUMENT&identifier=${identifier}&limit=20&includemetadata=false&offset=${offset}&reverse=true&prefix=true`; const url = `${getBaseApiReact()}${getArbitraryEndpointReact()}?mode=ALL&service=DOCUMENT&identifier=${identifier}&limit=20&includemetadata=false&offset=${offset}&reverse=true&prefix=true`;
const response = await fetch(url, { const response = await fetch(url, {
@ -209,8 +219,6 @@ export const AnnouncementDiscussion = ({
console.log(error); console.log(error);
} finally { } finally {
setIsLoading(false); setIsLoading(false);
// dispatch(setIsLoadingGlobal(false))
} }
}, },
[secretKey] [secretKey]
@ -259,7 +267,7 @@ export const AnnouncementDiscussion = ({
return sortedList; return sortedList;
}, [tempPublishedList, comments]); }, [tempPublishedList, comments]);
React.useEffect(() => { useEffect(() => {
if (!secretKey && isPrivate) return; if (!secretKey && isPrivate) return;
if (selectedAnnouncement && !firstMountRef.current && isPrivate !== null) { if (selectedAnnouncement && !firstMountRef.current && isPrivate !== null) {
getComments(selectedAnnouncement, isPrivate); getComments(selectedAnnouncement, isPrivate);
@ -299,6 +307,7 @@ export const AnnouncementDiscussion = ({
<Spacer height="20px" /> <Spacer height="20px" />
</div> </div>
<AnnouncementList <AnnouncementList
announcementData={data} announcementData={data}
initialMessages={combinedListTempAndReal} initialMessages={combinedListTempAndReal}
@ -308,6 +317,7 @@ export const AnnouncementDiscussion = ({
loadMore={loadMore} loadMore={loadMore}
myName={myName} myName={myName}
/> />
<div <div
style={{ style={{
backgroundColor: theme.palette.background.default, backgroundColor: theme.palette.background.default,
@ -343,6 +353,7 @@ export const AnnouncementDiscussion = ({
setIsFocusedParent={setIsFocusedParent} setIsFocusedParent={setIsFocusedParent}
/> />
</div> </div>
<Box <Box
sx={{ sx={{
display: 'flex', display: 'flex',
@ -359,7 +370,7 @@ export const AnnouncementDiscussion = ({
if (isSending) return; if (isSending) return;
setIsFocusedParent(false); setIsFocusedParent(false);
clearEditorContent(); clearEditorContent();
// Unfocus the editor // TODO Unfocus the editor
}} }}
style={{ style={{
alignSelf: 'center', alignSelf: 'center',
@ -371,7 +382,7 @@ export const AnnouncementDiscussion = ({
padding: '5px', padding: '5px',
}} }}
> >
{` Close`} {t('core:action.close', { postProcess: 'capitalizeFirst' })}
</CustomButton> </CustomButton>
)} )}
<CustomButton <CustomButton
@ -402,7 +413,9 @@ export const AnnouncementDiscussion = ({
}} }}
/> />
)} )}
{` Publish Comment`} {t('core:action.publish_comment', {
postProcess: 'capitalizeFirst',
})}
</CustomButton> </CustomButton>
</Box> </Box>
</div> </div>
@ -410,7 +423,9 @@ export const AnnouncementDiscussion = ({
<LoadingSnackbar <LoadingSnackbar
open={isLoading} open={isLoading}
info={{ info={{
message: 'Loading comments... please wait.', message: t('core:loading_comments', {
postProcess: 'capitalizeFirst',
}),
}} }}
/> />
</div> </div>

View File

@ -1,14 +1,14 @@
import React, { useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { MessageDisplay } from './MessageDisplay'; import { MessageDisplay } from './MessageDisplay';
import { Avatar, Box, Typography, useTheme } from '@mui/material'; import { Avatar, Box, Typography, useTheme } from '@mui/material';
import { formatTimestamp } from '../../utils/time'; import { formatTimestamp } from '../../utils/time';
import ChatBubbleIcon from '@mui/icons-material/ChatBubble'; import ChatBubbleIcon from '@mui/icons-material/ChatBubble';
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos'; import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
import { getBaseApi } from '../../background';
import { requestQueueCommentCount } from './GroupAnnouncements'; import { requestQueueCommentCount } from './GroupAnnouncements';
import { CustomLoader } from '../../common/CustomLoader'; import { CustomLoader } from '../../common/CustomLoader';
import { getArbitraryEndpointReact, getBaseApiReact } from '../../App'; import { getArbitraryEndpointReact, getBaseApiReact } from '../../App';
import { WrapperUserAction } from '../WrapperUserAction'; import { WrapperUserAction } from '../WrapperUserAction';
import { useTranslation } from 'react-i18next';
export const AnnouncementItem = ({ export const AnnouncementItem = ({
message, message,
@ -18,12 +18,12 @@ export const AnnouncementItem = ({
myName, myName,
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(['auth', 'core', 'group']);
const [commentLength, setCommentLength] = useState(0); const [commentLength, setCommentLength] = useState(0);
const getNumberOfComments = React.useCallback(async () => {
const getNumberOfComments = useCallback(async () => {
try { try {
const offset = 0; const offset = 0;
// dispatch(setIsLoadingGlobal(true))
const identifier = `cm-${message.identifier}`; const identifier = `cm-${message.identifier}`;
const url = `${getBaseApiReact()}${getArbitraryEndpointReact()}?mode=ALL&service=DOCUMENT&identifier=${identifier}&limit=0&includemetadata=false&offset=${offset}&reverse=true&prefix=true`; const url = `${getBaseApiReact()}${getArbitraryEndpointReact()}?mode=ALL&service=DOCUMENT&identifier=${identifier}&limit=0&includemetadata=false&offset=${offset}&reverse=true&prefix=true`;
@ -84,6 +84,7 @@ export const AnnouncementItem = ({
{message?.name?.charAt(0)} {message?.name?.charAt(0)}
</Avatar> </Avatar>
</WrapperUserAction> </WrapperUserAction>
<Box <Box
sx={{ sx={{
display: 'flex', display: 'flex',
@ -106,6 +107,7 @@ export const AnnouncementItem = ({
{message?.name} {message?.name}
</Typography> </Typography>
</WrapperUserAction> </WrapperUserAction>
{!messageData?.decryptedData && ( {!messageData?.decryptedData && (
<Box <Box
sx={{ sx={{
@ -117,6 +119,7 @@ export const AnnouncementItem = ({
<CustomLoader /> <CustomLoader />
</Box> </Box>
)} )}
{messageData?.decryptedData?.message && ( {messageData?.decryptedData?.message && (
<> <>
{messageData?.type === 'notification' ? ( {messageData?.type === 'notification' ? (
@ -150,6 +153,7 @@ export const AnnouncementItem = ({
</Box> </Box>
</Box> </Box>
</Box> </Box>
{!disableComment && ( {!disableComment && (
<Box <Box
sx={{ sx={{
@ -189,10 +193,13 @@ export const AnnouncementItem = ({
fontSize: '14px', fontSize: '14px',
}} }}
> >
Leave comment {t('core:action.leave_comment', {
postProcess: 'capitalizeFirst',
})}
</Typography> </Typography>
)} )}
</Box> </Box>
<ArrowForwardIosIcon <ArrowForwardIosIcon
sx={{ sx={{
fontSize: '20px', fontSize: '20px',

View File

@ -3,6 +3,7 @@ import { CellMeasurerCache } from 'react-virtualized';
import { AnnouncementItem } from './AnnouncementItem'; import { AnnouncementItem } from './AnnouncementItem';
import { Box } from '@mui/material'; import { Box } from '@mui/material';
import { CustomButton } from '../../styles/App-styles'; import { CustomButton } from '../../styles/App-styles';
import { useTranslation } from 'react-i18next';
const cache = new CellMeasurerCache({ const cache = new CellMeasurerCache({
fixedWidth: true, fixedWidth: true,
@ -18,8 +19,8 @@ export const AnnouncementList = ({
loadMore, loadMore,
myName, myName,
}) => { }) => {
const listRef = useRef(null);
const [messages, setMessages] = useState(initialMessages); const [messages, setMessages] = useState(initialMessages);
const { t } = useTranslation(['auth', 'core', 'group']);
useEffect(() => { useEffect(() => {
cache.clearAll(); cache.clearAll();
@ -36,9 +37,9 @@ export const AnnouncementList = ({
flexDirection: 'column', flexDirection: 'column',
flexGrow: 1, flexGrow: 1,
flexShrink: 1, flexShrink: 1,
overflow: 'auto',
position: 'relative', position: 'relative',
width: '100%', width: '100%',
overflow: 'auto',
}} }}
> >
{messages.map((message) => { {messages.map((message) => {
@ -69,19 +70,7 @@ export const AnnouncementList = ({
</div> </div>
); );
})} })}
{/* <AutoSizer>
{({ height, width }) => (
<List
ref={listRef}
width={width}
height={height}
rowCount={messages.length}
rowHeight={cache.rowHeight}
rowRenderer={rowRenderer}
deferredMeasurementCache={cache}
/>
)}
</AutoSizer> */}
<Box <Box
sx={{ sx={{
display: 'flex', display: 'flex',
@ -92,7 +81,9 @@ export const AnnouncementList = ({
> >
{showLoadMore && ( {showLoadMore && (
<CustomButton onClick={loadMore}> <CustomButton onClick={loadMore}>
Load older announcements {t('core:action.load_announcements', {
postProcess: 'capitalizeFirst',
})}
</CustomButton> </CustomButton>
)} )}
</Box> </Box>

View File

@ -31,6 +31,8 @@
"import": "import", "import": "import",
"invite": "invite", "invite": "invite",
"join": "join", "join": "join",
"leave_comment": "leave comment",
"load_announcements": "load older announcements",
"login": "login", "login": "login",
"logout": "logout", "logout": "logout",
"new": { "new": {
@ -46,6 +48,7 @@
"post_message": "post message", "post_message": "post message",
"publish": "publish", "publish": "publish",
"publish_app": "publish your app", "publish_app": "publish your app",
"publish_comment": "publish comment",
"register_name": "register name", "register_name": "register name",
"remove": "remove", "remove": "remove",
"return_apps_dashboard": "return to Apps Dashboard", "return_apps_dashboard": "return to Apps Dashboard",
@ -104,6 +107,7 @@
"member": "member list" "member": "member list"
}, },
"loading": "loading...", "loading": "loading...",
"loading_comments": "loading comments... please wait.",
"loading_posts": "loading posts... please wait.", "loading_posts": "loading posts... please wait.",
"message_us": "please message us on Telegram or Discord if you need 4 QORT to start chatting without any limitations", "message_us": "please message us on Telegram or Discord if you need 4 QORT to start chatting without any limitations",
"message": { "message": {