Skip to content

Commit

Permalink
chore: use GQL TargetName enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Aug 21, 2023
1 parent 04f394e commit 4b0758a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/lib/components/sml-versions/SMLVersionForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { smlVersionSchema } from '$lib/models/sml-versions';
import Textfield from '@smui/textfield';
import Button from '@smui/button';
import { VersionStabilities } from '$lib/generated';
import { TargetName, VersionStabilities } from '$lib/generated';
import Select, { Option } from '@smui/select';
export let onSubmit: (data: SMLVersionData) => void;
Expand All @@ -22,7 +22,7 @@
satisfactory_version: 0,
stability: VersionStabilities.Alpha,
version: '',
targets: [{ targetName: 'Windows', link: '' }]
targets: [{ targetName: TargetName.Windows, link: '' }]
};
export let submitText = 'Create';
Expand All @@ -33,7 +33,7 @@
});
const addTarget = () => {
addField('targets', { targetName: '', link: '' });
addField('targets', { targetName: TargetName.Windows, link: '' });
};
const removeTarget = (i: number) => {
Expand Down Expand Up @@ -106,9 +106,9 @@
<div class="flex content-center gap-2">
<div>
<Select bind:value={target.targetName} label="Platform">
<Option value="Windows">Windows Client</Option>
<Option value="WindowsServer">Windows Server</Option>
<Option value="LinuxServer">Linux Server</Option>
<Option value={TargetName.Windows}>Windows Client</Option>
<Option value={TargetName.WindowsServer}>Windows Server</Option>
<Option value={TargetName.LinuxServer}>Linux Server</Option>
<svelte:fragment slot="helperText">
<ValidationMessage for="targets.{i}.targetName" let:messages={message}>
<span class="validation-message">{message || ''}</span>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/models/sml-versions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as zod from 'zod';
import type { UpdateSmlVersionTarget, VersionStabilities } from '$lib/generated';
import type { TargetName, UpdateSmlVersionTarget, VersionStabilities } from '$lib/generated';

export type SMLTargetData = {
targetName: string;
targetName: TargetName;
link: string;
};

Expand Down
5 changes: 4 additions & 1 deletion src/lib/models/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Writable } from 'svelte/store';
import type { ZodObject, ZodRawShape } from 'zod';
import type { File } from '$lib/models/file';
import type { VersionStabilities } from '$lib/generated';
import { TargetName } from '$lib/generated/graphql';

export type VersionData = {
file: File;
Expand All @@ -25,7 +26,9 @@ export type VersionMetadata = {
targets: string[];
};

const ALLOWED_TARGETS = ['Windows', 'WindowsServer', 'LinuxServer'];
const ALLOWED_TARGETS = Object.keys(TargetName)
.map((key) => TargetName[key])
.filter((value) => typeof value === 'string') as TargetName[];

const readUPluginJson = async (
uPluginJson: string,
Expand Down
10 changes: 6 additions & 4 deletions src/lib/utils/formatting.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TargetName } from '$lib/generated/graphql';

export const prettyDate = (date: Date | string) => {
if (typeof date === 'string') {
date = new Date(date);
Expand All @@ -22,13 +24,13 @@ export const prettyBytes = (bytes: number, decimals = 2) => {
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
};

export const prettyTarget = (target: string) => {
export const prettyTarget = (target: TargetName) => {
switch (target) {
case 'Windows':
case TargetName.Windows:
return 'Windows Client';
case 'WindowsServer':
case TargetName.WindowsServer:
return 'Windows Server';
case 'LinuxServer':
case TargetName.LinuxServer:
return 'Linux Server';
}

Expand Down

0 comments on commit 4b0758a

Please sign in to comment.