forked from JensvandeWiel/ArkAscendedServerManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'JensvandeWiel:main' into main
- Loading branch information
Showing
18 changed files
with
743 additions
and
190 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 @@ | ||
import React, { createContext, useContext, useState, ReactNode } from 'react'; | ||
import { Alert } from '@mui/joy'; | ||
import {IconX} from "@tabler/icons-react"; | ||
|
||
type AlertContextType = { | ||
addAlert: (message: string, severity: "success" | "warning" | "primary" | "neutral" | "danger" | undefined) => void; | ||
alerts: Alert[]; | ||
}; | ||
|
||
const AlertContext = createContext<AlertContextType | undefined>(undefined); | ||
|
||
type AlertProviderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
type Alert = { | ||
message: string; | ||
severity: "success" | "warning" | "primary" | "neutral" | "danger" | undefined | ||
}; | ||
|
||
export function AlertProvider({ children }: AlertProviderProps) { | ||
|
||
const [alerts, setAlerts] = useState<Alert[]>([]) | ||
|
||
const addAlert = (message: string, severity: "success" | "warning" | "primary" | "neutral" | "danger" | undefined) => { | ||
const newAlert = { message, severity }; | ||
setAlerts([...alerts, newAlert]); | ||
|
||
console.log(alerts) | ||
}; | ||
|
||
const removeAlert = (index: number) => { | ||
const updatedAlerts = [...alerts]; | ||
updatedAlerts.splice(index, 1); | ||
setAlerts(updatedAlerts); | ||
}; | ||
|
||
return ( | ||
<AlertContext.Provider value={{ addAlert, alerts }}> | ||
{children} | ||
|
||
<div className={"m-4 absolute bottom-0 w-[80vw] left-1/2 -ml-[40vw]"}> | ||
{alerts.map((alert, index) => ( | ||
<Alert key={index} className={"m-4 "} color={alert.severity} endDecorator={<IconX onClick={() => removeAlert(index)}/>}> | ||
{alert.message} | ||
</Alert> | ||
))} | ||
</div> | ||
</AlertContext.Provider> | ||
); | ||
} | ||
|
||
export function useAlert() { | ||
const context = useContext(AlertContext); | ||
if (!context) { | ||
throw new Error('useAlert must be used within an AlertProvider'); | ||
} | ||
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
Oops, something went wrong.