From e7c49cdb1c1dd8884506259aae05b484889a8d98 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 16 Apr 2025 21:55:46 -0700 Subject: frontend: make EN translation viewable --- site/src/components/NewsFeed.tsx | 95 ++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 32 deletions(-) (limited to 'site/src') diff --git a/site/src/components/NewsFeed.tsx b/site/src/components/NewsFeed.tsx index a9b36cf..3057d61 100644 --- a/site/src/components/NewsFeed.tsx +++ b/site/src/components/NewsFeed.tsx @@ -1,3 +1,4 @@ +import { useState } from "react"; import { getGameTitle } from "../utils.ts"; export interface NewsData { @@ -12,6 +13,8 @@ export interface NewsData { image: string; link: string | null; }>; + en_headline: string | null; + en_content: string | null; } interface NewsFeedProps { @@ -19,6 +22,17 @@ interface NewsFeedProps { } export const NewsFeed: React.FC = ({ newsItems }) => { + // Track which items are showing English content + const [showEnglish, setShowEnglish] = useState>({}); + + // Toggle language for a specific news item + const toggleLanguage = (itemId: string) => { + setShowEnglish(prev => ({ + ...prev, + [itemId]: !prev[itemId] + })); + }; + return (
{newsItems.map((news) => { @@ -29,14 +43,21 @@ export const NewsFeed: React.FC = ({ newsItems }) => { }); const gameId = news.identifier; + const newsId = `${news.identifier}-${news.timestamp}-${news.content.substring(0, 20)}`; + const isEnglish = showEnglish[newsId] || false; + const hasTranslation = news.en_headline || news.en_content; + + // Choose content based on language selection + const displayHeadline = isEnglish && news.en_headline ? news.en_headline : news.headline; + const displayContent = isEnglish && news.en_content ? news.en_content : news.content; return (
{/* Header (Game Icon + Info) */} -
+
{/* Game Icon */}
@@ -58,20 +79,30 @@ export const NewsFeed: React.FC = ({ newsItems }) => { )}
+ + {/* Language Toggle Button */} + {hasTranslation && ( + + )}
{/* Content Area */}
{/* Headline */} - {news.headline && ( + {displayHeadline && (

- {news.headline} + {displayHeadline}

)} {/* Content */}

- {news.content.split(/(\[.*?\]\(.*?\)|https?:\/\/[^\s]+)/g).map((part, index) => { + {displayContent.split(/(\[.*?\]\(.*?\)|https?:\/\/[^\s]+)/g).map((part, index) => { const match = part.match(/\[(.*?)\]\((.*?)\)/); const urlMatch = part.match(/https?:\/\/[^\s]+/); if (match) { @@ -93,33 +124,33 @@ export const NewsFeed: React.FC = ({ newsItems }) => {

{/* Post Image(s) */} -
- {news.images.map((img, i) => ( - img.link ? ( - - news visual - - ) : ( -
- news visual -
- ) - ))} -
+
+ {news.images.map((img, i) => ( + img.link ? ( + + news visual + + ) : ( +
+ news visual +
+ ) + ))} +
{/* Footer with Read More Link */} {news.url && ( -- cgit v1.2.3