-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 대본 읽기 속도 설정, 계산 추가 (#311) #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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
134 changes: 134 additions & 0 deletions
134
src/components/slide/script/ScriptReadingSpeedModal.tsx
This file contains hidden or 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,134 @@ | ||
| import { useMemo } from 'react'; | ||
| import { useParams } from 'react-router-dom'; | ||
|
|
||
| import { Dropdown, Modal } from '@/components/common'; | ||
| import type { DropdownItem } from '@/components/common/Dropdown'; | ||
| import { useProjectScripts, useScriptReadingSpeed, useSlideId, useSlideScript } from '@/hooks'; | ||
| import { | ||
| SCRIPT_READING_SPEED_MAX, | ||
| SCRIPT_READING_SPEED_MIN, | ||
| estimateScriptsDurationSeconds, | ||
| formatScriptDuration, | ||
| } from '@/utils/scriptDuration'; | ||
|
|
||
| interface ScriptReadingSpeedModalProps { | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| export default function ScriptReadingSpeedModal({ isOpen, onClose }: ScriptReadingSpeedModalProps) { | ||
| const { projectId } = useParams<{ projectId: string }>(); | ||
| const activeProjectId = isOpen ? (projectId ?? '') : ''; | ||
| const { data: projectScripts } = useProjectScripts(activeProjectId); | ||
| const slideId = useSlideId(); | ||
| const script = useSlideScript(); | ||
| const { speedOptions, selectedSpeed, selectedPreset, setSelectedSpeed } = useScriptReadingSpeed(); | ||
|
|
||
| const speedDropdownItems: DropdownItem[] = speedOptions.map((option) => ({ | ||
| id: option.id, | ||
| label: option.label, | ||
| selected: selectedSpeed === option.charsPerMinute, | ||
| onClick: () => setSelectedSpeed(option.charsPerMinute), | ||
| })); | ||
|
|
||
| const scripts = useMemo(() => { | ||
| const scriptMap = new Map<string, string>(); | ||
|
|
||
| (projectScripts?.scripts ?? []).forEach((scriptItem) => { | ||
| scriptMap.set(scriptItem.slideId, scriptItem.scriptText ?? ''); | ||
| }); | ||
|
|
||
| if (slideId) { | ||
| scriptMap.set(slideId, script); | ||
| } else if (scriptMap.size < 1 && script.length > 0) { | ||
| scriptMap.set('current', script); | ||
| } | ||
|
|
||
| return Array.from(scriptMap.values()); | ||
| }, [projectScripts, slideId, script]); | ||
|
|
||
| const totalDurationSeconds = useMemo( | ||
| () => estimateScriptsDurationSeconds(scripts, selectedSpeed), | ||
| [scripts, selectedSpeed], | ||
| ); | ||
| const totalDuration = useMemo( | ||
| () => formatScriptDuration(totalDurationSeconds), | ||
| [totalDurationSeconds], | ||
| ); | ||
| const presetLabel = selectedPreset?.label ?? '직접 설정'; | ||
|
|
||
| return ( | ||
| <Modal isOpen={isOpen} onClose={onClose} title="읽기 속도 설정" size="sm"> | ||
| <div className="flex flex-col gap-4"> | ||
| <div className="flex flex-col gap-2"> | ||
| <span className="text-body-m-bold text-gray-800">프리셋</span> | ||
| <Dropdown | ||
| trigger={({ isOpen }) => ( | ||
| <button | ||
| type="button" | ||
| className={`flex w-full items-center justify-between rounded-lg border border-gray-200 bg-white px-5 py-3 ${isOpen ? 'border-gray-400' : ''}`} | ||
| > | ||
| <span className="text-body-m-bold text-gray-800">{presetLabel}</span> | ||
| <svg | ||
| className={`h-4 w-4 text-gray-600 transition-transform ${isOpen ? 'rotate-180' : ''}`} | ||
| viewBox="0 0 24 24" | ||
| fill="none" | ||
| aria-hidden | ||
| > | ||
| <path | ||
| d="M6 9l6 6 6-6" | ||
| stroke="currentColor" | ||
| strokeWidth="2" | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| /> | ||
| </svg> | ||
| </button> | ||
| )} | ||
| items={speedDropdownItems} | ||
| className="w-full" | ||
| menuClassName="w-full" | ||
| ariaLabel="읽기 속도 프리셋 선택" | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col gap-2"> | ||
| <label htmlFor="script-reading-speed-slider" className="text-body-m-bold text-gray-800"> | ||
| 읽기 속도: 분당 {selectedSpeed}자 | ||
| </label> | ||
| <input | ||
| id="script-reading-speed-slider" | ||
| type="range" | ||
| min={SCRIPT_READING_SPEED_MIN} | ||
| max={SCRIPT_READING_SPEED_MAX} | ||
| step={1} | ||
| value={selectedSpeed} | ||
| onChange={(event) => setSelectedSpeed(Number(event.target.value))} | ||
| className="h-2 w-full cursor-pointer accent-main" | ||
| /> | ||
| <div className="flex items-center justify-between text-caption text-gray-600"> | ||
| <span>매우 느리게</span> | ||
| <span>매우 빠르게</span> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="rounded-lg bg-gray-100 px-4 py-3"> | ||
| <p className="text-sm text-gray-600">전체 대본 예상 읽기 시간</p> | ||
| <p className="text-body-m-bold text-gray-800">{totalDuration}</p> | ||
| </div> | ||
|
|
||
| <p className="text-sm leading-5 text-gray-600"> | ||
| 예상 시간은 전체 대본의 공백을 제외한 글자 수를 기준으로 계산됩니다. | ||
| </p> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={onClose} | ||
| className="w-full rounded-md bg-main py-3 font-bold text-white transition-colors hover:bg-main-variant2" | ||
| > | ||
| 확인 | ||
| </button> | ||
| </div> | ||
| </Modal> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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,36 @@ | ||
| import { useMemo } from 'react'; | ||
|
|
||
| import { useScriptReadingSpeedStore } from '@/stores/scriptReadingSpeedStore'; | ||
| import { | ||
| SCRIPT_READING_SPEED_OPTIONS, | ||
| type ScriptReadingSpeedPresetId, | ||
| getScriptReadingSpeedPreset, | ||
| normalizeScriptReadingSpeed, | ||
| } from '@/utils/scriptDuration'; | ||
|
|
||
| export function useScriptReadingSpeed() { | ||
| const speed = useScriptReadingSpeedStore((state) => state.speed); | ||
| const setSpeed = useScriptReadingSpeedStore((state) => state.setSpeed); | ||
|
|
||
| const selectedSpeed = useMemo(() => normalizeScriptReadingSpeed(speed), [speed]); | ||
| const selectedPreset = useMemo(() => getScriptReadingSpeedPreset(selectedSpeed), [selectedSpeed]); | ||
| const selectedSpeedLabel = useMemo( | ||
| () => selectedPreset?.label ?? `직접 설정 (분당 ${selectedSpeed}자)`, | ||
| [selectedPreset, selectedSpeed], | ||
| ); | ||
|
|
||
| const setSelectedPresetId = (presetId: ScriptReadingSpeedPresetId) => { | ||
| const selectedOption = SCRIPT_READING_SPEED_OPTIONS.find((option) => option.id === presetId); | ||
| if (!selectedOption) return; | ||
| setSpeed(selectedOption.charsPerMinute); | ||
| }; | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return { | ||
| speedOptions: SCRIPT_READING_SPEED_OPTIONS, | ||
| selectedSpeed, | ||
| selectedPreset, | ||
| selectedSpeedLabel, | ||
| setSelectedSpeed: setSpeed, | ||
| setSelectedPresetId, | ||
| }; | ||
| } | ||
This file contains hidden or 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,35 @@ | ||
| import { create } from 'zustand'; | ||
| import { persist } from 'zustand/middleware'; | ||
|
|
||
| import { | ||
| DEFAULT_SCRIPT_READING_SPEED, | ||
| SCRIPT_READING_SPEED_STORAGE_KEY, | ||
| normalizeScriptReadingSpeed, | ||
| } from '@/utils/scriptDuration'; | ||
|
|
||
| interface ScriptReadingSpeedState { | ||
| speed: number; | ||
| setSpeed: (nextSpeed: number) => void; | ||
| } | ||
|
|
||
| export const useScriptReadingSpeedStore = create<ScriptReadingSpeedState>()( | ||
| persist( | ||
| (set) => ({ | ||
| speed: DEFAULT_SCRIPT_READING_SPEED, | ||
| setSpeed: (nextSpeed) => { | ||
| set({ speed: normalizeScriptReadingSpeed(nextSpeed) }); | ||
| }, | ||
| }), | ||
| { | ||
| name: SCRIPT_READING_SPEED_STORAGE_KEY, | ||
| partialize: (state) => ({ speed: state.speed }), | ||
| onRehydrateStorage: () => (state) => { | ||
| if (!state) return; | ||
| const normalizedSpeed = normalizeScriptReadingSpeed(state.speed); | ||
| if (state.speed !== normalizedSpeed) { | ||
| state.setSpeed(normalizedSpeed); | ||
| } | ||
| }, | ||
| }, | ||
| ), | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.