Dmitry Beresnev
commited on
Commit
·
2da1d42
1
Parent(s):
535bdb9
fix news UI
Browse files- app/components/news.py +61 -67
app/components/news.py
CHANGED
|
@@ -161,24 +161,16 @@ def display_scrollable_news_section(df: pd.DataFrame, section_title: str, sectio
|
|
| 161 |
""", unsafe_allow_html=True)
|
| 162 |
return
|
| 163 |
|
| 164 |
-
# Build header HTML
|
| 165 |
-
header_html = f"""
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
<div>
|
| 175 |
-
<h3 style="color: #D1D4DC; margin: 0; font-size: 18px; font-weight: 600;">{section_icon} {section_title}</h3>
|
| 176 |
-
<p style="color: #787B86; margin: 4px 0 0 0; font-size: 12px;">{section_subtitle}</p>
|
| 177 |
-
</div>
|
| 178 |
-
<div style="background: rgba(56, 97, 251, 0.15); color: #3861FB; padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;">{len(df.head(max_items))} stories</div>
|
| 179 |
-
</div>
|
| 180 |
-
</div>
|
| 181 |
-
"""
|
| 182 |
|
| 183 |
# Render header
|
| 184 |
st.markdown(header_html, unsafe_allow_html=True)
|
|
@@ -213,55 +205,57 @@ def display_scrollable_news_section(df: pd.DataFrame, section_title: str, sectio
|
|
| 213 |
|
| 214 |
sentiment_symbol = '▲' if news_item['sentiment'] == 'positive' else '▼' if news_item['sentiment'] == 'negative' else '●'
|
| 215 |
|
| 216 |
-
# Build card HTML
|
| 217 |
-
news_cards_html += f"""
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
| 265 |
|
| 266 |
st.markdown(scrollable_html, unsafe_allow_html=True)
|
| 267 |
|
|
|
|
| 161 |
""", unsafe_allow_html=True)
|
| 162 |
return
|
| 163 |
|
| 164 |
+
# Build header HTML (no leading whitespace)
|
| 165 |
+
header_html = f"""<div style="background: linear-gradient(135deg, #2A2E39 0%, #1E222D 100%); border: 1px solid #363A45; border-radius: 8px 8px 0 0; padding: 16px 20px; margin-bottom: 0;">
|
| 166 |
+
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 167 |
+
<div>
|
| 168 |
+
<h3 style="color: #D1D4DC; margin: 0; font-size: 18px; font-weight: 600;">{section_icon} {section_title}</h3>
|
| 169 |
+
<p style="color: #787B86; margin: 4px 0 0 0; font-size: 12px;">{section_subtitle}</p>
|
| 170 |
+
</div>
|
| 171 |
+
<div style="background: rgba(56, 97, 251, 0.15); color: #3861FB; padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;">{len(df.head(max_items))} stories</div>
|
| 172 |
+
</div>
|
| 173 |
+
</div>"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
# Render header
|
| 176 |
st.markdown(header_html, unsafe_allow_html=True)
|
|
|
|
| 205 |
|
| 206 |
sentiment_symbol = '▲' if news_item['sentiment'] == 'positive' else '▼' if news_item['sentiment'] == 'negative' else '●'
|
| 207 |
|
| 208 |
+
# Build card HTML (no leading whitespace)
|
| 209 |
+
news_cards_html += f"""<div style="background: linear-gradient(135deg, #1E222D 0%, #131722 100%); border: 1px solid #2A2E39; border-radius: 8px; padding: 16px; margin-bottom: 12px; transition: all 0.2s ease; cursor: pointer; position: relative; overflow: hidden;" onmouseover="this.style.borderColor='#3861FB'; this.style.transform='translateY(-2px)'; this.style.boxShadow='0 4px 12px rgba(56, 97, 251, 0.15)';" onmouseout="this.style.borderColor='#2A2E39'; this.style.transform='translateY(0)'; this.style.boxShadow='none';">
|
| 210 |
+
<div style="position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: {impact_color};"></div>
|
| 211 |
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; margin-left: 8px;">
|
| 212 |
+
<div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
|
| 213 |
+
<span style="color: #3861FB; font-weight: 600; font-size: 13px; font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;">{source}</span>
|
| 214 |
+
<span style="background: {impact_color}; color: white; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; letter-spacing: 0.5px;">{news_item['impact'].upper()}</span>
|
| 215 |
+
<span style="color: {sentiment_color}; font-size: 11px; font-weight: 600; padding: 2px 6px; border: 1px solid {sentiment_color}; border-radius: 4px;">{sentiment_symbol} {news_item['sentiment'].upper()}</span>
|
| 216 |
+
<span style="color: #787B86; font-size: 11px; background: rgba(120, 123, 134, 0.1); padding: 2px 6px; border-radius: 4px;">#{category}</span>
|
| 217 |
+
</div>
|
| 218 |
+
<span style="color: #787B86; font-size: 11px; white-space: nowrap;">{time_ago}</span>
|
| 219 |
+
</div>
|
| 220 |
+
<div style="color: #D1D4DC; font-size: 14px; line-height: 1.5; margin-bottom: 8px; margin-left: 8px; font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;">{summary}</div>
|
| 221 |
+
<a href="{url}" target="_blank" style="color: #3861FB; font-size: 12px; text-decoration: none; margin-left: 8px; display: inline-flex; align-items: center; gap: 4px; font-weight: 500;" onmouseover="this.style.color='#5880FF';" onmouseout="this.style.color='#3861FB';">Read Full Story →</a>
|
| 222 |
+
</div>
|
| 223 |
+
"""
|
| 224 |
+
|
| 225 |
+
# Generate unique class name to avoid conflicts
|
| 226 |
+
import random
|
| 227 |
+
unique_id = f"news-scroll-{random.randint(10000, 99999)}"
|
| 228 |
+
|
| 229 |
+
# Render scrollable container with all news cards using st.markdown (no leading whitespace)
|
| 230 |
+
scrollable_html = f"""<style>
|
| 231 |
+
.{unique_id} {{
|
| 232 |
+
height: {height};
|
| 233 |
+
overflow-y: auto;
|
| 234 |
+
background: #0D0E13;
|
| 235 |
+
border: 1px solid #2A2E39;
|
| 236 |
+
border-top: none;
|
| 237 |
+
border-radius: 0 0 8px 8px;
|
| 238 |
+
padding: 16px;
|
| 239 |
+
}}
|
| 240 |
+
.{unique_id}::-webkit-scrollbar {{
|
| 241 |
+
width: 8px;
|
| 242 |
+
}}
|
| 243 |
+
.{unique_id}::-webkit-scrollbar-track {{
|
| 244 |
+
background: #1E222D;
|
| 245 |
+
border-radius: 4px;
|
| 246 |
+
}}
|
| 247 |
+
.{unique_id}::-webkit-scrollbar-thumb {{
|
| 248 |
+
background: #363A45;
|
| 249 |
+
border-radius: 4px;
|
| 250 |
+
}}
|
| 251 |
+
.{unique_id}::-webkit-scrollbar-thumb:hover {{
|
| 252 |
+
background: #434651;
|
| 253 |
+
}}
|
| 254 |
+
</style>
|
| 255 |
+
<div class="{unique_id}">
|
| 256 |
+
{news_cards_html}
|
| 257 |
+
</div>
|
| 258 |
+
"""
|
| 259 |
|
| 260 |
st.markdown(scrollable_html, unsafe_allow_html=True)
|
| 261 |
|