Skip to content

Commit ba4e90c

Browse files
committed
Get Upload page ready for Mythic to finish
1 parent 299df54 commit ba4e90c

File tree

5 files changed

+92
-75
lines changed

5 files changed

+92
-75
lines changed

Diff for: packages/cyberstorm-forms/src/forms/UploadPackageForm.module.css

+27
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,30 @@
1313
flex-direction: row;
1414
gap: var(--gap--16);
1515
}
16+
17+
.submit > :last-child {
18+
flex-grow: 1;
19+
}
20+
21+
.teamContentWrapper {
22+
display: flex;
23+
flex-direction: column;
24+
gap: var(--space--12);
25+
}
26+
27+
.createTeamModalLink {
28+
color: #39e9aa;
29+
font-weight: var(--font-weight-medium);
30+
background: transparent;
31+
}
32+
33+
.createTeamSentence {
34+
display: flex;
35+
flex-direction: row;
36+
gap: var(--space--8);
37+
color: var(--text-tertiary, #9c9cc4);
38+
font-weight: var(--font-weight-semibold);
39+
40+
font-size: 0.875rem;
41+
line-height: 1.7;
42+
}

Diff for: packages/cyberstorm-forms/src/forms/UploadPackageForm.tsx

+53-62
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,51 @@ import {
1313
CreateTeamForm,
1414
FormSwitch,
1515
} from "@thunderstore/cyberstorm-forms";
16-
import { TextInput, Dialog, Button } from "@thunderstore/cyberstorm";
16+
import { Dialog, Button } from "@thunderstore/cyberstorm";
1717
import { SettingItem } from "@thunderstore/cyberstorm/src/components/SettingItem/SettingItem";
18-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
19-
import { faPlus } from "@fortawesome/free-solid-svg-icons";
2018
import { packageUpload } from "@thunderstore/thunderstore-api";
19+
import { usePromise } from "@thunderstore/use-promise";
20+
import { useDapper } from "@thunderstore/dapper";
2121

2222
const options = [
23-
{ label: "Asd", value: "asd" },
24-
{ label: "Asd2", value: "asd2" },
25-
{ label: "Asd3", value: "asd3" },
26-
{ label: "Asd4", value: "asd4" },
27-
{ label: "Asd5", value: "asd5" },
28-
{ label: "Asd6", value: "asd6" },
29-
{ label: "Asd7", value: "asd7" },
30-
{ label: "Asd8", value: "asd8" },
31-
{ label: "Asd9", value: "asd9" },
32-
{ label: "Asd10", value: "asd10" },
33-
{ label: "Asd11", value: "asd11" },
34-
{ label: "Asd12", value: "asd12" },
35-
{ label: "Asd13", value: "asd13" },
36-
{ label: "Asd14", value: "asd14" },
23+
{ label: "Asd", value: "asd asd" },
24+
{ label: "Asd2", value: "asd2 asd2" },
25+
{ label: "Asd3", value: "asd3 asd3" },
26+
{ label: "Asd4", value: "asd4 asd4" },
27+
{ label: "Asd5", value: "asd5 asd5" },
28+
{ label: "Asd6", value: "asd6 asd6" },
3729
];
3830

39-
interface UploadPackageFormProps {
40-
teams: {
41-
name: string;
42-
}[];
43-
}
31+
export function UploadPackageForm() {
32+
const dapper = useDapper();
33+
const user = usePromise(dapper.getCurrentUser, []);
34+
const communities = usePromise(dapper.getCommunities, []);
4435

45-
export function UploadPackageForm(props: UploadPackageFormProps) {
4636
const toaster = useFormToaster({
4737
successMessage: "Package submitted",
4838
});
4939

50-
// Parse categories to the right format for form
51-
function communityCategoriesParse(
40+
function communitiesParse(
5241
selected: {
5342
label: string;
5443
value: string;
55-
}[],
56-
onChange: (selected: { [key: string]: string[] }) => void
44+
}[]
5745
) {
58-
const communityCategories: { [key: string]: string[] } = {};
59-
selected.map((x) => (communityCategories[x.value] = [x.value]));
60-
onChange(communityCategories);
46+
return selected.map((x) => x.value);
6147
}
6248

63-
// Parse communities to the right format for form
64-
function communitiesParse(
49+
function communityCategoriesParse(
6550
selected: {
6651
label: string;
6752
value: string;
68-
}[],
69-
onChange: (selected: string[]) => void
53+
}[]
7054
) {
71-
onChange(selected.map((x) => x.value));
55+
const communityCategories: { [key: string]: string[] } = {};
56+
// TODO: Instead of getting the value from splitting a string, have it be passed in an object
57+
selected.map(
58+
(x) => (communityCategories["community_identifier"] = [x.value])
59+
);
60+
return communityCategories;
7261
}
7362

7463
return (
@@ -82,46 +71,48 @@ export function UploadPackageForm(props: UploadPackageFormProps) {
8271
<SettingItem
8372
title="Upload file"
8473
description="Upload your package as a ZIP file."
85-
content={<TextInput />}
74+
content={<>upload block here</>}
8675
/>
8776
<div className={styles.line} />
8877
<SettingItem
8978
title="Team"
90-
description="No teams available?"
91-
additionalLeftColumnContent={
92-
<Dialog.Root
93-
title="Create Team"
94-
trigger={
95-
<Button.Root colorScheme="primary" paddingSize="large">
96-
<Button.ButtonLabel>Create team</Button.ButtonLabel>
97-
<Button.ButtonIcon>
98-
<FontAwesomeIcon icon={faPlus} />
99-
</Button.ButtonIcon>
100-
</Button.Root>
101-
}
102-
>
103-
<CreateTeamForm />
104-
</Dialog.Root>
105-
}
79+
description="Select the team you want your package to be associated with."
10680
content={
107-
<FormSelectSearch
108-
name="team"
109-
schema={uploadPackageFormSchema}
110-
options={props.teams.map((t) => t.name)}
111-
placeholder="Choose a team..."
112-
/>
81+
<div className={styles.teamContentWrapper}>
82+
<FormSelectSearch
83+
name="team"
84+
schema={uploadPackageFormSchema}
85+
options={user.teams.map((t) => t.name)}
86+
placeholder="Choose a team..."
87+
/>
88+
<div className={styles.createTeamSentence}>
89+
<span>No teams available?</span>
90+
<Dialog.Root
91+
title="Create Team"
92+
trigger={
93+
<button className={styles.createTeamModalLink}>
94+
Create Team
95+
</button>
96+
}
97+
>
98+
<CreateTeamForm />
99+
</Dialog.Root>
100+
</div>
101+
</div>
113102
}
114103
/>
115104
<SettingItem
116105
title="Communities"
117-
description="Select communities you want your package to be listed under. Current community is selected by default."
106+
description="Select communities you want your package to be listed under."
118107
content={
119108
<FormMultiSelectSearch
120109
name="communities"
121110
schema={uploadPackageFormSchema}
122-
options={options}
111+
options={communities.results.map((c) => {
112+
return { label: c.name, value: c.identifier };
113+
})}
123114
placeholder="Choose community..."
124-
onChangeParse={communitiesParse}
115+
fieldFormFormatParser={communitiesParse}
125116
/>
126117
}
127118
/>
@@ -134,7 +125,7 @@ export function UploadPackageForm(props: UploadPackageFormProps) {
134125
schema={uploadPackageFormSchema}
135126
options={options}
136127
placeholder="Choose categories..."
137-
onChangeParse={communityCategoriesParse}
128+
fieldFormFormatParser={communityCategoriesParse}
138129
/>
139130
}
140131
/>

Diff for: packages/cyberstorm/src/components/Layout/Developers/PackageUpload/PackageUploadLayout.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@ import { BreadCrumbs } from "../../../BreadCrumbs/BreadCrumbs";
44
import { PackageUploadLink } from "../../../Links/Links";
55
import { BaseLayout } from "../../BaseLayout/BaseLayout";
66
import { UploadPackageForm } from "@thunderstore/cyberstorm-forms";
7-
import { useDapper } from "@thunderstore/dapper";
8-
import { usePromise } from "@thunderstore/use-promise";
97

108
/**
119
* Cyberstorm PackageUpload Layout
1210
*/
1311

1412
export function PackageUploadLayout() {
15-
const dapper = useDapper();
16-
const user = usePromise(dapper.getCurrentUser, []);
17-
// TODO: Somehow grab categories from all the selected communities and pass them on
18-
// const communities = usePromise(dapper.getCommunities, []);
19-
// const filters = usePromise(dapper.getCommunityFilters, [communityId])
2013
return (
2114
<BaseLayout
2215
breadCrumb={
@@ -25,7 +18,7 @@ export function PackageUploadLayout() {
2518
</BreadCrumbs>
2619
}
2720
header={<Title text="Upload Package" />}
28-
mainContent={<UploadPackageForm teams={user.teams} />}
21+
mainContent={<UploadPackageForm />}
2922
/>
3023
);
3124
}

Diff for: packages/thunderstore-api/src/fetch/packageUpload.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type PackageUploadApiArgs = {
77
team: string;
88
community_categories: { [key: string]: string[] };
99
communities: string[];
10-
has_nsfw_content: boolean;
10+
has_nsfw_content?: boolean;
1111
};
1212

1313
export function packageUpload(
@@ -17,12 +17,18 @@ export function packageUpload(
1717
const path = "api/experimental/submission/submit/";
1818

1919
// TODO: Add these datas in form
20-
const todoData = { ...data, upload_uuid: "123", author_name: "root" };
20+
const todoData = {
21+
...data,
22+
upload_uuid: "123",
23+
author_name: "root",
24+
};
2125

2226
return apiFetch2({
2327
config,
2428
path,
25-
method: "POST",
26-
body: JSON.stringify(todoData),
29+
request: {
30+
method: "POST",
31+
body: JSON.stringify(todoData),
32+
},
2733
});
2834
}

Diff for: packages/ts-api-react-forms/src/schema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export const uploadPackageFormSchema = z.object({
1313
team: z.string(),
1414
community_categories: z.record(z.array(z.string())),
1515
communities: z.array(z.string()).nonempty(),
16-
has_nsfw_content: z.boolean(),
16+
has_nsfw_content: z.boolean().default(false),
1717
});

0 commit comments

Comments
 (0)