fixing column endings, sort

This commit is contained in:
Isaac Johnson 2026-06-01 19:02:10 -05:00
parent eb8e3f8d79
commit 0702fea1ed
5 changed files with 54 additions and 1 deletions

View File

@ -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 }; return { issues, totalCount };
} catch (error: any) { } catch (error: any) {
if (error.response) { if (error.response) {

View File

@ -1181,7 +1181,9 @@ export class TuiEngine {
const lineIndex = r + this.state.detailScrollOffset; const lineIndex = r + this.state.detailScrollOffset;
if (lineIndex < contentLines.length) { if (lineIndex < contentLines.length) {
const line = contentLines[lineIndex]; 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 { } else {
console.log(borderCh + ' '.repeat(cols - 2) + borderCh); console.log(borderCh + ' '.repeat(cols - 2) + borderCh);
} }

13
test-create.js Normal file
View File

@ -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));

11
test-sort.js Normal file
View File

@ -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));

14
test-sort2.js Normal file
View File

@ -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));