-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature: Button that allows the user to switch the side where the sidebar is displayed #340
Open
ghRodrigo
wants to merge
6
commits into
develop
Choose a base branch
from
feature/switchSidebarPosition
base: develop
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
6 commits
Select commit
Hold shift + click to select a range
74aac3c
Feature: Button that allows the user to switch the side where the sid…
ghRodrigo 06c4b45
Merge branch 'develop' into feature/switchSidebarPosition
ghRodrigo c13c804
Changed the position of the button and changed the location of the co…
ghRodrigo 4fb6095
changed the position of the button to the bottom of the sidebar
ghRodrigo 972be8e
Merge branch 'develop' into feature/switchSidebarPosition
ghRodrigo b9eaf46
Made it so the position of the sidebar is kept in localStorage
ghRodrigo 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
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,37 @@ | ||
import { createContext, useContext, useState, useEffect } from "react"; | ||
|
||
type SidebarContextType = { | ||
sidebarPosition: 'left' | 'right'; | ||
toggleSidebarPosition: () => void; | ||
}; | ||
|
||
const SidebarContext = createContext<SidebarContextType | undefined>(undefined); | ||
|
||
export const SidebarProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
const [sidebarPosition, setSidebarPosition] = useState<'left' | 'right'>(() => { | ||
const storedPosition = window.localStorage.getItem("sidebar-position"); | ||
return storedPosition === "left" || storedPosition === "right" ? storedPosition : "right"; | ||
}); | ||
|
||
const toggleSidebarPosition = () => { | ||
setSidebarPosition((prev) => { | ||
const newPosition = prev === "right" ? "left" : "right"; | ||
window.localStorage.setItem("sidebar-position", newPosition); | ||
return newPosition; | ||
}); | ||
}; | ||
|
||
return ( | ||
<SidebarContext.Provider value={{ sidebarPosition, toggleSidebarPosition }}> | ||
{children} | ||
</SidebarContext.Provider> | ||
); | ||
}; | ||
|
||
export const useSidebarContext = () => { | ||
const context = useContext(SidebarContext); | ||
if (!context) { | ||
throw new Error('useSidebarContext must be used within a SidebarProvider') | ||
} | ||
return context | ||
} |
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
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
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.
In the same light as the previous comment, since the sidebar button to change sides should not be global, it does not really make sense to render the
SidebarProvider
here.It should be inside the
TimeTableScheduler.tsx
page