├── .gitignore ├── .prettierrc ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json └── src ├── Store.js ├── elements ├── AppNav │ ├── index.js │ └── style.css ├── CommentItem │ ├── index.js │ └── style.css ├── HackerNews │ ├── index.js │ └── style.css ├── StoriesPage │ ├── index.js │ └── style.css ├── StoryItem │ ├── index.js │ └── style.css ├── StoryPage │ ├── index.js │ └── style.css └── UserPage │ ├── index.js │ └── style.css ├── index.js ├── serviceWorker.js └── setupRoutes.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "none", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "printWidth": 100 7 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Solid Hacker News App 2 | 3 | This is an older webcomponent demo. If you want to see the latest Solid Hackernews look [here](https://github.com/solidjs/solid-hackernews) 4 | 5 | Demo app based on [NX-JS Hacker News Example](https://github.com/nx-js/hackernews-example). Use Solid Element and WebComponent Router with Solid. 6 | 7 | You can view it [here](http://ryansolid.github.io/solid-hackernews-app). 8 | 9 | This project was bootstrapped with [Create Solid](https://github.com/ryansolid/create-solid). 10 | 11 | 12 | ## Testing Locally: 13 | First, you'll need to clone this repo, then cd into the `solid-hackernews-app` folder 14 | 15 | Then, run `npm install` to install all dependencies 16 | 17 | Lastly, run `npm run start` and the web-app will open in your default browser at `http://localhost:3000/` 18 | 19 | Happy Hacking! 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solid-hackernews-app", 3 | "version": "0.1.2", 4 | "homepage": "http://ryansolid.github.io/solid-hackernews-app", 5 | "private": true, 6 | "dependencies": { 7 | "solid-element": "1.0.0", 8 | "solid-scripts": "0.0.58", 9 | "webcomponent-router": "0.4.3" 10 | }, 11 | "scripts": { 12 | "start": "solid-scripts start", 13 | "build": "solid-scripts build", 14 | "test": "solid-scripts test" 15 | }, 16 | "browserslist": [ 17 | "Chrome 74", 18 | "Firefox 63", 19 | "Safari 11", 20 | "Edge 17", 21 | "Node 12" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ryansolid/solid-hackernews-app/fbfaee44b663b4a749343d6029a7a9fad6a09d76/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Hacker News 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "Hacker News", 3 | "name": "Solid Hacker News App", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/Store.js: -------------------------------------------------------------------------------- 1 | import { createContext, useContext } from "solid-js"; 2 | 3 | const StoreContext = createContext(); 4 | export function StoreProvider(props) { 5 | return {props.children}; 6 | } 7 | 8 | export function useStore() { 9 | return useContext(StoreContext); 10 | } 11 | 12 | const mapStories = { 13 | top: "news", 14 | new: "newest", 15 | show: "show", 16 | ask: "ask", 17 | job: "jobs" 18 | }; 19 | function createStore() { 20 | const cache = {}; 21 | 22 | const get = (path) => 23 | cache[path] || 24 | (cache[path] = fetch(`https://node-hnapi.herokuapp.com/${path}`).then((r) => r.json())); 25 | 26 | return { 27 | getItem: (id) => get(`item/${id}`), 28 | getUser: (id) => get(`user/${id}`), 29 | getStories: (type, page) => get(`${mapStories[type]}?page=${page}`) 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /src/elements/AppNav/index.js: -------------------------------------------------------------------------------- 1 | import { customElement } from 'solid-element'; 2 | 3 | import style from './style.css'; 4 | 5 | const AppNav = () => ( 6 | <> 7 | 8 | Hacker News 9 | new{" "} 10 | | show{" "} 11 | | ask{" "} 12 | | jobs 13 | 14 | Built with Solid |{" "} 15 | Source 16 | 17 | 18 | ) 19 | 20 | export default customElement('app-nav', AppNav); 21 | -------------------------------------------------------------------------------- /src/elements/AppNav/style.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | background-color: rgb(255, 102, 0); 4 | padding: 4px; 5 | overflow: hidden; 6 | contain: content; 7 | } 8 | 9 | a { 10 | color: inherit; 11 | text-decoration: none; 12 | cursor: pointer; 13 | } 14 | 15 | a.active { 16 | color: white; 17 | } 18 | 19 | b { 20 | padding: 0 4px; 21 | } 22 | 23 | span { 24 | color: white; 25 | display: inline-block; 26 | float: right; 27 | font-size: 9pt; 28 | } 29 | 30 | span a:hover { 31 | text-decoration: underline; 32 | } -------------------------------------------------------------------------------- /src/elements/CommentItem/index.js: -------------------------------------------------------------------------------- 1 | import { createSignal } from "solid-js"; 2 | import { customElement } from "solid-element"; 3 | import style from "./style.css"; 4 | 5 | const CommentItem = ({ comment }) => { 6 | const [hidden, setHidden] = createSignal(false); 7 | 8 | return ( 9 | <> 10 | 11 | 12 |
13 | 14 | {comment.user} 15 | {" "} 16 | {comment.time_ago} 17 | setHidden(h => !h)}>{hidden() ? "[+]" : "[-]"} 18 |
19 |