Skip to content

Commit

Permalink
fix: renterd gpu, map colors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Aug 21, 2023
1 parent 73e7297 commit b8a5a3b
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 27 deletions.
6 changes: 3 additions & 3 deletions apps/renterd/components/Hosts/HostMap/Globe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ export function Globe({
}}
pointsTransitionDuration={0}
pointColor={(h: HostDataWithLocation) => {
const { color } = getHostStatus(h)
const { colorHex } = getHostStatus(h)
if (!activeHost || h.publicKey === activeHost?.publicKey) {
return color
return colorHex
}
return colorWithOpacity(color, 0.2)
return colorWithOpacity(colorHex, 0.2)
}}
pointRadius={(h: HostDataWithLocation) => {
let radius = 0
Expand Down
26 changes: 20 additions & 6 deletions apps/renterd/components/Hosts/HostMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Globe } from './Globe'
import { useHosts } from '../../../contexts/hosts'
import { HostDataWithLocation } from '../../../contexts/hosts/types'
import { DataLabel } from '@siafoundation/design-system'
import { hostColors } from '../../../contexts/hosts/status'

export function HostMap() {
const { gpu } = useAppSettings()
Expand All @@ -13,17 +14,13 @@ export function HostMap() {
onHostMapHover: onHostHover,
hostsWithLocation,
} = useHosts()
if (!(gpu.hasCheckedGpu && gpu.shouldRender)) {

if (!gpu.shouldRender) {
return null
}

return (
<div className="w-full h-full">
<div className="absolute top-5 left-5 flex gap-4">
<DataLabel color="blue" label="Active & usable" />
<DataLabel color="red" label="Active & unusable" />
<DataLabel color="green" label="Potential host" />
</div>
<Globe
activeHost={
activeHost?.location
Expand All @@ -37,6 +34,23 @@ export function HostMap() {
setCmd(cmd)
}}
/>
<div className="absolute top-5 left-6 flex flex-col gap-1">
<DataLabel
color={hostColors.activeAndUsable.colorHex}
label="Active contract & usable"
size="12"
/>
<DataLabel
color={hostColors.activeAndUnusable.colorHex}
label="Active contract & unusable"
size="12"
/>
<DataLabel
color={hostColors.potentialHost.colorHex}
label="No active contract"
size="12"
/>
</div>
</div>
)
}
27 changes: 22 additions & 5 deletions apps/renterd/components/Hosts/HostsActionsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Button, Earth16, ListChecked16 } from '@siafoundation/design-system'
import {
Button,
Earth16,
ListChecked16,
Tooltip,
} from '@siafoundation/design-system'
import { HostsViewDropdownMenu } from './HostsViewDropdownMenu'
import { useDialog } from '../../contexts/dialog'
import { useHosts } from '../../contexts/hosts'
Expand All @@ -17,14 +22,26 @@ export function HostsActionsMenu() {
<ListChecked16 />
Manage lists
</Button>
{gpu.canGpuRender && (
<Tooltip
content={
gpu.canGpuRender && gpu.isGpuEnabled
? 'Toggle interactive map'
: 'Enable GPU to view interactive map'
}
>
<Button
onClick={() => setViewMode(viewMode === 'map' ? 'list' : 'map')}
tip="Toggle interactive map"
disabled={!gpu.canGpuRender}
onClick={() => {
if (gpu.isGpuEnabled) {
setViewMode(viewMode === 'map' ? 'list' : 'map')
} else {
openDialog('settings')
}
}}
>
<Earth16 />
</Button>
)}
</Tooltip>
<HostsViewDropdownMenu />
</div>
)
Expand Down
7 changes: 2 additions & 5 deletions apps/renterd/components/Hosts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { HostsActionsMenu } from './HostsActionsMenu'
import { HostsFilterBar } from './HostsFilterBar'
import { HostMap } from './HostMap'
import { cx } from 'class-variance-authority'
import { getHostStatus } from '../../contexts/hosts/status'

export function Hosts() {
const { openDialog } = useDialog()
Expand Down Expand Up @@ -69,11 +70,7 @@ export function Hosts() {
<Table
focusId={activeHost?.publicKey}
focusColor={
activeHost?.activeContractsCount.gt(0) && !activeHost?.usable
? 'red'
: activeHost?.activeContractsCount.gt(0)
? 'blue'
: 'green'
activeHost ? getHostStatus(activeHost).colorName : undefined
}
isLoading={dataState === 'loading'}
emptyState={<StateEmpty />}
Expand Down
21 changes: 18 additions & 3 deletions apps/renterd/contexts/hosts/status.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import { colors } from '@siafoundation/design-system'
import { HostData } from './types'

export const hostColors = {
activeAndUsable: {
colorHex: colors.green[600],
colorName: 'green',
},
activeAndUnusable: {
colorHex: colors.amber[600],
colorName: 'amber',
},
potentialHost: {
colorHex: colors.blue[600],
colorName: 'blue',
},
} as const

export function getHostStatus(h: HostData) {
// red
if (h.activeContractsCount.gt(0) && !h.usable) {
return {
status: 'activeAndUnusable',
color: colors.red[600],
...hostColors.activeAndUnusable,
}
}
// blue
if (h.activeContractsCount.gt(0)) {
return {
status: 'activeAndUsable',
color: colors.blue[600],
...hostColors.activeAndUsable,
}
}
// green
return {
status: 'potentialHost',
color: colors.green[600],
...hostColors.potentialHost,
}
}

Expand Down
11 changes: 9 additions & 2 deletions libs/design-system/src/app/DataLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ type Props = {
enabled?: boolean
onChange?: (val: boolean) => void
color?: string
size?: React.ComponentProps<typeof Text>['size']
}

export function DataLabel({ label, enabled = true, onChange, color }: Props) {
export function DataLabel({
size,
label,
enabled = true,
onChange,
color,
}: Props) {
return (
<div
className={cx(
Expand All @@ -25,7 +32,7 @@ export function DataLabel({ label, enabled = true, onChange, color }: Props) {
<Status style={{ backgroundColor: color }} />
</div>
)}
<Text>{label}</Text>
<Text size={size}>{label}</Text>
</div>
)
}
26 changes: 25 additions & 1 deletion libs/design-system/src/app/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function SettingsDialog({
showSiaStats = true,
securityEl,
}: Props) {
const { settings, setSettings, setCurrency, currencyOptions } =
const { settings, setSettings, setCurrency, currencyOptions, gpu } =
useAppSettings()

return (
Expand Down Expand Up @@ -95,6 +95,30 @@ export function SettingsDialog({
</Paragraph>
</div>
</Alert>
<Alert>
<div className="flex flex-col gap-4">
<div className="flex gap-2 items-center">
<Text>
<Information16 />
</Text>
<Heading size="20" className="flex-1">
GPU
</Heading>
<Switch
disabled={!gpu.canGpuRender}
checked={gpu.canGpuRender && gpu.isGpuEnabled}
onCheckedChange={gpu.setIsGpuEnabled}
size="medium"
/>
</div>
<Paragraph size="14">
Enable features that require a GPU.{' '}
{!gpu.canGpuRender
? ''
: 'This device does not support GPU rendering.'}
</Paragraph>
</div>
</Alert>
</div>
</div>
<Separator className="w-full" />
Expand Down
5 changes: 4 additions & 1 deletion libs/design-system/src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Props<
isLoading: boolean
emptyState?: React.ReactNode
focusId?: string
focusColor?: 'green' | 'red' | 'blue' | 'default'
focusColor?: 'green' | 'red' | 'amber' | 'blue' | 'default'
}

export function Table<
Expand Down Expand Up @@ -236,6 +236,9 @@ export function Table<
focusColor === 'red'
? '!shadow-red-500 dark:!shadow-red-400'
: '',
focusColor === 'amber'
? '!shadow-amber-500 dark:!shadow-amber-500'
: '',
focusColor === 'green'
? '!shadow-green-500 dark:!shadow-green-400'
: ''
Expand Down
7 changes: 6 additions & 1 deletion libs/react-core/src/useAppSettings/useGpuFeatures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ export function useGpuFeatures() {
const shouldRender = canGpuRender && isGpuEnabled

return {
// has the GPU been evaluated
hasCheckedGpu,
// does the GPU have the ability to render at all
canGpuRender,
// is the GPU currently enabled by default or the user
isGpuEnabled,
// if the GPU has the ability and is currently enabled
shouldRender,

setCanGpuRender,
setIsGpuEnabled,
shouldRender,
}
}

0 comments on commit b8a5a3b

Please sign in to comment.