-
Notifications
You must be signed in to change notification settings - Fork 4
[Draft] User Profiles with Editing #510
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
Open
nole2701
wants to merge
11
commits into
main
Choose a base branch
from
user-profile-mobile
base: main
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.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
08060ae
before merging main into branch
nole2701 72470cd
Merge branch 'main' into user-profile-editing
nole2701 185a14b
Merge conflict handling
nole2701 654e6bc
draft for the user profile sidebar. for upload testing
nole2701 27dee6e
commented out the code that blocks console logs for now
nole2701 efac771
mobile layout done and profile page done
nole2701 3209aec
ran dev-check
nole2701 892551b
responded to comments
nole2701 0c0738a
hopefully fixed build issue by adding /index to MdFileUpload
nole2701 4d152ce
Merge branch 'main' into user-profile-mobile
nole2701 79c69cb
merged main into branch 2
nole2701 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
69 changes: 69 additions & 0 deletions
69
website/src/components/dashboard/edit-profile-sidebar-form-context.tsx
This file contains hidden or 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,69 @@ | ||
| import React, { createContext, useContext, useState } from "react" | ||
| import { | ||
| unstable_FormStateReturn as FormStateReturn, | ||
| unstable_useFormState as useFormState, | ||
| } from "reakit" | ||
| import * as Dailp from "../../graphql/dailp" | ||
|
|
||
| type FormContextType = { | ||
| form: FormStateReturn<any | undefined> | ||
| isEditing: boolean | ||
| setIsEditing: (bool: boolean) => void | ||
| } | ||
|
|
||
| const FormContext = createContext<FormContextType>({} as FormContextType) | ||
|
|
||
| /** Instantiates a form state used to keep track of the current user and information about all its features. */ | ||
| export const FormProvider = (props: { children: any }) => { | ||
| const [isEditing, setIsEditing] = useState(false) | ||
| const user: Dailp.User = {} as Dailp.User | ||
|
|
||
| const [updateUserResult, updateUser] = Dailp.useUpdateCurrentUserMutation() | ||
|
|
||
| /** Calls the backend GraphQL mutation to update a user's profile data. */ | ||
| const runUpdate = async (variables: { user: Dailp.CurrentUserUpdate }) => { | ||
| await updateUser(variables) | ||
| } | ||
|
|
||
| const form = useFormState({ | ||
| values: { | ||
| user, | ||
| }, | ||
| onValidate: (values) => { | ||
| if (!values || !values.user) { | ||
| throw { values: "No user found" } | ||
| } | ||
| }, | ||
| onSubmit: (values) => { | ||
| console.log("Submitting user profile update") | ||
| console.log(values.user.displayName) | ||
| console.log(values.user.avatarUrl) | ||
| console.log(values.user.bio) | ||
| console.log(values.user.organization) | ||
| console.log(values.user.location) | ||
| setIsEditing(false) | ||
|
|
||
| runUpdate({ | ||
| user: { | ||
| displayName: values.user.displayName, | ||
| avatarUrl: values.user.avatarUrl, | ||
| bio: values.user.bio, | ||
| organization: values.user.organization, | ||
| location: values.user.location, | ||
| }, | ||
| }) | ||
| }, | ||
| }) | ||
|
|
||
| return ( | ||
| <FormContext.Provider value={{ form, isEditing, setIsEditing }}> | ||
| {props.children} | ||
| </FormContext.Provider> | ||
| ) | ||
| } | ||
|
|
||
| export const useForm = () => { | ||
| const context = useContext(FormContext) | ||
|
|
||
| return context | ||
| } | ||
Oops, something went wrong.
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.
It might be a good idea to add error handling or a try/catch around this