File size: 3,447 Bytes
21fe460
 
0d872e9
21fe460
 
0d872e9
21fe460
 
 
 
 
9ee3555
 
 
 
 
21fe460
9ee3555
0d872e9
aca9d3a
deff3f3
 
 
 
 
 
9ee3555
21fe460
 
9ee3555
 
 
 
0d872e9
94c7310
9ee3555
94c7310
9ee3555
 
 
 
94c7310
9ee3555
94c7310
9ee3555
94c7310
 
9ee3555
94c7310
9ee3555
 
 
 
94c7310
9ee3555
94c7310
9ee3555
deff3f3
21fe460
 
 
 
deff3f3
 
 
0d872e9
9ee3555
 
deff3f3
 
 
 
21fe460
aca9d3a
 
 
 
 
 
4f6cc65
aca9d3a
9ee3555
aca9d3a
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import streamlit as st

from utils.time_utils import compute_end_time, format_time


def render_card(index: int, on_save, on_delete, rank_tone: str) -> None:
    card = st.session_state.cards[index]
    title_key = f"title_{index}"
    hour_key = f"hour_{index}"
    minute_key = f"minute_{index}"

    current_hour = f"{int(st.session_state.get(hour_key, card['startHour'])):02d}"
    current_minute = f"{int(st.session_state.get(minute_key, card['startMinute'])):02d}"
    end_hour, end_minute = compute_end_time(current_hour, current_minute)
    card["endHour"] = end_hour
    card["endMinute"] = end_minute

    with st.container(border=True):
        st.markdown(f'<div class="card-rank-marker card-rank-{rank_tone}"></div>', unsafe_allow_html=True)
        title_col, status_col = st.columns([1.8, 0.42])
        with title_col:
            card["title"] = st.text_input(
                "Title",
                value=card["title"],
                key=title_key,
                placeholder="Morning Shift",
                label_visibility="collapsed",
            )

        with status_col:
            badge = "Saved" if card.get("id") else "Draft"
            st.markdown(f'<div class="card-status">{badge}</div>', unsafe_allow_html=True)

        hour_col, minute_col, end_col, save_col, delete_col = st.columns([0.46, 0.46, 0.8, 0.62, 0.62])
        with hour_col:
            hour_value = st.number_input(
                "Hour",
                min_value=0,
                max_value=23,
                value=int(current_hour),
                step=1,
                key=hour_key,
                label_visibility="collapsed",
            )
            card["startHour"] = f"{hour_value:02d}"

        with minute_col:
            minute_value = st.number_input(
                "Minute",
                min_value=0,
                max_value=59,
                value=int(current_minute),
                step=1,
                key=minute_key,
                label_visibility="collapsed",
            )
            card["startMinute"] = f"{minute_value:02d}"

        end_hour, end_minute = compute_end_time(card["startHour"], card["startMinute"])
        card["endHour"] = end_hour
        card["endMinute"] = end_minute

        with end_col:
            st.markdown(
                f"""
                <div class="end-time-inline end-time-inline-accent">
                    <div class="end-time-inline-label">End</div>
                    <div class="end-time-inline-value">{format_time(end_hour, end_minute)}</div>
                </div>
                """,
                unsafe_allow_html=True,
            )

        with save_col:
            st.markdown('<div class="secondary-action compact-button">', unsafe_allow_html=True)
            st.button(
                "Update" if card.get("id") else "Save",
                key=f"save_{index}",
                use_container_width=True,
                on_click=on_save,
                args=(index,),
            )
            st.markdown("</div>", unsafe_allow_html=True)
        with delete_col:
            st.markdown('<div class="danger-action compact-button">', unsafe_allow_html=True)
            st.button(
                "Delete",
                key=f"delete_{index}",
                use_container_width=True,
                on_click=on_delete,
                args=(index,),
            )
            st.markdown("</div>", unsafe_allow_html=True)