Skip to content

Commit

Permalink
Insights fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererXII committed Jan 25, 2024
1 parent 4097c6a commit 6b2540d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ui/insights/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const li = window.lishogi;

export default class InsightCtrl {
username: string;
usernameHash: string;
endpoint: string;
isBot: boolean;

Expand All @@ -27,6 +28,7 @@ export default class InsightCtrl {
readonly redraw: Redraw
) {
this.username = opts.username;
this.usernameHash = opts.usernameHash;
this.endpoint = opts.endpoint;
this.isBot = opts.isBot;
this.trans = li.trans(this.opts.i18n);
Expand Down Expand Up @@ -101,10 +103,10 @@ export default class InsightCtrl {
this.isError = false;
const queryString = this.queryString(tab, true);
const path = this.endpoint + '/' + tab + (queryString ? '?' + queryString : '');
console.log(path);
fetch(path, {
headers: {
'Content-Type': 'application/json',
Authorization: this.usernameHash,
},
})
.then(response => {
Expand Down
1 change: 1 addition & 0 deletions ui/insights/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Tab = (typeof tabs)[number];

export interface InsightOpts {
username: string;
usernameHash: string;
endpoint: string;
isBot: boolean;
i18n: any;
Expand Down
10 changes: 9 additions & 1 deletion ui/insights/src/views/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ export function smallWinrateChart(winrate: WinRate): VNode {
}

export function horizontalBar(numbers: number[], cls: string[] = []): VNode {
const noFirst = numbers[0] === 0,
noLast = numbers[numbers.length - 1] === 0;
return h(
'div.simple-horizontal-bar',
numbers.map((n, i) =>
h('div' + (cls[i] ? `.${cls[i]}` : ''), {
style: {
width: n + '%',
borderRadius:
n === 100 ? '10px' : i === 0 ? '10px 0 0 10px' : i === numbers.length - 1 ? '0 10px 10px 0' : '0',
n === 100
? '10px'
: i === 0 || (noFirst && i === 1)
? '10px 0 0 10px'
: i === numbers.length - 1 || (noLast && i === numbers.length - 2)
? '0 10px 10px 0'
: '0',
},
})
)
Expand Down
5 changes: 4 additions & 1 deletion ui/insights/src/views/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ function content(ctrl: InsightCtrl, tab: Tab): VNode {
return h(
'div.angle-content.loading',
ctrl.isError
? 'Insights are not currently available. Sorry about that! If this keeps happening please report this on GitHub.'
? h(
'p',
'Insights are not currently available. Sorry about that! If this keeps happening please report this on GitHub.'
)
: spinner()
);

Expand Down

0 comments on commit 6b2540d

Please sign in to comment.