Skip to content

Commit ad6c458

Browse files
committed
more hackernews tweaks
1 parent de8272b commit ad6c458

2 files changed

Lines changed: 47 additions & 51 deletions

File tree

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createAsync, type RouteDefinition, type RouteSectionProps } from "@solidjs/router";
2-
import { For, Show } from "solid-js";
1+
import { type RouteDefinition, type RouteSectionProps } from "@solidjs/router";
2+
import { For, Show, createMemo } from "solid-js";
33
import Comment from "~/components/comment";
44
import { getStory } from "~/lib/api";
55

@@ -10,31 +10,29 @@ export const route = {
1010
} satisfies RouteDefinition;
1111

1212
export default function Story(props: RouteSectionProps) {
13-
const story = createAsync(() => getStory(props.params.id));
13+
const story = createMemo(() => getStory(props.params.id));
1414
return (
15-
<Show when={story()}>
16-
<div class="item-view">
17-
<div class="item-view-header">
18-
<a href={story()!.url} target="_blank">
19-
<h1>{story()!.title}</h1>
20-
</a>
21-
<Show when={story()!.domain}>
22-
<span class="host">({story()!.domain})</span>
23-
</Show>
24-
<p class="meta">
25-
{story()!.points} points | by <a href={`/users/${story()!.user}`}>{story()!.user}</a>{" "}
26-
{story()!.time_ago} ago
27-
</p>
28-
</div>
29-
<div class="item-view-comments">
30-
<p class="item-view-comments-header">
31-
{story()!.comments_count ? story()!.comments_count + " comments" : "No comments yet."}
32-
</p>
33-
<ul class="comment-children">
34-
<For each={story()!.comments}>{comment => <Comment comment={comment()} />}</For>
35-
</ul>
36-
</div>
15+
<div class="item-view">
16+
<div class="item-view-header">
17+
<a href={story().url} target="_blank">
18+
<h1>{story().title}</h1>
19+
</a>
20+
<Show when={story().domain}>
21+
<span class="host">({story().domain})</span>
22+
</Show>
23+
<p class="meta">
24+
{story().points} points | by <a href={`/users/${story().user}`}>{story().user}</a>{" "}
25+
{story().time_ago} ago
26+
</p>
3727
</div>
38-
</Show>
28+
<div class="item-view-comments">
29+
<p class="item-view-comments-header">
30+
{story().comments_count ? story().comments_count + " comments" : "No comments yet."}
31+
</p>
32+
<ul class="comment-children">
33+
<For each={story().comments}>{comment => <Comment comment={comment()} />}</For>
34+
</ul>
35+
</div>
36+
</div>
3937
);
4038
}
Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createAsync, type RouteDefinition, type RouteSectionProps } from "@solidjs/router";
2-
import { Show } from "solid-js";
1+
import { type RouteDefinition, type RouteSectionProps } from "@solidjs/router";
2+
import { Show, createMemo, Loading } from "solid-js";
33
import { getUser } from "~/lib/api";
44

55
export const route = {
@@ -9,29 +9,27 @@ export const route = {
99
} satisfies RouteDefinition;
1010

1111
export default function User(props: RouteSectionProps) {
12-
const user = createAsync(() => getUser(props.params.id));
12+
const user = createMemo(() => getUser(props.params.id));
1313
return (
14-
<div class="user-view">
15-
<Show when={user()}>
16-
<Show when={!user()!.error} fallback={<h1>User not found.</h1>}>
17-
<h1>User : {user()!.id}</h1>
18-
<ul class="meta">
19-
<li>
20-
<span class="label">Created:</span> {user()!.created}
21-
</li>
22-
<li>
23-
<span class="label">Karma:</span> {user()!.karma}
24-
</li>
25-
<Show when={user()!.about}>
26-
<li innerHTML={user()!.about} class="about" />{" "}
27-
</Show>
28-
</ul>
29-
<p class="links">
30-
<a href={`https://news.ycombinator.com/submitted?id=${user()!.id}`}>submissions</a> |{" "}
31-
<a href={`https://news.ycombinator.com/threads?id=${user()!.id}`}>comments</a>
32-
</p>
33-
</Show>
34-
</Show>
35-
</div>
14+
<Loading fallback={<div>Loading...</div>}>
15+
<div class="user-view">
16+
<h1>User : {user().id}</h1>
17+
<ul class="meta">
18+
<li>
19+
<span class="label">Created:</span> {user().created}
20+
</li>
21+
<li>
22+
<span class="label">Karma:</span> {user().karma}
23+
</li>
24+
<Show when={user().about}>
25+
<li innerHTML={user().about} class="about" />{" "}
26+
</Show>
27+
</ul>
28+
<p class="links">
29+
<a href={`https://news.ycombinator.com/submitted?id=${user().id}`}>submissions</a> |{" "}
30+
<a href={`https://news.ycombinator.com/threads?id=${user().id}`}>comments</a>
31+
</p>
32+
</div>
33+
</Loading>
3634
);
3735
}

0 commit comments

Comments
 (0)