@@ -10,6 +10,7 @@ export default class extends Controller {
1010 declare readonly descriptionTarget : HTMLInputElement
1111 declare readonly issueTargets : Element [ ]
1212 declare readonly shareCopiedValue : string
13+ declare readonly sharePrefilledValue : string
1314 declare readonly shareIgnoredValue : string
1415 declare readonly sessionActiveValue : boolean
1516
@@ -26,14 +27,18 @@ export default class extends Controller {
2627
2728 static values = {
2829 shareCopied : String ,
30+ sharePrefilled : String ,
2931 shareIgnored : String ,
3032 sessionActive : Boolean ,
3133 }
3234
3335 public connect ( ) {
3436 this . connected = true
35- this . prefillFieldsFromURL ( )
36- this . showShareIgnoredNotice ( )
37+ if ( this . sessionActiveValue ) {
38+ this . showShareIgnoredNotice ( )
39+ } else {
40+ this . prefillFieldsFromURL ( )
41+ }
3742 }
3843
3944 public disconnect ( ) {
@@ -95,24 +100,31 @@ export default class extends Controller {
95100 const url = `${ window . location . origin } ${ window . location . pathname } ${ query } `
96101
97102 navigator . clipboard . writeText ( url ) . then ( ( ) => {
98- this . showFlashNotice ( this . shareCopiedValue )
103+ this . showFlash ( this . shareCopiedValue , 'notice' )
99104 } )
100105 }
101106
102107 private prefillFieldsFromURL ( ) {
103108 const urlParams = new URLSearchParams ( window . location . search )
104109
105- this . prefillField ( urlParams , 'comments' , this . descriptionTarget )
106- this . prefillField ( urlParams , 'timer_start' , this . startTarget )
107- this . prefillField ( urlParams , 'timer_end' , this . endTarget )
110+ const prefilled = [
111+ this . prefillField ( urlParams , 'comments' , this . descriptionTarget ) ,
112+ this . prefillField ( urlParams , 'timer_start' , this . startTarget ) ,
113+ this . prefillField ( urlParams , 'timer_end' , this . endTarget ) ,
114+ ] . some ( Boolean )
115+
116+ if ( prefilled ) {
117+ this . showFlash ( this . sharePrefilledValue , 'notice' )
118+ }
108119 }
109120
110- private prefillField ( urlParams : URLSearchParams , param : string , target : HTMLInputElement ) {
121+ private prefillField ( urlParams : URLSearchParams , param : string , target : HTMLInputElement ) : boolean {
111122 const value = urlParams . get ( param )
112- if ( ! value ) return
123+ if ( ! value ) return false
113124
114125 target . value = value
115126 target . dispatchEvent ( new Event ( 'change' ) )
127+ return true
116128 }
117129
118130 private showShareIgnoredNotice ( ) {
@@ -125,26 +137,27 @@ export default class extends Controller {
125137 urlParams . getAll ( 'issue_ids[]' ) . some ( ( v ) => v !== '' )
126138
127139 if ( hasShareParams ) {
128- this . showFlashNotice ( this . shareIgnoredValue )
140+ this . showFlash ( this . shareIgnoredValue , 'warning' )
129141 }
130142 }
131143
132- private showFlashNotice ( message : string ) {
133- const flash = document . getElementById ( 'flash_notice' )
134- if ( flash ) {
135- flash . textContent = message
136- flash . style . display = ''
144+ private showFlash ( message : string , type : 'notice' | 'warning' ) {
145+ const flashId = `flash_${ type } `
146+ const existing = document . getElementById ( flashId )
147+ if ( existing ) {
148+ existing . textContent = message
149+ existing . style . display = ''
137150 return
138151 }
139152
140153 const container = document . getElementById ( 'content' )
141154 if ( ! container ) return
142155
143- const notice = document . createElement ( 'div' )
144- notice . id = 'flash_notice'
145- notice . className = ' flash notice'
146- notice . textContent = message
147- container . prepend ( notice )
156+ const flash = document . createElement ( 'div' )
157+ flash . id = flashId
158+ flash . className = ` flash ${ type } `
159+ flash . textContent = message
160+ container . prepend ( flash )
148161 }
149162
150163 private extractIssueIds ( ) : string [ ] {
0 commit comments