-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from DevlinRocha/server-settings
Server settings created - server owners can now edit the names and icons for their servers after creation
- Loading branch information
Showing
21 changed files
with
584 additions
and
29 deletions.
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
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,88 @@ | ||
import tw from "tailwind-styled-components/dist/tailwind"; | ||
import ServerSettingsSidebar from "./ServerSettingsSidebar"; | ||
import ServerSettingsView from "./serverSettingsView/ServerSettingsView"; | ||
import Image from "next/image"; | ||
import closeButton from "../../../assets/closeButton.svg"; | ||
import { useAppDispatch } from "../../redux/hooks"; | ||
import { useEffect } from "react"; | ||
import { | ||
setServerSettingsOpen, | ||
setServerCopy, | ||
setServerSettingsScreen, | ||
useServerSettingsState, | ||
} from "../../features/serverSettings"; | ||
import { useServersState } from "../../features/servers"; | ||
import { setUnsavedChangesError } from "../../features/userSettings"; | ||
|
||
export default function ServerSettings() { | ||
const { server } = useServersState(); | ||
const { serverCopy } = useServerSettingsState(); | ||
const dispatch = useAppDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(setServerCopy(server)); | ||
}, []); | ||
|
||
function unsavedChanges() { | ||
if (!serverCopy) return false; | ||
|
||
if (serverCopy !== server) { | ||
dispatch(setUnsavedChangesError(true)); | ||
|
||
setTimeout(() => { | ||
dispatch(setUnsavedChangesError(false)); | ||
}, 1500); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
function closeWindow() { | ||
if (unsavedChanges()) return; | ||
|
||
dispatch(setServerSettingsOpen(false)); | ||
dispatch(setServerSettingsScreen("Overview")); | ||
} | ||
|
||
return ( | ||
<Container> | ||
<ServerSettingsSidebar /> | ||
|
||
<SettingsContainer> | ||
<ServerSettingsView /> | ||
|
||
<CloseButton> | ||
<StyledImage | ||
onClick={closeWindow} | ||
src={closeButton} | ||
width={36} | ||
height={36} | ||
alt={"Close button"} | ||
/> | ||
|
||
<Caption>ESC</Caption> | ||
</CloseButton> | ||
</SettingsContainer> | ||
</Container> | ||
); | ||
} | ||
|
||
const Container = tw.div` | ||
flex flex-none w-screen h-screen select-none | ||
`; | ||
|
||
const SettingsContainer = tw.div` | ||
relative flex w-full h-full | ||
`; | ||
|
||
const CloseButton = tw.figure` | ||
flex-none pt-15 text-center mr-5 | ||
`; | ||
|
||
const StyledImage = tw(Image)` | ||
cursor-pointer | ||
`; | ||
|
||
const Caption = tw.figcaption` | ||
text-[13px] text-gray-300 font-semibold | ||
`; |
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,94 @@ | ||
import tw from "tailwind-styled-components/dist/tailwind"; | ||
import { useAppDispatch } from "../../redux/hooks"; | ||
import { useServersState } from "../../features/servers"; | ||
import { | ||
setDeleteServerConfirmOpen, | ||
setServerSettingsScreen, | ||
useServerSettingsState, | ||
} from "../../features/serverSettings"; | ||
import { setUnsavedChangesError } from "../../features/userSettings"; | ||
|
||
export default function ServerSettingsSidebar() { | ||
const { serverSettingsScreen, serverCopy } = useServerSettingsState(); | ||
const { server } = useServersState(); | ||
const dispatch = useAppDispatch(); | ||
|
||
function unsavedChanges() { | ||
if (!serverCopy) return false; | ||
|
||
if (serverCopy !== server) { | ||
dispatch(setUnsavedChangesError(true)); | ||
|
||
setTimeout(() => { | ||
dispatch(setUnsavedChangesError(false)); | ||
}, 1500); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
function viewServerOverview() { | ||
if (unsavedChanges()) return; | ||
|
||
dispatch(setServerSettingsScreen("Overview")); | ||
} | ||
|
||
return ( | ||
<Container> | ||
<NavContainer> | ||
<ListHeading> | ||
{server.name.toUpperCase() || "SERVER SETTINGS"} | ||
</ListHeading> | ||
|
||
<SettingsList> | ||
<ListItem | ||
className={`${ | ||
serverSettingsScreen === "Overview" && "bg-gray-300" | ||
}`} | ||
onClick={viewServerOverview} | ||
> | ||
Overview | ||
</ListItem> | ||
</SettingsList> | ||
|
||
<Divider /> | ||
|
||
<SettingsList> | ||
<DeleteServer | ||
onClick={() => dispatch(setDeleteServerConfirmOpen(true))} | ||
> | ||
Delete Server | ||
</DeleteServer> | ||
</SettingsList> | ||
</NavContainer> | ||
</Container> | ||
); | ||
} | ||
|
||
const Container = tw.div` | ||
flex flex-col items-end w-1/2 bg-gray-100 | ||
`; | ||
|
||
const NavContainer = tw.nav` | ||
w-[218px] py-15 pr-1.5 pl-5 | ||
`; | ||
|
||
const SettingsList = tw.ol` | ||
`; | ||
|
||
const ListHeading = tw.h3` | ||
px-2.5 pb-1.5 text-xs font-bold | ||
`; | ||
|
||
const ListItem = tw.li` | ||
px-2.5 py-1.5 mb-0.5 font-medium rounded-md cursor-pointer | ||
hover:bg-gray-200 | ||
`; | ||
|
||
const Divider = tw.div` | ||
h-px mx-2.5 my-2 bg-gray-200 | ||
`; | ||
|
||
const DeleteServer = tw(ListItem)` | ||
text-red-500 | ||
`; |
Oops, something went wrong.
7dddebb
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.
Successfully deployed to the following URLs: