Skip to content

Commit 1c177aa

Browse files
committed
fix landing page
1 parent bdf30af commit 1c177aa

11 files changed

Lines changed: 297 additions & 156 deletions

File tree

package-lock.json

Lines changed: 204 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
},
2525
"homepage": "https://github.com/ryansolid/solid-realworld#readme",
2626
"devDependencies": {
27-
"@babel/core": "7.6.2",
27+
"@babel/core": "7.7.4",
2828
"@babel/plugin-syntax-dynamic-import": "7.2.0",
29-
"babel-preset-solid": "0.2.1",
30-
"rollup": "1.26.0",
29+
"babel-preset-solid": "0.2.3",
30+
"rollup": "1.27.8",
3131
"rollup-plugin-babel": "4.3.3",
3232
"rollup-plugin-clear": "^2.0.7",
3333
"rollup-plugin-node-resolve": "5.2.0",
3434
"rollup-plugin-serve": "^1.0.1",
3535
"rollup-plugin-terser": "5.1.2",
36-
"solid-js": "0.13.0"
36+
"solid-js": "0.14.7"
3737
}
3838
}

src/App.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { lazy } from "solid-js";
2+
import { useStore } from "./store";
3+
4+
const NavBar = lazy(() => import("./components/NavBar")),
5+
Home = lazy(() => import("./components/Home")),
6+
Editor = lazy(() => import("./components/Editor")),
7+
Settings = lazy(() => import("./components/Settings")),
8+
Auth = lazy(() => import("./components/Auth")),
9+
Article = lazy(() => import("./components/Article")),
10+
Profile = lazy(() => import("./components/Profile"));
11+
12+
export default () => {
13+
const [CommonStore, UserStore, { match, getParams }] = useStore(
14+
"common",
15+
"user",
16+
"router"
17+
);
18+
19+
if (!CommonStore.state.token) CommonStore.setAppLoaded();
20+
else UserStore.pullUser().finally(() => CommonStore.setAppLoaded());
21+
22+
return (
23+
<>
24+
<NavBar />
25+
<Show when={CommonStore.state.appLoaded}>
26+
<Switch>
27+
<Match when={match("editor", /^#\/editor\/?(.*)/)}><Editor {...getParams()} /></Match>
28+
<Match when={match("settings", /^#\/settings/)}><Settings /></Match>
29+
<Match when={match("login", /^#\/login/)}><Auth /></Match>
30+
<Match when={match("register", /^#\/register/)}><Auth /></Match>
31+
<Match when={match("article", /^#\/article\/(.*)/)}><Article {...getParams()} /></Match>
32+
<Match when={match("profile", /^#\/@([^/]*)\/?(favorites)?/)}><Profile {...getParams()} /></Match>
33+
<Match when={match("", /^#?$/)}><Home /></Match>
34+
</Switch>
35+
</Show>
36+
</>
37+
);
38+
};

src/components/App.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/components/ArticlePreview.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export default ({ article }) => {
1919
return (
2020
<div class="article-preview">
2121
<div class="article-meta">
22-
<NavLink to={`/@${article.author.username}`}>
22+
<NavLink href={`@${article.author.username}`} route="profile">
2323
<img src={article.author.image} alt="" />
2424
</NavLink>
2525

2626
<div class="info">
27-
<NavLink class="author" to={`/@${article.author.username}`}>
27+
<NavLink class="author" href={`@${article.author.username}`} route="profile">
2828
{article.author.username}
2929
</NavLink>
3030
<span class="date">{new Date(article.createdAt).toDateString()}</span>
@@ -40,7 +40,7 @@ export default ({ article }) => {
4040
</div>
4141
</div>
4242

43-
<NavLink to={`/article/${article.slug}`} class="preview-link">
43+
<NavLink href={`article/${article.slug}`} route="article" class="preview-link">
4444
<h1>{article.title}</h1>
4545
<p>{article.description}</p>
4646
<span>Read more...</span>

src/components/Home.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
1-
import { createEffect } from "solid-js";
1+
import { createEffect, createSignal } from "solid-js";
22
import { useStore } from "../store";
33
import NavLink from "./NavLink";
44
import ArticleList from "./ArticleList";
55

66
const qsParse = () => "";
77

88
export default () => {
9-
const [CommonStore, UserStore, ArticlesStore] = useStore(
9+
const [CommonStore, UserStore, ArticlesStore, { location }] = useStore(
1010
"common",
1111
"user",
12-
"articles"
12+
"articles",
13+
"router"
1314
),
14-
getTab = () => qsParse(window.location.search).tab || "all",
15-
getTag = () => qsParse(window.location.search).tag || "",
15+
[tab, setTab] = createSignal(CommonStore.state.token ? "feed" : "all"),
1616
getPredicate = () => {
17-
switch (getTab()) {
17+
switch (tab()) {
1818
case "feed":
1919
return { myFeed: true };
20-
case "tag":
21-
return { tag: qsParse(window.location.search).tag };
22-
default:
20+
case "all":
2321
return {};
22+
default:
23+
return { tag: tab() };
2424
}
2525
},
26-
handleTabChange = tab => {
27-
if (props.location.query.tab === tab) return;
28-
props.router.push({ ...props.location, query: { tab } });
29-
},
3026
handleSetPage = page => {
3127
ArticlesStore.setPage(page);
3228
ArticlesStore.loadArticles();
3329
};
3430

3531
createEffect(() => {
36-
// if (
37-
// getTab(props) !== getTab(previousProps) ||
38-
// getTag(props) !== getTag(previousProps)
39-
// ) {
32+
const search = location().split("?")[1];
33+
if (!search) return setTab("all");
34+
const query = new URLSearchParams(search);
35+
setTab(query.get("tab"));
36+
});
37+
createEffect(() => {
4038
ArticlesStore.setPredicate(getPredicate());
4139
ArticlesStore.loadArticles();
42-
// }
4340
});
41+
CommonStore.loadTags();
4442

4543
return (
4644
<div class="home-page">
@@ -60,23 +58,31 @@ export default () => {
6058
<ul class="nav nav-pills outline-active">
6159
<Show when={UserStore.state.currentUser}>
6260
<li class="nav-item">
63-
<NavLink class="nav-link" route="?tab=feed">
61+
<NavLink
62+
class="nav-link"
63+
href="?tab=feed"
64+
active={tab() === "feed"}
65+
>
6466
Your Feed
6567
</NavLink>
6668
</li>
6769
</Show>
6870
<li class="nav-item">
69-
<NavLink class="nav-link" route="?tab=all">
71+
<NavLink
72+
class="nav-link"
73+
href="?tab=all"
74+
active={tab() === "all"}
75+
>
7076
Global Feed
7177
</NavLink>
7278
</li>
73-
{/* <Show when={props.tag}>
79+
<Show when={tab() !== "all" && tab() !== "feed"}>
7480
<li className="nav-item">
7581
<a href="" className="nav-link active">
76-
<i className="ion-pound" /> {props.tag}
82+
<i className="ion-pound" /> {tab()}
7783
</a>
7884
</li>
79-
</Show> */}
85+
</Show>
8086
</ul>
8187
</div>
8288

@@ -96,10 +102,7 @@ export default () => {
96102
<div class="tag-list">
97103
<For each={CommonStore.state.tags}>
98104
{tag => (
99-
<a
100-
href={`#/?tab=tag&tag=${tag}`}
101-
class="tag-pill tag-default"
102-
>
105+
<a href={`#/?tab=${tag}`} class="tag-pill tag-default">
103106
{tag}
104107
</a>
105108
)}

src/components/NavBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export default () => {
4444
</NavLink>
4545
</li>
4646
<li class="nav-item">
47-
<NavLink class="nav-link" route="profile">
48-
<i class="ion-compose"></i>&nbsp;User
47+
<NavLink class="nav-link" route="profile" href={`@${UserStore.state.currentUser.username}`}>
48+
<i class="ion-compose"></i>&nbsp;{UserStore.state.currentUser}
4949
</NavLink>
5050
</li>
5151
</Show>

src/components/NavLink.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useStore } from "../store";
22

33
export default props => {
4-
const [{ match }] = useStore("router");
4+
const [{ getParams }] = useStore("router");
55
return (
66
<a
77
class={props.class}
8-
classList={{ active: match(props.route) }}
9-
href={`#/${props.route}`}
8+
classList={{ active: props.active || getParams().routeName === props.route }}
9+
href={`#/${props.href || props.route}`}
1010
>
1111
{props.children}
1212
</a>

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render } from 'solid-js/dom';
2-
import App from './components/App';
2+
import App from './App';
33
import { Provider } from './store';
44

55
render(() => (

src/store/createCommon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function createCommon(agent) {
2222
async loadTags() {
2323
setState('isLoadingTags', true);
2424
try {
25-
const { tags } = agent.Tags.getAll();
25+
const { tags } = await agent.Tags.getAll();
2626
setState({ tags: tags.map(t => t.toLowerCase()) });
2727
} finally {
2828
setState('isLoadingTags', false);

0 commit comments

Comments
 (0)