Skip to content

Commit

Permalink
fix: translations in production
Browse files Browse the repository at this point in the history
  • Loading branch information
ImLunaHey committed Jan 9, 2025
1 parent 439af25 commit 2221da0
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/components/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
UserRoundPlusIcon,
VolumeOffIcon,
} from 'lucide-react';
import { useNavigate } from '@tanstack/react-router';
import { useLocation, useNavigate } from '@tanstack/react-router';
import { MessageCircle, Heart, Repeat } from 'lucide-react';
import { useLike } from '../lib/bluesky/hooks/useLike';
import { BSkyPost } from '../lib/bluesky/types/BSkyPost';
Expand Down Expand Up @@ -61,20 +61,19 @@ const BetterContext = ({ context }: { context?: string }) => {
};

const PostDropdownMenu = ({ post, setTranslatedText }: { post: BSkyPost; setTranslatedText: (text: string) => void }) => {
const location = useLocation();
const isProd = new URL(location.href).hostname === 'akari.blue';
const handleTranslate = async (event: React.MouseEvent<HTMLDivElement>) => {
event.stopPropagation();
const response = await fetch(
process.env.NODE_ENV === 'production' ? 'https://translate.akari.blue' : 'http://localhost:8787',
{
method: 'POST',
body: JSON.stringify({
q: post.record.text,
source: post.record.langs?.[0] ?? 'auto',
target: navigator.language,
}),
headers: { 'Content-Type': 'application/json' },
},
);
const response = await fetch(isProd ? 'https://translate.akari.blue' : 'http://localhost:8787', {
method: 'POST',
body: JSON.stringify({
q: post.record.text,
source: post.record.langs?.[0] ?? 'auto',
target: navigator.language,
}),
headers: { 'Content-Type': 'application/json' },
});
const json = (await response.json()) as {
alternatives: [];
detectedLanguage: {
Expand Down

0 comments on commit 2221da0

Please sign in to comment.