-
Notifications
You must be signed in to change notification settings - Fork 522
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
1 parent
e0eb9d8
commit a939247
Showing
10 changed files
with
81 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
export function useView(name: string): [string, (view: string) => void] { | ||
const [view, setView] = useState(() => localStorage.getItem(name) || "board"); | ||
|
||
const updateView = (view: string) => { | ||
setView(view); | ||
localStorage.setItem(name, view); | ||
}; | ||
|
||
useEffect(() => { | ||
const handleStorageChange = () => { | ||
setView(localStorage.getItem(name) || "board"); | ||
}; | ||
|
||
window.addEventListener("storage", handleStorageChange); | ||
|
||
return () => { | ||
window.removeEventListener("storage", handleStorageChange); | ||
}; | ||
}, [name]); | ||
|
||
return [view, updateView]; | ||
} |
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,27 @@ | ||
import React, { ComponentType } from "react"; | ||
|
||
import { useView } from "@/Utils/useView"; | ||
|
||
export default function View({ | ||
name, | ||
board, | ||
list, | ||
}: { | ||
name: string; | ||
board: ComponentType<{ setView: (view: string) => void }>; | ||
list: ComponentType<{ setView: (view: string) => void }>; | ||
}) { | ||
const [view, setView] = useView(`${name}DefaultView`); | ||
|
||
const views: Record< | ||
"board" | "list", | ||
ComponentType<{ setView: (view: string) => void }> | ||
> = { | ||
board, | ||
list, | ||
}; | ||
|
||
const SelectedView = views[view as keyof typeof views] || board; | ||
|
||
return <SelectedView setView={setView} />; | ||
} |
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