-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56549 from Expensify/cmartins-useTranslateLive
Cmartins use translate live
- Loading branch information
Showing
7 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
Check failure on line 1 in src/hooks/useTranslateLive.ts
|
||
import {useEffect} from 'react'; | ||
import Onyx, {useOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry, ReportAction} from 'react-native-onyx'; | ||
import * as API from '@libs/API'; | ||
Check failure on line 5 in src/hooks/useTranslateLive.ts
|
||
import useLocalize from './useLocalize'; | ||
Check failure on line 6 in src/hooks/useTranslateLive.ts
|
||
|
||
export default function useTranslateLive(reportID: string, reportAction: OnyxEntry<ReportAction>) { | ||
const {preferredLocale} = useLocalize(); | ||
const [session] = useOnyx(ONYXKEYS.SESSION); | ||
|
||
useEffect(() => { | ||
if (reportAction.message.length > 1) { | ||
return; | ||
} | ||
|
||
if (reportAction.actorAccountID === session?.accountID) { | ||
return; | ||
} | ||
|
||
if (!reportAction?.message?.[0]?.html) { | ||
return; | ||
} | ||
|
||
console.log('over here API call') | ||
API.makeRequestWithSideEffects('Translate', { | ||
type: 'live', | ||
textToTranslate: reportAction?.message?.[0]?.html, | ||
targetLanguage: preferredLocale, | ||
}).then((response) => { | ||
console.log('over here', response) | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, { | ||
[reportAction.reportActionID]: { | ||
message: [{...reportAction?.message[0], translatedText: response.translation}] | ||
} | ||
}); | ||
}); | ||
}, [reportID, reportAction.reportActionID]); | ||
Check warning on line 38 in src/hooks/useTranslateLive.ts
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters