-
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.
Browse files
Browse the repository at this point in the history
#89 simulate calls
- Loading branch information
Showing
12 changed files
with
486 additions
and
343 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,65 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import service from "services/call.service"; | ||
import S from "./styled"; | ||
import { formatTime } from "utils/helpers"; | ||
|
||
interface IProps { | ||
type: "outgoing" | "received" | ||
contactName: string; | ||
phone: string; | ||
} | ||
|
||
const VoiceCall = ({ contactName, type, phone }: IProps) => { | ||
const { t } = useTranslation(); | ||
const currentTimer = React.useRef<NodeJS.Timeout>(); | ||
const [isCallActive, setIsCallActive] = React.useState(false); | ||
const [isConnecting, setIsConnecting] = React.useState(false); | ||
const [callTime, setCallTime] = React.useState<number>(0); | ||
const [callStartDate, setCallStartDate] = React.useState<number>(0); | ||
|
||
const startCall = () => { | ||
setIsConnecting(true); | ||
setIsCallActive(true); | ||
setTimeout(() => { | ||
currentTimer.current = setInterval(() => { | ||
setCallTime(state => state += 1); | ||
}, 1000); | ||
setCallStartDate(Date.now()); | ||
setIsConnecting(false); | ||
}, 3000) | ||
} | ||
|
||
const endCall = () => { | ||
clearInterval(currentTimer.current); | ||
setIsCallActive(false); | ||
service.insertCallRecord({ | ||
contactName, | ||
startDate: callStartDate, | ||
endDate: Date.now(), | ||
phone, | ||
type | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<S.MainContainer> | ||
{ | ||
isCallActive | ||
? isConnecting ? `Calling ${contactName}...` : formatTime(callTime) | ||
: formatTime(callTime) | ||
} | ||
</S.MainContainer> | ||
<S.ButtonContainer> | ||
{ | ||
isCallActive | ||
? <button onClick={() => endCall()}>{t("end")}</button> | ||
: <button onClick={() => startCall()}>{t("start")}</button> | ||
} | ||
</S.ButtonContainer> | ||
</> | ||
) | ||
} | ||
|
||
export default VoiceCall; |
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,46 @@ | ||
import styled from "styled-components"; | ||
|
||
export const MainContainer = styled.div` | ||
height: 80%; | ||
display: flex; | ||
flex-flow: column; | ||
justify-content: center; | ||
align-items: center; | ||
overflow: auto; | ||
`; | ||
|
||
export const ButtonContainer = styled.div` | ||
height: 20%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
|
||
export const ResultsBox = styled.div` | ||
min-height: 30%; | ||
width: 100%; | ||
align-items: center; | ||
justify-content: center; | ||
display: flex; | ||
`; | ||
|
||
export const Item = styled.button` | ||
min-height: 30%; | ||
width: 100%; | ||
border: none; | ||
&:active, &:focus { | ||
font-weight: bold; | ||
background-color: #000000c6; | ||
color: #ffffffc6; | ||
} | ||
`; | ||
|
||
const S = { | ||
ButtonContainer, | ||
MainContainer, | ||
Item, | ||
ResultsBox, | ||
} | ||
|
||
export default S; |
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,9 @@ | ||
import { StorageEntity } from "./storageEntity"; | ||
|
||
export interface CallRecord extends StorageEntity { | ||
contactName: string | ||
type: "received" | "outgoing" | ||
phone: string | ||
startDate: number | ||
endDate: number | ||
} |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export interface StorageEntity { | ||
id: string | ||
date: string | ||
import { generateId } from "utils/helpers" | ||
|
||
export class StorageEntity { | ||
id?: string = generateId().toString(); | ||
date?: number = Date.now(); | ||
} |
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 |
---|---|---|
|
@@ -6,5 +6,7 @@ | |
"no": "No", | ||
"done": "Done", | ||
"play": "Play", | ||
"call": "Call" | ||
"call": "Call", | ||
"start": "Start", | ||
"end": "End" | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Profile } from "@interfaces/profile"; | ||
import { Profile } from "interfaces/profile"; | ||
|
||
export const setCurrentProfile = (payload: Profile) => | ||
({ type: "SET_CURRENT_PROFILE", payload }); |
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,12 @@ | ||
import { CallRecord } from "interfaces/callRecord"; | ||
import db from "../utils/db"; | ||
|
||
export const insertCallRecord = (callRecord: CallRecord) => { | ||
db.insert<CallRecord>("callRecords", callRecord); | ||
} | ||
|
||
const service = { | ||
insertCallRecord, | ||
} | ||
|
||
export default service; |
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