11from typing import Any
22
33from backend .config .lexicon import SLACK_UI
4+ from backend .models .db_models import Draft
45
56
67def build_draft_card (
@@ -17,7 +18,9 @@ def build_draft_card(
1718 f"{ SLACK_UI ['draft_ready_header' ].format (topic = topic )} | 📢 { platform .upper ()} "
1819 )
1920 if not is_valid :
20- header_text = SLACK_UI ["validation_failed_header" ].format (platform = platform .upper ())
21+ header_text = SLACK_UI ["validation_failed_header" ].format (
22+ platform = platform .upper ()
23+ )
2124
2225 blocks : list [dict [str , Any ]] = [
2326 {
@@ -269,49 +272,98 @@ def build_generation_modal(channel_id: str) -> dict[str, Any]:
269272 }
270273
271274
272- def build_app_home () -> dict [str , Any ]:
273- return {
274- "type" : "home" ,
275- "blocks" : [
276- {
277- "type" : "header" ,
278- "text " : {
279- "type " : "plain_text" ,
280- "text " : SLACK_UI [ "home_welcome" ] ,
281- "emoji " : True ,
282- } ,
275+ def build_app_home (drafts : list [ Draft ] | None = None ) -> dict [str , Any ]:
276+ if drafts is None :
277+ drafts = []
278+
279+ blocks : list [ dict [ str , Any ]] = [
280+ {
281+ "type " : "header" ,
282+ "text " : {
283+ "type " : "plain_text" ,
284+ "text " : SLACK_UI [ "home_welcome" ] ,
285+ "emoji" : True ,
283286 },
287+ },
288+ {
289+ "type" : "section" ,
290+ "text" : {"type" : "mrkdwn" , "text" : SLACK_UI ["home_description" ]},
291+ },
292+ {"type" : "divider" },
293+ {
294+ "type" : "actions" ,
295+ "elements" : [
296+ {
297+ "type" : "button" ,
298+ "text" : {
299+ "type" : "plain_text" ,
300+ "text" : SLACK_UI ["home_btn_create" ],
301+ "emoji" : True ,
302+ },
303+ "style" : "primary" ,
304+ "action_id" : "action_open_generation_modal" ,
305+ },
306+ {
307+ "type" : "button" ,
308+ "text" : {
309+ "type" : "plain_text" ,
310+ "text" : SLACK_UI ["home_btn_upload" ],
311+ "emoji" : True ,
312+ },
313+ "action_id" : "action_open_upload_modal" ,
314+ },
315+ ],
316+ },
317+ {"type" : "divider" },
318+ {
319+ "type" : "header" ,
320+ "text" : {"type" : "plain_text" , "text" : SLACK_UI ["home_drafts_header" ], "emoji" : True },
321+ },
322+ ]
323+
324+ if not drafts :
325+ blocks .append (
284326 {
285327 "type" : "section" ,
286- "text" : {"type" : "mrkdwn" , "text" : SLACK_UI ["home_description" ]},
287- },
288- {"type" : "divider" },
289- {
290- "type" : "actions" ,
291- "elements" : [
292- {
293- "type" : "button" ,
294- "text" : {
295- "type" : "plain_text" ,
296- "text" : SLACK_UI ["home_btn_create" ],
297- "emoji" : True ,
298- },
299- "style" : "primary" ,
300- "action_id" : "action_open_generation_modal" ,
328+ "text" : {"type" : "mrkdwn" , "text" : SLACK_UI ["home_drafts_empty" ]},
329+ }
330+ )
331+ else :
332+ for d in drafts :
333+ status_emoji = "⏳"
334+ if d .status == "published" :
335+ status_emoji = "✅"
336+ elif d .status == "scheduled" :
337+ status_emoji = "🕒"
338+ elif d .status == "failed" :
339+ status_emoji = "❌"
340+
341+ blocks .append (
342+ {
343+ "type" : "section" ,
344+ "text" : {
345+ "type" : "mrkdwn" ,
346+ "text" : SLACK_UI ["home_draft_card_text" ].format (
347+ topic = d .topic ,
348+ platform = d .platform .upper (),
349+ status_emoji = status_emoji ,
350+ status = d .status ,
351+ ),
301352 },
302- {
353+ "accessory" : {
303354 "type" : "button" ,
304355 "text" : {
305356 "type" : "plain_text" ,
306- "text" : SLACK_UI ["home_btn_upload " ],
357+ "text" : SLACK_UI ["home_draft_open_btn " ],
307358 "emoji" : True ,
308359 },
309- "action_id" : "action_open_upload_modal" ,
360+ "value" : f"{ d .id } |{ d .platform } " ,
361+ "action_id" : "action_open_draft_details" ,
310362 },
311- ],
312- },
313- ],
314- }
363+ }
364+ )
365+
366+ return { "type" : "home" , "blocks" : blocks }
315367
316368
317369def build_upload_modal () -> dict [str , Any ]:
0 commit comments