55from textual .app import App , ComposeResult
66from textual .containers import Horizontal , Vertical
77from textual .events import Event
8+ from textual .types import NoSelection
89from textual .widgets import (Button , Input , ListItem , ListView , Select , Static ,
910 TextArea )
1011
2324 load_file_into_form )
2425
2526
27+ class SocialEntry (Horizontal ):
28+ DEFAULT_CSS = """
29+ SocialEntry Select {
30+ width: 25%;
31+ }
32+ SocialEntry Input {
33+ width: 50%;
34+ }
35+ SocialEntry Button {
36+ width: 25%;
37+ }
38+ """
39+
40+ def __init__ (self , index : int , value : str ) -> None :
41+ super ().__init__ ()
42+ self .index = index
43+ self .select = Select (
44+ options = [
45+ GITHUB_OPTION ,
46+ GITLAB_OPTION ,
47+ BITBUCKET_OPTION ,
48+ LINKEDIN_OPTION ,
49+ FACEBOOK_OPTION ,
50+ INSTAGRAM_OPTION ,
51+ X_OPTION ,
52+ YOUTUBE_OPTION ,
53+ ],
54+ prompt = PROMPT_SOCIAL_NETWORK ,
55+ value = value ,
56+ )
57+ self .url_input = Input (placeholder = PLACEHOLDER_SOCIAL_URL )
58+ self .delete_btn = Button (BUTTON_DELETE , id = f"delete_social_{ index } " )
59+
60+ def compose (self ) -> ComposeResult :
61+ yield self .select
62+ yield self .url_input
63+ yield self .delete_btn
64+
65+
66+ class AliasEntry (Horizontal ):
67+ DEFAULT_CSS = """
68+ AliasEntry Input {
69+ width: 75%;
70+ }
71+ AliasEntry Button {
72+ width: 25%;
73+ }
74+ """
75+
76+ def __init__ (self , index : int ) -> None :
77+ super ().__init__ ()
78+ self .index = index
79+ self .alias_input = Input (placeholder = PLACEHOLDER_ALIAS )
80+ self .delete_btn = Button (BUTTON_DELETE , id = f"delete_alias_{ index } " )
81+
82+ def compose (self ) -> ComposeResult :
83+ yield self .alias_input
84+ yield self .delete_btn
85+
86+
2687class MemberApp (App ):
2788 """Single app that toggles between a file list and a form while connected to a GitHub fork+push flow."""
2889
@@ -129,8 +190,8 @@ def on_mount(self) -> None:
129190 self .form_container .display = False
130191
131192 # Some data structures
132- self .social_entries = []
133- self .alias_entries = []
193+ self .social_entries : list [ SocialEntry ] = []
194+ self .alias_entries : list [ AliasEntry ] = []
134195 self .social_index = 0
135196 self .alias_index = 0
136197 self .current_file = None
@@ -206,47 +267,10 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
206267 index = int (bid .replace ("delete_alias_" , "" ))
207268 self .remove_alias_entry (index )
208269
209- def add_social_entry (self ) -> None :
210- class SocialEntry (Horizontal ):
211- DEFAULT_CSS = """
212- SocialEntry Select {
213- width: 25%;
214- }
215- SocialEntry Input {
216- width: 50%;
217- }
218- SocialEntry Button {
219- width: 25%;
220- }
221- """
222-
223- def __init__ (se , index ):
224- super ().__init__ ()
225- se .index = index
226- se .select = Select (
227- options = [
228- GITHUB_OPTION ,
229- GITLAB_OPTION ,
230- BITBUCKET_OPTION ,
231- LINKEDIN_OPTION ,
232- FACEBOOK_OPTION ,
233- INSTAGRAM_OPTION ,
234- X_OPTION ,
235- YOUTUBE_OPTION ,
236- ],
237- prompt = PROMPT_SOCIAL_NETWORK ,
238- )
239- se .url_input = Input (placeholder = PLACEHOLDER_SOCIAL_URL )
240- se .delete_btn = Button (
241- BUTTON_DELETE , id = f"delete_social_{ index } "
242- )
243-
244- def compose (se ) -> ComposeResult :
245- yield se .select
246- yield se .url_input
247- yield se .delete_btn
248-
249- new_entry = SocialEntry (self .social_index )
270+ def add_social_entry (
271+ self , value : str | NoSelection = Select .BLANK
272+ ) -> None :
273+ new_entry = SocialEntry (self .social_index , value )
250274 self .social_index += 1
251275 self .social_entries .append (new_entry )
252276 self .social_container .mount (new_entry )
@@ -262,28 +286,6 @@ def remove_social_entry(self, index: int) -> None:
262286 found .remove ()
263287
264288 def add_alias_entry (self ) -> None :
265- class AliasEntry (Horizontal ):
266- DEFAULT_CSS = """
267- AliasEntry Input {
268- width: 75%;
269- }
270- AliasEntry Button {
271- width: 25%;
272- }
273- """
274-
275- def __init__ (se , index ):
276- super ().__init__ ()
277- se .index = index
278- se .alias_input = Input (placeholder = PLACEHOLDER_ALIAS )
279- se .delete_btn = Button (
280- BUTTON_DELETE , id = f"delete_alias_{ index } "
281- )
282-
283- def compose (se ) -> ComposeResult :
284- yield se .alias_input
285- yield se .delete_btn
286-
287289 row = AliasEntry (self .alias_index )
288290 self .alias_index += 1
289291 self .alias_entries .append (row )
0 commit comments