bluesky-explorer / app /ui /components.py
jccolon's picture
Upload 21 files
ffac8cc verified
from __future__ import annotations
import streamlit as st
from config.settings import MAX_POSTS_WARNING
from app.client_manager import is_logged_in, login, logout, set_client
def render_login_sidebar():
st.sidebar.header("Acceso a Bluesky")
if not is_logged_in():
handle = st.sidebar.text_input("Handle", "", key="login_handle")
app_password = st.sidebar.text_input("App Password", type="password", key="login_password")
if st.sidebar.button("Iniciar sesi贸n", key="btn_login"):
try:
client = login(handle, app_password)
set_client(client, handle)
st.sidebar.success("Autenticado correctamente.")
st.rerun()
except Exception:
st.sidebar.error("Usuario o contrase帽a incorrectos.")
else:
st.sidebar.success(f"Sesi贸n iniciada como {st.session_state.get('bsky_handle')}")
if st.sidebar.button("Cerrar sesi贸n", key="btn_logout"):
logout()
st.rerun()
def render_search_form():
st.sidebar.header("Configuraci贸n de b煤squeda")
with st.sidebar.form("search_form", clear_on_submit=False):
topic = st.text_input("T茅rmino", value="apag贸n", key="search_topic")
days_back = st.slider("D铆as atr谩s", 7, 365, 30, key="search_days_back")
max_posts = st.number_input("M谩ximo de posts", 1, 30000, 1000, key="search_max_posts")
operator = st.radio("Operador", ["AND", "OR"], horizontal=True, key="search_operator")
require_confirm = max_posts > MAX_POSTS_WARNING
if require_confirm:
st.warning(f"馃毃 Has solicitado {int(max_posts)} publicaciones. Puede ralentizar el proceso.", icon="鈿狅笍")
confirm_heavy = st.checkbox("Entiendo el aviso y deseo continuar", key="search_confirm_heavy")
else:
confirm_heavy = True
submitted = st.form_submit_button("Buscar", use_container_width=True, type="primary")
return submitted, str(topic).strip(), int(days_back), int(max_posts), operator, bool(require_confirm), bool(confirm_heavy)