Refresh roboname

This commit is contained in:
KoalaSat 2024-05-01 20:11:20 +02:00
parent 69b72d4231
commit d3d1ddcf07
No known key found for this signature in database
GPG Key ID: 2F7F61C6146AB157
3 changed files with 15 additions and 5 deletions

View File

@ -90,7 +90,7 @@ const RobotProfile = ({
sx={{ width: '100%' }}
>
<Grid item sx={{ height: '2.3em', position: 'relative' }}>
{slot?.hashId ? (
{slot?.nickname ? (
<Typography align='center' component='h5' variant='h5'>
<div
style={{

View File

@ -59,7 +59,9 @@ class Garage {
const rawSlots = JSON.parse(slotsDump);
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
if (rawSlot?.token) {
this.slots[rawSlot.token] = new Slot(rawSlot.token, Object.keys(rawSlot.robots), {});
this.slots[rawSlot.token] = new Slot(rawSlot.token, Object.keys(rawSlot.robots), {}, () =>
this.triggerHook('onRobotUpdate'),
);
Object.keys(rawSlot.robots).forEach((shortAlias) => {
const rawRobot = rawSlot.robots[shortAlias];
@ -113,9 +115,10 @@ class Garage {
if (!token || !shortAliases) return;
if (this.getSlot(token) === null) {
this.slots[token] = new Slot(token, shortAliases, attributes);
this.slots[token] = new Slot(token, shortAliases, attributes, () =>
this.triggerHook('onRobotUpdate'),
);
this.save();
this.triggerHook('onRobotUpdate');
}
};

View File

@ -3,13 +3,19 @@ import { Robot, type Order } from '.';
import { roboidentitiesClient } from '../services/Roboidentities/Web';
class Slot {
constructor(token: string, shortAliases: string[], robotAttributes: Record<any, any>) {
constructor(
token: string,
shortAliases: string[],
robotAttributes: Record<any, any>,
onRobotUpdate: () => void,
) {
this.token = token;
this.hashId = sha256(sha256(this.token));
this.nickname = null;
roboidentitiesClient.generateRoboname(this.hashId).then((nickname) => {
this.nickname = nickname;
onRobotUpdate();
});
roboidentitiesClient.generateRobohash(this.hashId, 'small');
roboidentitiesClient.generateRobohash(this.hashId, 'large');
@ -23,6 +29,7 @@ class Slot {
this.activeShortAlias = null;
this.lastShortAlias = null;
this.copiedToken = false;
onRobotUpdate();
}
token: string | null;