♻️ Add version reading by package file

This commit is contained in:
Manuel
2023-01-31 21:17:37 +01:00
parent 2b76ae83b1
commit 2b20cecb79
19 changed files with 83 additions and 36 deletions

View File

@@ -0,0 +1,15 @@
export const calculateETA = (givenSeconds: number) => {
// If its superior than one day return > 1 day
if (givenSeconds > 86400) {
return '> 1 day';
}
// Transform the givenSeconds into a readable format. e.g. 1h 2m 3s
const hours = Math.floor(givenSeconds / 3600);
const minutes = Math.floor((givenSeconds % 3600) / 60);
const seconds = Math.floor(givenSeconds % 60);
// Only show hours if it's greater than 0.
const hoursString = hours > 0 ? `${hours}h ` : '';
const minutesString = minutes > 0 ? `${minutes}m ` : '';
const secondsString = seconds > 0 ? `${seconds}s` : '';
return `${hoursString}${minutesString}${secondsString}`;
};

View File

@@ -0,0 +1,20 @@
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import { TFunction } from 'next-i18next';
dayjs.extend(duration);
export const parseDuration = (time: number, t: TFunction): string => {
const etaDuration = dayjs.duration(time, 's');
let eta = etaDuration.format(`s [${t('common:time.seconds')}]`);
if (etaDuration.asMinutes() > 1) {
eta = etaDuration.format(`m [${t('common:time.minutes')}] `) + eta;
}
if (etaDuration.asHours() > 1) {
eta = etaDuration.format(`H [${t('common:time.hours')}] `) + eta;
}
return eta;
};

View File

@@ -0,0 +1,15 @@
import create from 'zustand';
import { ServerSidePackageAttributesType } from '../../server/getPackageVersion';
interface PackageAttributesState {
attributes: ServerSidePackageAttributesType;
setInitialPackageAttributes: (attributes: ServerSidePackageAttributesType) => void;
}
export const usePackageAttributesStore = create<PackageAttributesState>((set) => ({
attributes: { packageVersion: undefined, environment: 'test' },
setInitialPackageAttributes(attributes) {
set((state) => ({ ...state, attributes }));
},
}));