Skip to content

Commit

Permalink
updated comments styles
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanu-dutta committed Jan 15, 2022
1 parent 10cf7e3 commit 0e7cc5c
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 70 deletions.
49 changes: 49 additions & 0 deletions app/components/Comment/Comment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useState } from "react";
import { Link } from "remix";
import type { LinksFunction } from "remix";
import type { Comment as CommentType } from "~/types";
import stylesUrl from "./comment.css";

export const links: LinksFunction = () => {
return [{ href: stylesUrl, rel: "stylesheet" }];
};

type CommentProps = {
comment: CommentType;
};

export default function Comment({ comment }: CommentProps) {
const [hidden, hide] = useState(false);
return (
<>
{!comment.deleted && (
<article className="comment">
<div
className={`meta-bar ${hidden ? "hidden" : ""}`}
onClick={() => hide(!hidden)}
>
<span className="meta">
<Link to={`/user/${comment.user}`}>{comment.user}</Link>{" "}
{comment.time_ago}
</span>
</div>

<div
className="body"
dangerouslySetInnerHTML={{ __html: comment.content }}
></div>

{!hidden && comment.comments.length > 0 && (
<ul className="children">
{comment.comments.map((c) => (
<li key={c.id}>
<Comment comment={c} />
</li>
))}
</ul>
)}
</article>
)}
</>
);
}
46 changes: 46 additions & 0 deletions app/components/Comment/comment.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.comment {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
html.dark .comment {
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.comment .meta-bar {
padding: 1em 0;
cursor: pointer;
background: 100% 50% no-repeat url(/assets/icons/fold.svg);
background-size: 1em 1em;
}
.comment .hidden.meta-bar {
background-image: url(/assets/icons/unfold.svg);
}
.comment .children {
padding: 0 0 0 1em;
margin: 0;
}
.comment .hidden .body,
.comment .hidden .children {
display: none;
}
@media (min-width: 720px) {
.comment .children {
padding: 0 0 0 2em;
}
}
.comment li {
list-style: none;
}
.comment .meta {
display: block;
font-size: 14px;
color: var(--fg-light);
}
.comment a {
color: var(--fg-light);
}
/* prevent crazy overflow layout bug on mobile */
.comment .body :global(*) {
overflow-wrap: break-word;
}
.comment :global(pre) {
overflow-x: auto;
}
43 changes: 0 additions & 43 deletions app/components/Comments/Comments.tsx

This file was deleted.

42 changes: 23 additions & 19 deletions app/components/Item/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
import { Link } from "remix";
import type { LinksFunction } from "remix";
import type { Item } from "~/types";
import Comments from "../Comments/Comments";
import Comment from "../Comment/Comment";
import stylesUrl from "./item.css";

type ItemProps = {
item: Item;
};

export const links: LinksFunction = () => {
return [{ href: stylesUrl, rel: "stylesheet" }];
};

export default function Item({ item }: ItemProps) {
const comments = item.comments.map((comment) => {
return <Comments key={comment.id} comment={comment} />;
return <Comment key={comment.id} comment={comment} />;
});
return (
<div className="item">
<div
className="top-matter"
style={{
borderBottom: "1em solid rgba(0,0,0,0.1)",
paddingBottom: "0.5rem",
}}
>
<h1 className="header">{item.title}</h1>
<small className="subheader">
<a href={item.url} className="link">
{item.domain}
</a>
</small>
<p className="info">
{item.points} by{" "}
<div>
<article className="item">
<a className="main-link" href={item.url}>
<h1>{item.title}</h1>
{item.domain && <small>{item.domain}</small>}
</a>

<p className="meta">
{item.points} points by{" "}
<Link to={`/user/${item.user}`} prefetch="intent">
{item.user}
</Link>{" "}
{item.time_ago}
</p>
</div>

{item.content && (
<div dangerouslySetInnerHTML={{ __html: item.content }}></div>
)}
</article>

<div className="comments">{comments}</div>
</div>
);
Expand Down
27 changes: 27 additions & 0 deletions app/components/Item/item.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.item h1 {
font-weight: 500;
}
.item {
border-bottom: 1em solid rgba(0, 0, 0, 0.1);
margin: 0 -2em 2em -2em;
padding: 0 2em 2em 2em;
}
html.dark .item {
border-bottom: 1em solid rgba(255, 255, 255, 0.1);
}
.item .main-link {
display: block;
text-decoration: none;
}
.item small {
display: block;
font-size: 14px;
}
.item .meta {
font-size: 0.8em;
font-weight: 300;
color: var(--fg-light);
}
.item .comments > :global(.comment):first-child {
border-top: none;
}
2 changes: 1 addition & 1 deletion app/components/Loader/loader.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
align-items: center;
}

:global(html).dark .loader-container {
html.dark .loader-container {
background-color: rgba(255, 255, 255, 0.3);
color: var(--fg);
}
Expand Down
2 changes: 0 additions & 2 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ import stylesUrl from "~/styles/global.css";
import { links as headerLinks } from "~/components/Header/Header";
import { links as loaderLinks } from "~/components/Loader/Loader";
import { links as themeTogglerLinks } from "~/components/ThemeToggler/ThemeToggler";
import { links as articleLinks } from "~/components/Article/Article";

export const links: LinksFunction = () => {
return [
{ href: stylesUrl, rel: "stylesheet" },
...headerLinks(),
...loaderLinks(),
...themeTogglerLinks(),
...articleLinks(),
];
};

Expand Down
9 changes: 6 additions & 3 deletions app/routes/$list.$page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { json, Link, useLoaderData } from "remix";
import type { LoaderFunction, MetaFunction } from "remix";

import type { LoaderFunction, LinksFunction, MetaFunction } from "remix";
import type { ArticleResponseType } from "~/types";

import ArticleList from "~/components/ArticleList";
import { links as articleLinks } from "~/components/Article/Article";
import { AppTitle } from "~/constants";

type LoaderData = {
Expand Down Expand Up @@ -40,6 +39,10 @@ export const meta: MetaFunction = ({ data }) => {
};
};

export const links: LinksFunction = () => {
return [...articleLinks()];
};

export default function ListPageRoute() {
const data = useLoaderData<LoaderData>();

Expand Down
9 changes: 7 additions & 2 deletions app/routes/item.$id.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { redirect, useLoaderData } from "remix";
import type { LoaderFunction, MetaFunction } from "remix";
import Item from "~/components/Item/Item";
import type { LinksFunction, LoaderFunction, MetaFunction } from "remix";
import Item, { links as itemLinks } from "~/components/Item/Item";
import { links as commentLinks } from "~/components/Comment/Comment";
import type { Item as ItemType } from "~/types";
import { AppTitle } from "~/constants";

Expand All @@ -22,6 +23,10 @@ export const meta: MetaFunction = ({ data }: { data: ItemRouteLoaderData }) => {
};
};

export const links: LinksFunction = () => {
return [...itemLinks(), ...commentLinks()];
};

export default function ItemRoute() {
const { item } = useLoaderData<ItemRouteLoaderData>();
return <Item item={item} />;
Expand Down
1 change: 1 addition & 0 deletions app/types/item-comment.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export type Comment = {
level: number;
url: string;
comments: Comment[];
deleted: boolean;
};
5 changes: 5 additions & 0 deletions public/assets/icons/fold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/assets/icons/unfold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0e7cc5c

Please sign in to comment.