Skip to content

Commit be69aa7

Browse files
committed
Looking great.
1 parent 89c6334 commit be69aa7

File tree

7 files changed

+48
-18
lines changed

7 files changed

+48
-18
lines changed

config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const client_id = 'd10c47b12243b3cdfd86';

src/ap

Whitespace-only changes.

src/api.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const FEED_EXPIRY = 60*1000*2;
2+
13
let g, u;
24

35
//test();
@@ -60,7 +62,21 @@ export async function getFollowers(state) {
6062
}
6163

6264
export async function getPeopleToFollow(state) {
63-
// this is costly so we cache it
65+
if ( !! state.discover ) {
66+
return state.discover;
67+
}
68+
if ( ! state.followers ) {
69+
await getFollowers(state);
70+
}
71+
const discover = new Set();
72+
await Promise.all(state.followers.map(async f => {
73+
const {following_url} = f;
74+
const source = following_url.slice(0, following_url.indexOf('{'));
75+
const following = await fetch(source).then(resp => resp.json());
76+
following.forEach(f => discover.add(f.login));
77+
}));
78+
state.discover = [...discover.values()];
79+
return state.discover;
6480
}
6581

6682
export async function newPost(submitEvent, state) {
@@ -120,11 +136,15 @@ export function timeAgo(date) {
120136
}
121137

122138
export async function getFeed(state) {
139+
if ( state && state.feed && ((Date.now() - state.feed.updated) < FEED_EXPIRY) ) {
140+
return state.feed;
141+
}
123142
const feed = [];
124143
await Promise.all(state.followers.map(async ({login}) => feed.push(...(await getItsGists(state, login)))));
125144
sortPostsByMostRecent(feed);
126145
if ( state ) {
127146
state.feed = feed;
147+
state.feed.updated = Date.now();
128148
}
129149
return feed;
130150
}

src/app.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {R,X} from '../node_modules/brutalist-web/r.js';
22
import * as API from './api.js';
3+
import Discover from './views/Discover.js';
34
import AuthIn from './views/AuthIn.js';
45
import App from './views/App.js';
56

@@ -24,7 +25,13 @@ async function start() {
2425
appState.name = appState.profileData.login;
2526
await API.getFollowers(appState);
2627
await API.getMyGists(appState);
27-
await API.getFeed(appState);
28+
API.getFeed(appState).then(() => {
29+
appState.currentFeed = ':feed';
30+
App(appState);
31+
});
32+
API.getPeopleToFollow(appState).then(() => {
33+
Discover(appState);
34+
});
2835
(await App(appState)).to('main.app', 'innerHTML');
2936
}
3037
}

src/views/App.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as API from '../api.js';
33
import MyAuth from './MyAuth.js';
44
import PostList from './PostList.js';
55
import NewPost from './NewPost.js';
6+
import Discover from './Discover.js';
67
import browseUser from '../browseUser.js';
78

89
export default function App(state) {
@@ -34,9 +35,7 @@ export default function App(state) {
3435
</section>
3536
</article>
3637
<aside>
37-
<h1>Discover others</h1>
38-
<p>
39-
Follow the followers of your followers, or the followers of those you follow.
38+
${Discover(state)}
4039
</aside>
4140
<footer>
4241
Project of Dosycorp. "Gist", GitHub are marks of GitHub, Inc and its parents and subsidiaries. There is no relationship between GistBarn and these companies.

src/views/AuthIn.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import {R,X} from '../../node_modules/brutalist-web/r.js';
2+
import {client_id} from '../../config.js';
23

34
export default function AuthIn(state) {
45
return R`
5-
${state.loggedIn ? R`
6-
<span class=username>${state.name}</span>
7-
<span class=logout><a click=${logout} href=#logout>Logout</a></span>` :
8-
R`
9-
<span class="authin">
10-
<a href=https://github.com/login/oauth/authorize?client_id=d10c47b12243b3cdfd86&scope=gist>Login</a>
11-
</span>
12-
`}
6+
<span class="authin">
7+
<a href=https://github.com/login/oauth/authorize?client_id=${client_id}&scope=gist>Login</a>
8+
</span>
139
`;
1410
}
1511

16-
function logout() {
17-
localStorage.setItem('token', '');
18-
history.popState();
19-
location.search = '?code=logout';
20-
}

src/views/Discover.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {R,X} from '../../node_modules/brutalist-web/r.js';
2+
import {followUser} from '../api.js';
3+
4+
export default function Discover(state) {
5+
return R`
6+
<div class=discover>
7+
<h1>Discover others</h1>
8+
<p>
9+
Follow the followers of your followers, or the followers of those you follow.
10+
</div>
11+
`;
12+
}

0 commit comments

Comments
 (0)