╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Discussions.zig ──────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
219 const edit_tab_label = "edit"; 220 const reply_tab_label = "reply"; 221 const remove_tab_label = "remove"; 222 const new_tab_label = "new"; 223 224 // tabs switching between the discussions page's views 225 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 226 var header = try Header.init(allocator, session, data.search); 227 errdefer header.deinit(allocator); 228 const selected_index = View.viewIndex(data.view); 229 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_discussions; 230 231 // recent discussions 232 { 233 const route = try thread.searchRoute(ui.RoutablePage.repoDiscussionsRoute(data.identity, data.label, ""), data.search); 234 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == 0); 235 var label_buf: [64]u8 = undefined; 236 const label = try thread.countLabel(&label_buf, recent_tab_label, data.recent); 237 try header.addTab(allocator, label, link, 0); 238 } 239 240 // labels tab 241 { 242 const labels_route = try thread.searchRoute(ui.RoutablePage.repoThreadLabelsRoute(.discuss, data.identity, data.label), data.search); 243 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 244 try header.addTab(allocator, labels_tab_label, labels_link, View.viewIndex(.labels)); 245 } 246 247 // new-discussion tab; an edit or comment url shows its tab in this place 248 { 249 const route = switch (data.view) { 250 .edit => ui.RoutablePage.repoThreadEditRoute(.discuss, data.identity, data.selected_id) orelse return error.RouteTooLong, 251 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.discuss, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 252 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.discuss, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 253 .remove => ui.RoutablePage.repoThreadRemoveRoute(.discuss, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 254 else => ui.RoutablePage.repoThreadNewRoute(.discuss, data.identity) orelse return error.RouteTooLong, 255 }; 256 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 257 const label: []const u8 = switch (data.view) { 258 .edit => edit_tab_label, 259 .new_comment => reply_tab_label, 260 .edit_comment => edit_tab_label, 261 .remove => remove_tab_label, 262 else => new_tab_label, 263 }; 264 try header.addTab(allocator, label, link, View.viewIndex(.new)); 265 } 266 267 header.select(View.viewIndex(data.view)); 268 return header; 269 } 270