Skip to content

Commit

Permalink
feat: updating timer
Browse files Browse the repository at this point in the history
  • Loading branch information
TinySmallM committed Jan 27, 2025
1 parent f1802c1 commit c09b45a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
10 changes: 10 additions & 0 deletions src/misc/dateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ export function isPreviousDay(newerDate: Date, olderDate: Date) {

return isSameDay(previousDate, olderDate)
}

export function formatTime(seconds: number) {
const minutes = Math.floor(seconds / 60)
const remainingSeconds = Math.floor(seconds % 60)

const formattedMinutes = String(minutes).padStart(1, '0')
const formattedSeconds = String(remainingSeconds).padStart(2, '0')

return `${formattedMinutes}:${formattedSeconds}`
}
12 changes: 11 additions & 1 deletion src/ui/messenger/attaches/AttachVoice/AttachVoice.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.AttachVoice {
.AttachVoice__top {
display: flex;
gap: 8px;
color: var(--vkui--color_background_accent_themed);
Expand All @@ -19,3 +19,13 @@
cursor: pointer;
box-shadow: -100px 0 0 100px var(--vkui--color_background_accent_themed);
}

.AttachVoice__time {
display: block;
padding: 2px 0;
font: var(--messageDateFontSize) / var(--messageDateLineHeight) var(--fontFamily);
}

.AttachVoice__details {
color: black;
}
49 changes: 30 additions & 19 deletions src/ui/messenger/attaches/AttachVoice/AttachVoice.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineComponent, InputEvent, shallowRef } from 'vue'
import * as Attach from 'model/Attach'
import { formatTime } from 'misc/dateTime'
import { ButtonIcon } from 'ui/ui/ButtonIcon/ButtonIcon'
import { Icon32PauseCircle, Icon32PlayCircle } from 'assets/icons'
import './AttachVoice.css'
Expand Down Expand Up @@ -33,9 +34,9 @@ export const AttachVoice = defineComponent<Props>((props) => {
const currentPosition = audio.currentTime - min
const percentage = (currentPosition / diff) * 100

range.value = Math.round(percentage)
range.value = percentage

requestAnimationFrame(updateRange)
requestId.value = requestAnimationFrame(updateRange)
}

const toggleAudio = () => {
Expand All @@ -58,27 +59,37 @@ export const AttachVoice = defineComponent<Props>((props) => {
}

return () => {
console.log(range.value)
const getTime = () => {
return audio.currentTime === 0
? formatTime(props.voice.duration)
: formatTime(audio.currentTime)
}

return (
<div class="AttachVoice">
<ButtonIcon onClick={toggleAudio} icon={
isPause.value ? <Icon32PauseCircle /> : <Icon32PlayCircle />
} />
<div class="AttachVoice__track">
<input
class="AttachVoice__range"
type="range"
id="track"
name="track"
value={range.value}
min="0"
max="100"
onChange={(event) => moveRange(event)}
onMousedown={() => (isRange.value = true)}
onMouseup={() => (isRange.value = false)}
/>
<div class="AttachVoice__top">
<ButtonIcon onClick={toggleAudio} icon={
isPause.value ? <Icon32PauseCircle /> : <Icon32PlayCircle />
} />
<div class="AttachVoice__track">
<input
class="AttachVoice__range"
type="range"
id="track"
name="track"
value={range.value}
min="0"
max="100"
onChange={(event) => moveRange(event)}
onTouchstart={() => (isRange.value = true)}
onTouchend={() => (isRange.value = false)}
onMousedown={() => (isRange.value = true)}
onMouseup={() => (isRange.value = false)}
/>
<span class="AttachVoice__time">{getTime()}</span>
</div>
</div>
<div class="AttachVoice__bottom">Тут будет открывашка.</div>
</div>
)
}
Expand Down

0 comments on commit c09b45a

Please sign in to comment.