feat(app): add persistence of settings across sessions
This commit is contained in:
@@ -8,12 +8,14 @@ import Footer from "../Footer/Footer";
|
||||
import ErrorBoundary from "../ErrorBoundary/ErrorBoundary";
|
||||
import Notice from "../Notice/Notice";
|
||||
import useIconParameters from "../../hooks/useIconParameters";
|
||||
import usePersistSettings from "../../hooks/usePersistSettings";
|
||||
|
||||
const errorFallback = <Notice message="Search error" />;
|
||||
const waitingFallback = <Notice type="none" message="" />;
|
||||
|
||||
const App: React.FC<any> = () => {
|
||||
useIconParameters();
|
||||
usePersistSettings();
|
||||
|
||||
return (
|
||||
<React.StrictMode>
|
||||
|
||||
13
src/components/SettingsActions/SettingsActions.css
Normal file
13
src/components/SettingsActions/SettingsActions.css
Normal file
@@ -0,0 +1,13 @@
|
||||
.action-button {
|
||||
background-color: rgba(255, 255, 255, 0.05);
|
||||
color: white;
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 558px) {
|
||||
.action-button {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
53
src/components/SettingsActions/SettingsActions.tsx
Normal file
53
src/components/SettingsActions/SettingsActions.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import React from "react";
|
||||
import { ArrowCounterClockwise, CheckCircle, Link } from "phosphor-react";
|
||||
import { useRecoilValue, useResetRecoilState } from "recoil";
|
||||
import { iconWeightAtom, iconSizeAtom, iconColorAtom } from "../../state/atoms";
|
||||
import "./SettingsActions.css";
|
||||
import useTransientState from "../../hooks/useTransientState";
|
||||
import { resetSettingsSelector } from "../../state/selectors";
|
||||
|
||||
const SettingsActions: React.FC = () => {
|
||||
const weight = useRecoilValue(iconWeightAtom);
|
||||
const size = useRecoilValue(iconSizeAtom);
|
||||
const color = useRecoilValue(iconColorAtom);
|
||||
const reset = useResetRecoilState(resetSettingsSelector);
|
||||
|
||||
const [copied, setCopied] = useTransientState<boolean>(false, 2000);
|
||||
|
||||
const copyDeepLinkToClipboard = () => {
|
||||
const paramString = new URLSearchParams([
|
||||
["weight", weight.toString()],
|
||||
["size", size.toString()],
|
||||
["color", color.replace("#", "")],
|
||||
]).toString();
|
||||
void navigator.clipboard?.writeText(
|
||||
`${window.location.host}?${paramString}`
|
||||
);
|
||||
setCopied(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
className="action-button"
|
||||
title="Restore default settings"
|
||||
onClick={reset}
|
||||
>
|
||||
<ArrowCounterClockwise size={24} />
|
||||
</button>
|
||||
<button
|
||||
className="action-button"
|
||||
title="Copy URL for current settings"
|
||||
onClick={copyDeepLinkToClipboard}
|
||||
>
|
||||
{copied ? (
|
||||
<CheckCircle size={24} color="#1FA647" weight="fill" />
|
||||
) : (
|
||||
<Link size={24} />
|
||||
)}
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingsActions;
|
||||
@@ -5,6 +5,7 @@ import StyleInput from "../StyleInput/StyleInput";
|
||||
import SearchInput from "../SearchInput/SearchInput";
|
||||
import SizeInput from "../SizeInput/SizeInput";
|
||||
import ColorInput from "../ColorInput/ColorInput";
|
||||
import SettingsActions from "../SettingsActions/SettingsActions";
|
||||
|
||||
type ToolbarProps = {};
|
||||
|
||||
@@ -16,6 +17,7 @@ const Toolbar: React.FC<ToolbarProps> = () => {
|
||||
<SearchInput />
|
||||
<SizeInput />
|
||||
<ColorInput />
|
||||
<SettingsActions />
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user