Skip to content

Commit

Permalink
unneeded changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickCleary committed Jul 15, 2023
1 parent 4578d69 commit 58da1b6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 55 deletions.
4 changes: 1 addition & 3 deletions common/components/widgets/internal/SmallData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ type SmallDataProps = {
export const SmallData: React.FC<SmallDataProps> = ({ analysis, widgetValue }) => {
return (
<div className=" flex flex-row items-end justify-between">
<p
className={classNames('truncate text-xs leading-tight text-design-subtitleGrey sm:text-sm')}
>
<p className={classNames('truncate text-sm leading-tight text-design-subtitleGrey ')}>
{analysis}
</p>
<div className="flex flex-row items-baseline gap-x-1">{widgetValue.getFormattedValue()}</div>
Expand Down
10 changes: 2 additions & 8 deletions common/components/widgets/internal/UnitText.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import classNames from 'classnames';
import React from 'react';
export interface UnitTextProps {
text: string;
light?: boolean;
}
export const UnitText: React.FC<UnitTextProps> = ({ text, light }) => {
return (
<span className={classNames(light ? 'text-stone-200' : 'text-stone-700', 'text-base ')}>
{text}
</span>
);
export const UnitText: React.FC<UnitTextProps> = ({ text }) => {
return <span className="text-sm text-design-subtitleGrey">{text}</span>;
};
12 changes: 2 additions & 10 deletions common/components/widgets/internal/WidgetText.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import classNames from 'classnames';
import React from 'react';

export interface WidgetTextProps {
text: string;
light?: boolean;
}
export const WidgetText: React.FC<WidgetTextProps> = ({ text, light }) => {
return (
<span
className={classNames(light ? 'text-stone-100' : 'text-stone-900', 'text-base font-semibold')}
>
{text}
</span>
);
export const WidgetText: React.FC<WidgetTextProps> = ({ text }) => {
return <span className="text-base font-semibold text-gray-900">{text}</span>;
};
44 changes: 21 additions & 23 deletions common/types/basicWidgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface WidgetValueInterface {
readonly percentChange?: number;

getUnits: () => string;
getFormattedValue: (light?: boolean) => React.ReactNode;
getFormattedValue: () => React.ReactNode;
getFormattedDelta: () => string;
getFormattedPercentChange: () => string;
}
Expand Down Expand Up @@ -43,9 +43,9 @@ export class DeltaTimeWidgetValue extends BaseWidgetValue implements WidgetValue
if (this.delta === undefined) return '...';
return getTimeUnit(this.delta);
}
getFormattedValue(light) {
getFormattedValue() {
if (this.delta === undefined) return '...';
return getFormattedTimeValue(this.delta, light);
return getFormattedTimeValue(this.delta);
}
getFormattedDelta() {
new Error('DeltaWidgets should use `getFormattedValue`');
Expand All @@ -57,12 +57,12 @@ export class DeltaZonesWidgetValue extends BaseWidgetValue implements WidgetValu
getUnits() {
return 'zones';
}
getFormattedValue(light) {
getFormattedValue() {
if (this.delta === undefined) return '...';
return (
<p>
<WidgetText light={light} text={`${this.delta >= 0 ? '+' : '-'}${Math.abs(this.delta)}`} />{' '}
<UnitText light={light} text={this.getUnits()} />
<WidgetText text={`${this.delta >= 0 ? '+' : '-'}${Math.abs(this.delta)}`} />{' '}
<UnitText text={this.getUnits()} />
</p>
);
}
Expand All @@ -79,9 +79,9 @@ export class TimeWidgetValue extends BaseWidgetValue implements WidgetValueInter
return getTimeUnit(this.value);
}

getFormattedValue(light?: boolean) {
getFormattedValue() {
if (this.value === undefined) return '...';
return getFormattedTimeValue(this.value, light);
return getFormattedTimeValue(this.value);
}

getFormattedDelta() {
Expand All @@ -104,12 +104,12 @@ export class SZWidgetValue extends BaseWidgetValue implements WidgetValueInterfa
getUnits() {
return 'zones';
}
getFormattedValue(light) {
getFormattedValue() {
if (typeof this.value === 'undefined') return '...';
return (
<p className="">
<WidgetText light={light} text={`${Math.abs(this.value).toString()}`} />{' '}
<UnitText light={light} text={this.getUnits()} />
<WidgetText text={`${Math.abs(this.value).toString()}`} />{' '}
<UnitText text={this.getUnits()} />
</p>
);
}
Expand All @@ -124,12 +124,12 @@ export class PercentageWidgetValue extends BaseWidgetValue implements WidgetValu
return '%';
}

getFormattedValue(light) {
getFormattedValue() {
if (this.value === undefined) return '...';
return (
<p>
<WidgetText light={light} text={`${Math.round(100 * this.value).toString()}`} />{' '}
<UnitText light={light} text={this.getUnits()} />
<WidgetText text={`${Math.round(100 * this.value).toString()}`} />{' '}
<UnitText text={this.getUnits()} />
</p>
);
}
Expand All @@ -145,12 +145,11 @@ export class TripsWidgetValue extends BaseWidgetValue implements WidgetValueInte
return 'Trips';
}

getFormattedValue(light) {
getFormattedValue() {
if (this.value === undefined) return '...';
return (
<p>
<WidgetText light={light} text={Math.abs(this.value).toFixed(0)} />{' '}
<UnitText light={light} text={this.getUnits()} />
<WidgetText text={Math.abs(this.value).toFixed(0)} /> <UnitText text={this.getUnits()} />
</p>
);
}
Expand All @@ -166,12 +165,11 @@ export class MPHWidgetValue extends BaseWidgetValue implements WidgetValueInterf
return 'MPH';
}

getFormattedValue(light) {
getFormattedValue() {
if (typeof this.value === 'undefined') return '...';
return (
<p>
<WidgetText light={light} text={this.value.toFixed(1)} />{' '}
<UnitText light={light} text={this.getUnits()} />
<WidgetText text={this.value.toFixed(1)} /> <UnitText text={this.getUnits()} />
</p>
);
}
Expand All @@ -188,12 +186,12 @@ export class RidersWidgetValue extends BaseWidgetValue implements WidgetValueInt
return 'Riders';
}

getFormattedValue(light) {
getFormattedValue() {
if (this.value === undefined) return '...';
return (
<p>
<WidgetText light={light} text={`${(this.value / 1000).toFixed(1)}k`} />{' '}
<UnitText light={light} text={this.getUnits()} />
<WidgetText text={`${(this.value / 1000).toFixed(1)}k`} />{' '}
<UnitText text={this.getUnits()} />
</p>
);
}
Expand Down
20 changes: 9 additions & 11 deletions common/utils/time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,31 @@ export const getTimeUnit = (value: number) => {
}
};

export const getFormattedTimeValue = (value: number, light?: boolean) => {
export const getFormattedTimeValue = (value: number) => {
const absValue = Math.round(Math.abs(value));
const duration = dayjs.duration(absValue, 'seconds');
switch (true) {
case absValue < 100:
return (
<p>
<WidgetText light={light} text={absValue.toFixed(0)} />
<UnitText light={light} text={'s'} />
<WidgetText text={absValue.toFixed(0)} />
<UnitText text={'s'} />
</p>
);
case absValue < 3600:
return (
<p>
<WidgetText light={light} text={duration.format('m')} />
<UnitText light={light} text={'m'} />{' '}
<WidgetText light={light} text={duration.format('s').padStart(2, '0')} />
<UnitText light={light} text={'s'} />
<WidgetText text={duration.format('m')} />
<UnitText text={'m'} /> <WidgetText text={duration.format('s').padStart(2, '0')} />
<UnitText text={'s'} />
</p>
);
default:
return (
<p>
<WidgetText light={light} text={duration.format('H')} />
<UnitText light={light} text={'h'} />{' '}
<WidgetText light={light} text={duration.format('m').padStart(2, '0')} />
<UnitText light={light} text={'m'} />
<WidgetText text={duration.format('H')} />
<UnitText text={'h'} /> <WidgetText text={duration.format('m').padStart(2, '0')} />
<UnitText text={'m'} />
</p>
);
}
Expand Down

0 comments on commit 58da1b6

Please sign in to comment.