-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UploadPackageForm form and separate form functionality from layout #932
Open
Oksamies
wants to merge
2
commits into
master
Choose a base branch
from
upload-package-form-continuance
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+259
−71
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/cyberstorm-forms/src/forms/UploadPackageForm.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.root { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--gap--48); | ||
} | ||
|
||
.line { | ||
border-bottom: var(--border-width--px) solid var(--color-surface--4); | ||
} | ||
|
||
.submit { | ||
display: flex; | ||
flex-direction: row; | ||
gap: var(--gap--16); | ||
} | ||
|
||
.submit > :last-child { | ||
flex-grow: 1; | ||
} | ||
|
||
.teamContentWrapper { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--space--12); | ||
} | ||
|
||
.createTeamModalLink { | ||
color: #39e9aa; | ||
font-weight: var(--font-weight-medium); | ||
background: transparent; | ||
} | ||
|
||
.createTeamSentence { | ||
display: flex; | ||
flex-direction: row; | ||
gap: var(--space--8); | ||
color: var(--text-tertiary, #9c9cc4); | ||
font-weight: var(--font-weight-semibold); | ||
|
||
font-size: 0.875rem; | ||
line-height: 1.7; | ||
} |
161 changes: 161 additions & 0 deletions
161
packages/cyberstorm-forms/src/forms/UploadPackageForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
"use client"; | ||
|
||
import styles from "./UploadPackageForm.module.css"; | ||
import { | ||
ApiForm, | ||
uploadPackageFormSchema, | ||
} from "@thunderstore/ts-api-react-forms"; | ||
import { | ||
FormSubmitButton, | ||
FormMultiSelectSearch, | ||
FormSelectSearch, | ||
useFormToaster, | ||
CreateTeamForm, | ||
FormSwitch, | ||
} from "@thunderstore/cyberstorm-forms"; | ||
import { Dialog, Button } from "@thunderstore/cyberstorm"; | ||
import { SettingItem } from "@thunderstore/cyberstorm/src/components/SettingItem/SettingItem"; | ||
import { packageUpload } from "@thunderstore/thunderstore-api"; | ||
import { usePromise } from "@thunderstore/use-promise"; | ||
import { useDapper } from "@thunderstore/dapper"; | ||
|
||
const options = [ | ||
{ label: "Asd", value: "asd asd" }, | ||
{ label: "Asd2", value: "asd2 asd2" }, | ||
{ label: "Asd3", value: "asd3 asd3" }, | ||
{ label: "Asd4", value: "asd4 asd4" }, | ||
{ label: "Asd5", value: "asd5 asd5" }, | ||
{ label: "Asd6", value: "asd6 asd6" }, | ||
]; | ||
|
||
export function UploadPackageForm() { | ||
const dapper = useDapper(); | ||
const user = usePromise(dapper.getCurrentUser, []); | ||
const communities = usePromise(dapper.getCommunities, []); | ||
|
||
const toaster = useFormToaster({ | ||
successMessage: "Package submitted", | ||
}); | ||
|
||
function communitiesParse( | ||
selected: { | ||
label: string; | ||
value: string; | ||
}[] | ||
) { | ||
return selected.map((x) => x.value); | ||
} | ||
|
||
function communityCategoriesParse( | ||
selected: { | ||
label: string; | ||
value: string; | ||
}[] | ||
) { | ||
const communityCategories: { [key: string]: string[] } = {}; | ||
// TODO: Instead of getting the value from splitting a string, have it be passed in an object | ||
selected.map( | ||
(x) => (communityCategories["community_identifier"] = [x.value]) | ||
); | ||
return communityCategories; | ||
} | ||
|
||
return ( | ||
<ApiForm | ||
{...toaster} | ||
schema={uploadPackageFormSchema} | ||
endpoint={packageUpload} | ||
formProps={{ className: styles.root }} | ||
> | ||
<div className={styles.root}> | ||
<SettingItem | ||
title="Upload file" | ||
description="Upload your package as a ZIP file." | ||
content={<>upload block here</>} | ||
/> | ||
<div className={styles.line} /> | ||
<SettingItem | ||
title="Team" | ||
description="Select the team you want your package to be associated with." | ||
content={ | ||
<div className={styles.teamContentWrapper}> | ||
<FormSelectSearch | ||
name="team" | ||
schema={uploadPackageFormSchema} | ||
options={user.teams.map((t) => t.name)} | ||
placeholder="Choose a team..." | ||
/> | ||
<div className={styles.createTeamSentence}> | ||
<span>No teams available?</span> | ||
<Dialog.Root | ||
title="Create Team" | ||
trigger={ | ||
<button className={styles.createTeamModalLink}> | ||
Create Team | ||
</button> | ||
} | ||
> | ||
<CreateTeamForm /> | ||
</Dialog.Root> | ||
</div> | ||
</div> | ||
} | ||
/> | ||
<SettingItem | ||
title="Communities" | ||
description="Select communities you want your package to be listed under." | ||
content={ | ||
<FormMultiSelectSearch | ||
name="communities" | ||
schema={uploadPackageFormSchema} | ||
options={communities.results.map((c) => { | ||
return { label: c.name, value: c.identifier }; | ||
})} | ||
placeholder="Choose community..." | ||
fieldFormFormatParser={communitiesParse} | ||
/> | ||
} | ||
/> | ||
<SettingItem | ||
title="Categories" | ||
description="Select descriptive categories to help people discover your package." | ||
content={ | ||
<FormMultiSelectSearch | ||
name="community_categories" | ||
schema={uploadPackageFormSchema} | ||
options={options} | ||
placeholder="Choose categories..." | ||
fieldFormFormatParser={communityCategoriesParse} | ||
/> | ||
} | ||
/> | ||
<div className={styles.line} /> | ||
<SettingItem | ||
title="Contains NSFW content" | ||
description='A "NSFW" -tag will be applied to your package.' | ||
content={ | ||
<FormSwitch | ||
schema={uploadPackageFormSchema} | ||
name="has_nsfw_content" | ||
/> | ||
} | ||
/> | ||
<div className={styles.line} /> | ||
<SettingItem | ||
title="Submit" | ||
description='Double-check your selections and hit "Submit" when you are ready!' | ||
content={ | ||
<div className={styles.submit}> | ||
<Button.Root colorScheme="danger"> | ||
<Button.ButtonLabel>Reset</Button.ButtonLabel> | ||
</Button.Root> | ||
<FormSubmitButton text="Submit" /> | ||
</div> | ||
} | ||
/> | ||
</div> | ||
</ApiForm> | ||
); | ||
} | ||
|
||
UploadPackageForm.displayName = "UploadPackageForm"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
.../cyberstorm/src/components/Layout/Developers/PackageUpload/PackageUploadLayout.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { RequestConfig } from "../index"; | ||
import { apiFetch2 } from "../apiFetch"; | ||
|
||
export type PackageUploadApiArgs = { | ||
// author_name: string; | ||
// upload_uuid: string; | ||
team: string; | ||
community_categories: { [key: string]: string[] }; | ||
communities: string[]; | ||
has_nsfw_content?: boolean; | ||
}; | ||
|
||
export function packageUpload( | ||
config: RequestConfig, | ||
data: PackageUploadApiArgs | ||
) { | ||
const path = "api/experimental/submission/submit/"; | ||
|
||
// TODO: Add these datas in form | ||
const todoData = { | ||
...data, | ||
upload_uuid: "123", | ||
author_name: "root", | ||
}; | ||
|
||
return apiFetch2({ | ||
config, | ||
path, | ||
request: { | ||
method: "POST", | ||
body: JSON.stringify(todoData), | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
communityCategories
object is using a hardcoded key"community_identifier"
which overwrites the same key on each iteration. The selected values should include both the community and category IDs, likely in a format like"communityId:categoryId"
, allowing the parser to split this into the correct community-to-categories mapping.Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.