Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit e58aa972 authored by Muhammad Zaki's avatar Muhammad Zaki
Browse files

feat: added story component

parent 4efeb2fa
No related branches found
No related tags found
No related merge requests found
type t = {
id: int,
title: string,
points: int,
user: string,
time: int,
time_ago: string,
comments_count: int,
\"type": string,
url?: string,
domain?: string,
comments: array<Comment.t>
}
@react.component
let make = (~story: t) => {
<li className="news-item">
<span className="score"> {story.points->React.int} </span>
<span className="title">
{switch story.url {
| Some(url) if !Js.String2.startsWith(url, "item?id=") =>
<>
<a href={url} target="_blank" rel="noreferrer"> {story.title->React.string} </a>
{" "->React.string}
<span className="host"> {story.domain->Belt.Option.getExn->React.string} </span>
</>
| _ => <Link href={`/item/${story.id->Js.Int.toString}`}> {story.title->React.string} </Link>
}}
</span>
<br />
<span className="meta">
{story.\"type" !== "job"
? <>
{"by "->React.string}
<Link href={`/users/${story.user}`}> {story.user->React.string} </Link>
{" "->React.string}
{story.time_ago->React.string}
{" | "->React.string}
<Link href={`/stories/${story.id->Js.Int.toString}`}>
{(
story.comments_count > 0
? `${story.comments_count->Js.Int.toString} comments`
: "discuss"
)->React.string}
</Link>
</>
: React.null}
</span>
{" "->React.string}
{story.\"type" !== "link"
? <span className="label"> {story.\"type"->React.string} </span>
: React.null}
</li>
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment