-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
246 additions
and
55 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
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { atom, useSetAtom } from 'jotai'; | ||
import { atomEffect } from 'jotai-effect' | ||
import faviconDefault from '/favicon_default.svg'; | ||
import faviconOnline from '/favicon_online.svg'; | ||
import faviconPartial from '/favicon_partial.svg'; | ||
import faviconOffline from '/favicon_offline.svg'; | ||
import { globalStatusAtom } from './socketio'; | ||
|
||
/** | ||
* This atom is used to change the key of the main page error boundry, which also resets the router | ||
* as a side effect. This is used to reset the page that errored as well as resetting the current | ||
* page when the user clicks on the active menu link. | ||
*/ | ||
export const contentRefreshKeyAtom = atom(0); | ||
|
||
//Hook to refresh content | ||
export const useContentRefresh = () => { | ||
const setContentRefreshKey = useSetAtom(contentRefreshKeyAtom); | ||
return () => setContentRefreshKey(Math.random()); | ||
}; | ||
|
||
/** | ||
* This atom describes if the main page is in error state or not. | ||
* When the page is in error, clicking on any menu link will reset the error boundry and router, | ||
* therefore also resetting the page that errored. | ||
*/ | ||
export const pageErrorStatusAtom = atom(false); | ||
|
||
|
||
|
||
/** | ||
* Page title management | ||
*/ | ||
const faviconEl = document.getElementById('favicon') as HTMLLinkElement; | ||
const pageTitleAtom = atom('txAdmin'); | ||
|
||
export const useSetPageTitle = () => { | ||
const setPageTitle = useSetAtom(pageTitleAtom); | ||
return (title = 'txAdmin') => setPageTitle(title); | ||
} | ||
|
||
export const pageTitleWatcher = atomEffect((get, set) => { | ||
if (!window.txConsts.isWebInterface) return; | ||
const pageTitle = get(pageTitleAtom); | ||
const globalStatus = get(globalStatusAtom); | ||
|
||
if (!globalStatus) { | ||
faviconEl.href = faviconDefault; | ||
document.title = 'txAdmin'; | ||
} else { | ||
if(globalStatus.server.status === 'ONLINE'){ | ||
faviconEl.href = faviconOnline; | ||
}else if(globalStatus.server.status === 'PARTIAL'){ | ||
faviconEl.href = faviconPartial; | ||
} else { | ||
faviconEl.href = faviconOffline; | ||
} | ||
document.title = `(${globalStatus.server.players}) ${globalStatus.server.name} · ${pageTitle}`; | ||
} | ||
|
||
return () => { | ||
faviconEl.href = faviconDefault; | ||
document.title = 'txAdmin'; | ||
} | ||
}); |
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