Skip to content

Commit

Permalink
LiveMode Toggle 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hmu332233 committed Mar 15, 2022
1 parent d0cd54c commit 659d1e6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
9 changes: 9 additions & 0 deletions hooks/useToggle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useState, useCallback } from 'react';

function useToggle(initStatus: boolean = false) {
const [value, setValue] = useState(initStatus);
const toggle = useCallback(() => setValue((v) => !v), []);
return [value, toggle, setValue] as const;
}

export default useToggle;
29 changes: 20 additions & 9 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import CopyModal from 'components/CopyModal';
import Hits from 'components/Hits';

import useDebounce from 'hooks/useDebounce';
import useToggle from 'hooks/useToggle';

import { objectToQueryString } from 'utils/string';

function Home() {
const [isLiveMode, toggleIsLiveMode] = useToggle(true);
const [dateString, setDateString] = useState('');
const [size, setSize] = useState('');
const queryString = useDebounce(
objectToQueryString({ date: dateString, size }),
objectToQueryString({ date: isLiveMode ? '' : dateString, size }),
300,
);

Expand Down Expand Up @@ -49,15 +52,23 @@ function Home() {
<img src={svgUrl} alt="moon.svg" />
</a>
<div className="form-control w-full max-w-xs">
<label className="label">
<span className="label-text">Date</span>
<label className="label cursor-pointer" onClick={toggleIsLiveMode}>
<span className="label-text">Live Mode</span>
<input type="checkbox" className="toggle" checked={isLiveMode} />
</label>
<input
type="date"
className="input input-bordered w-full max-w-xs"
value={dateString}
onChange={handleDateStringChange}
/>
{!isLiveMode && (
<>
<label className="label">
<span className="label-text">Date</span>
</label>
<input
type="date"
className="input input-bordered w-full max-w-xs"
value={dateString}
onChange={handleDateStringChange}
/>
</>
)}
</div>
<div className="form-control w-full max-w-xs">
<label className="label">
Expand Down

1 comment on commit 659d1e6

@vercel
Copy link

@vercel vercel bot commented on 659d1e6 Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.