Skip to content

Commit 911af84

Browse files
committed
Fix tab selection
1 parent 8f24f15 commit 911af84

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/static/riot/competitions/detail/submission_modal.tag

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
</div>
4040
<!-- Logs -->
4141
<div class="ui tab modal-tab" data-tab="{admin_: submission.admin}logs" hide="{opts.hide_output}">
42-
<div class="ui top attached inverted pointing menu" if="{logTabs.length > 0}">
42+
<div class="ui top attached inverted pointing menu" if="{logTabs.length > 0}" ref="log_tabs_menu">
4343
<div each="{tab, i in logTabs}"
44-
class="submission-modal item {active: i === 0}"
45-
data-tab="{tab.fullTabId}">
44+
class="submission-modal item {active: tab.fullTabId === activeLogTabId || (!activeLogTabId && i === 0)}"
45+
data-tab="{tab.fullTabId}"
46+
onclick="{() => activeLogTabId = tab.fullTabId}">
4647
{tab.label}
4748
</div>
4849
</div>
@@ -52,7 +53,7 @@
5253
</div>
5354
<!-- Dynamic tabs -->
5455
<div each="{tab, i in logTabs}"
55-
class="ui bottom attached inverted segment tab log {active: i === 0}"
56+
class="ui bottom attached inverted segment tab log {active: tab.fullTabId === activeLogTabId || (!activeLogTabId && i === 0)}"
5657
data-tab="{tab.fullTabId}">
5758
<pre class="{empty: is_empty(tab.content)}">{ show_log(tab.content) }</pre>
5859
</div>
@@ -117,8 +118,12 @@
117118
.filter(t => !self.is_empty(t.content))
118119
.map(t => ({
119120
...t,
120-
fullTabId: `${prefix}${t.key}`
121+
fullTabId: `${prefix}sub_${self.submission.id}_${t.key}`
121122
}))
123+
124+
if (!self.activeLogTabId || !self.logTabs.find(t => t.fullTabId === self.activeLogTabId)) {
125+
self.activeLogTabId = self.logTabs.length ? self.logTabs[0].fullTabId : null
126+
}
122127
}
123128

124129
self.get_score_details = function (column) {
@@ -154,11 +159,11 @@
154159
self.rebuild_log_tabs()
155160
self.update()
156161
setTimeout(() => {
157-
const $items = $(self.root).find('.ui.top.attached.menu .item')
162+
if (!self.refs.log_tabs_menu) return
163+
const $items = $(self.refs.log_tabs_menu).find('.item')
158164
$items.tab()
159-
// pick the first tab deterministically
160165
if (self.logTabs.length) {
161-
$items.tab('change tab', self.logTabs[0].fullTabId)
166+
$items.tab('change tab', self.activeLogTabId || self.logTabs[0].fullTabId)
162167
}
163168
}, 0)
164169
})

0 commit comments

Comments
 (0)