From 0702fea1ed989be312eda5156e1e255f1a026104 Mon Sep 17 00:00:00 2001 From: Isaac Johnson Date: Mon, 1 Jun 2026 19:02:10 -0500 Subject: [PATCH] fixing column endings, sort --- src/api.ts | 13 +++++++++++++ src/tui.ts | 4 +++- test-create.js | 13 +++++++++++++ test-sort.js | 11 +++++++++++ test-sort2.js | 14 ++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test-create.js create mode 100644 test-sort.js create mode 100644 test-sort2.js diff --git a/src/api.ts b/src/api.ts index c791c82..3f978f3 100644 --- a/src/api.ts +++ b/src/api.ts @@ -138,6 +138,19 @@ export async function fetchIssues( }) ); + // Apply local sorting as the Forgejo API does not inherently sort via endpoint parameters + issues.sort((a, b) => { + let diff = 0; + if (options.sortField === 'created') { + diff = new Date(b.created_at).getTime() - new Date(a.created_at).getTime(); + } else if (options.sortField === 'updated') { + diff = new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime(); + } else if (options.sortField === 'comments') { + diff = b.comments - a.comments; + } + return options.sortOrder === 'desc' ? diff : -diff; + }); + return { issues, totalCount }; } catch (error: any) { if (error.response) { diff --git a/src/tui.ts b/src/tui.ts index 46bc44d..d56ef3c 100644 --- a/src/tui.ts +++ b/src/tui.ts @@ -1181,7 +1181,9 @@ export class TuiEngine { const lineIndex = r + this.state.detailScrollOffset; if (lineIndex < contentLines.length) { const line = contentLines[lineIndex]; - console.log(borderCh + ' ' + line.padEnd(cols - 4) + ' ' + borderCh); + const linePlainLen = stripAnsi(line).length; + const padding = Math.max(0, cols - 4 - linePlainLen); + console.log(borderCh + ' ' + line + ' '.repeat(padding) + ' ' + borderCh); } else { console.log(borderCh + ' '.repeat(cols - 2) + borderCh); } diff --git a/test-create.js b/test-create.js new file mode 100644 index 0000000..6639181 --- /dev/null +++ b/test-create.js @@ -0,0 +1,13 @@ +import fs from 'fs'; +import os from 'os'; +import axios from 'axios'; + +const configPath = os.homedir() + '/.config/fjtui/fjtui.json'; +const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); + +axios.post(config.url + '/api/v1/repos/' + config.repo + '/issues', { + title: 'Second issue', + body: 'Body' +}, { + headers: { 'Authorization': 'token ' + config.token } +}).then(r => console.log('created')).catch(e => console.error(e.message)); diff --git a/test-sort.js b/test-sort.js new file mode 100644 index 0000000..2400b36 --- /dev/null +++ b/test-sort.js @@ -0,0 +1,11 @@ +import fs from 'fs'; +import os from 'os'; +import axios from 'axios'; + +const configPath = os.homedir() + '/.config/fjtui/fjtui.json'; +const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); + +axios.get(config.url + '/api/v1/repos/' + config.repo + '/issues', { + headers: { 'Authorization': 'token ' + config.token }, + params: { sort: 'oldest' } +}).then(r => console.log(r.data.map(i => i.id + ' ' + i.created_at))).catch(e => console.error(e.message)); diff --git a/test-sort2.js b/test-sort2.js new file mode 100644 index 0000000..a8f1083 --- /dev/null +++ b/test-sort2.js @@ -0,0 +1,14 @@ +import fs from 'fs'; +import os from 'os'; +import axios from 'axios'; + +const configPath = os.homedir() + '/.config/fjtui/fjtui.json'; +const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); + +axios.get(config.url + '/api/v1/repos/' + config.repo + '/issues?state=all', { + headers: { 'Authorization': 'token ' + config.token } +}).then(r => console.log('NO SORT: ' + r.data.map(i => i.id).join(', '))).catch(e => console.error(e.message)); + +axios.get(config.url + '/api/v1/repos/' + config.repo + '/issues?state=all&sort=oldest', { + headers: { 'Authorization': 'token ' + config.token } +}).then(r => console.log('OLDEST: ' + r.data.map(i => i.id).join(', '))).catch(e => console.error(e.message));