-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor code to use consistent naming conventions and improve…
… code readability
- Loading branch information
Showing
14 changed files
with
297 additions
and
121 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,66 +1,66 @@ | ||
const ChatOtherMessage = ( | ||
{ time, message, sender, senderNickName, isPrimary }: { | ||
time: string | ||
message: string | ||
sender: string | ||
senderNickName: string | ||
isPrimary: boolean | ||
}, | ||
{ time, message, sender, senderNickName, isPrimary }: { | ||
time: string | ||
message: string | ||
sender: string | ||
senderNickName: string | ||
isPrimary: boolean | ||
}, | ||
) => { | ||
const isPrimaryClass = isPrimary ? "c-talk-chat other primary" : "c-talk-chat other subsequent" | ||
const isPrimaryClass = isPrimary ? "c-talk-chat other primary" : "c-talk-chat other subsequent" | ||
|
||
return ( | ||
<li class={isPrimaryClass}> | ||
<div class="c-talk-chat-box"> | ||
{isPrimary && ( | ||
<div class="c-talk-chat-icon"> | ||
<img | ||
src={`/api/v1/friends/${sender}/icon/`} | ||
alt="" | ||
class="rounded-full text-white dark:text-black" | ||
/> | ||
</div> | ||
)} | ||
return ( | ||
<li class={isPrimaryClass}> | ||
<div class="c-talk-chat-box"> | ||
{isPrimary && ( | ||
<div class="c-talk-chat-icon"> | ||
<img | ||
src={`/api/v1/friends/${sender}/icon/`} | ||
alt="" | ||
class="rounded-full text-white dark:text-black" | ||
/> | ||
</div> | ||
)} | ||
|
||
<div class="c-talk-chat-right"> | ||
{isPrimary && ( | ||
<div class="c-talk-chat-name"> | ||
<p>{senderNickName}</p> | ||
</div> | ||
)} | ||
<div class="c-talk-chat-right"> | ||
{isPrimary && ( | ||
<div class="c-talk-chat-name"> | ||
<p>{senderNickName}</p> | ||
</div> | ||
)} | ||
|
||
<div class="c-talk-chat-msg"> | ||
<p> | ||
{convertLineBreak(message)} | ||
</p> | ||
</div> | ||
</div> | ||
<div class="c-talk-chat-date"> | ||
<p>{convertTime(time)}</p> | ||
</div> | ||
</div> | ||
</li> | ||
) | ||
<div class="c-talk-chat-msg"> | ||
<p> | ||
{convertLineBreak(message)} | ||
</p> | ||
</div> | ||
</div> | ||
<div class="c-talk-chat-date"> | ||
<p>{convertTime(time)}</p> | ||
</div> | ||
</div> | ||
</li> | ||
) | ||
} | ||
//preactで動作する改行を反映させるために、改行コードをbrタグに変換する関数 | ||
function convertLineBreak(message: string | null | undefined) { | ||
if (message === null || message === undefined) return | ||
return message.split("\n").map((line, index) => ( | ||
<span key={index}> | ||
{line} | ||
<br /> | ||
</span> | ||
)) | ||
if (message === null || message === undefined) return | ||
return message.split("\n").map((line, index) => ( | ||
<span key={index}> | ||
{line} | ||
<br /> | ||
</span> | ||
)) | ||
} | ||
//Date型のデータを受け取り、午前か午後何時何分かを返す関数 | ||
function convertTime(time: string | number | Date) { | ||
const date = new Date(time) | ||
const hours = date.getHours() | ||
const minutes = date.getMinutes() | ||
const ampm = hours >= 12 ? "午後" : "午前" | ||
const hour = hours % 12 | ||
const zeroPaddingHour = hour === 0 ? 12 : hour | ||
const zeroPaddingMinutes = String(minutes).padStart(2, "0") | ||
return `${ampm} ${zeroPaddingHour}:${zeroPaddingMinutes}` | ||
const date = new Date(time) | ||
const hours = date.getHours() | ||
const minutes = date.getMinutes() | ||
const ampm = hours >= 12 ? "午後" : "午前" | ||
const hour = hours % 12 | ||
const zeroPaddingHour = hour === 0 ? 12 : hour | ||
const zeroPaddingMinutes = String(minutes).padStart(2, "0") | ||
return `${ampm} ${zeroPaddingHour}:${zeroPaddingMinutes}` | ||
} | ||
export default ChatOtherMessage | ||
export default ChatOtherMessage |
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
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
Oops, something went wrong.