-
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.
💥 feat!: Added configContext and completed tasks toogle
- Loading branch information
1 parent
53ead06
commit db88625
Showing
7 changed files
with
118 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use client"; | ||
|
||
import { useConfig } from "@/app/_lib/contexts/ConfigContext"; | ||
|
||
export function CompletedTasksSwap() { | ||
const { config, updateConfig } = useConfig(); | ||
|
||
const showCompletedTasks = config.showCompletedTasks; | ||
|
||
function toggleShowCompletedTasks() { | ||
updateConfig({ ...config, showCompletedTasks: !showCompletedTasks }); | ||
} | ||
|
||
return ( | ||
<label className="swap swap-flip"> | ||
{/* this hidden checkbox controls the state */} | ||
<input | ||
type="checkbox" | ||
checked={showCompletedTasks} | ||
onChange={toggleShowCompletedTasks} | ||
/> | ||
|
||
{/* eye icon */} | ||
|
||
<svg | ||
className="swap-on fill-current w-12 h-12" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
> | ||
<path d="M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z" /> | ||
<path | ||
fillRule="evenodd" | ||
d="M1.323 11.447C2.811 6.976 7.028 3.75 12.001 3.75c4.97 0 9.185 3.223 10.675 7.69.12.362.12.752 0 1.113-1.487 4.471-5.705 7.697-10.677 7.697-4.97 0-9.186-3.223-10.675-7.69a1.762 1.762 0 0 1 0-1.113ZM17.25 12a5.25 5.25 0 1 1-10.5 0 5.25 5.25 0 0 1 10.5 0Z" | ||
clipRule="evenodd" | ||
/> | ||
</svg> | ||
|
||
{/* closed eye icon */} | ||
<svg | ||
className="swap-off fill-current w-12 h-12" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
> | ||
|
||
<path d="M3.53 2.47a.75.75 0 0 0-1.06 1.06l18 18a.75.75 0 1 0 1.06-1.06l-18-18ZM22.676 12.553a11.249 11.249 0 0 1-2.631 4.31l-3.099-3.099a5.25 5.25 0 0 0-6.71-6.71L7.759 4.577a11.217 11.217 0 0 1 4.242-.827c4.97 0 9.185 3.223 10.675 7.69.12.362.12.752 0 1.113Z" /> | ||
<path d="M15.75 12c0 .18-.013.357-.037.53l-4.244-4.243A3.75 3.75 0 0 1 15.75 12ZM12.53 15.713l-4.243-4.244a3.75 3.75 0 0 0 4.244 4.243Z" /> | ||
<path d="M6.75 12c0-.619.107-1.213.304-1.764l-3.1-3.1a11.25 11.25 0 0 0-2.63 4.31c-.12.362-.12.752 0 1.114 1.489 4.467 5.704 7.69 10.675 7.69 1.5 0 2.933-.294 4.242-.827l-2.477-2.477A5.25 5.25 0 0 1 6.75 12Z" /> | ||
</svg> | ||
|
||
</label> | ||
); | ||
} |
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,42 @@ | ||
"use client"; | ||
|
||
// ConfigContext.tsx | ||
import React, { createContext, useState, useContext, ReactNode } from "react"; | ||
|
||
const ConfigContext = createContext<any | null>(null); | ||
|
||
export interface TasksConfig { | ||
checkAudio: string; | ||
uncheckAudio: string; | ||
deleteAudio: string; | ||
showCompletedTasks: boolean; | ||
} | ||
|
||
const initialConfig: TasksConfig = { | ||
checkAudio: "./sounds/[Original] completedTaskSound.mp3", | ||
uncheckAudio: "./sounds/CompletedTaskBassInverted.mpeg", | ||
deleteAudio: "./sounds/delete.mp3", | ||
showCompletedTasks: true, | ||
}; | ||
|
||
export const ConfigContextProvider = ({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) => { | ||
const [config, setConfig] = useState<TasksConfig>(initialConfig); | ||
|
||
const updateConfig = (newConfig: TasksConfig) => { | ||
setConfig({ ...newConfig }); | ||
}; | ||
|
||
return ( | ||
<ConfigContext.Provider value={{ config, updateConfig }}> | ||
{children} | ||
</ConfigContext.Provider> | ||
); | ||
}; | ||
|
||
export const useConfig = () => { | ||
return useContext(ConfigContext); | ||
}; |
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