Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start defining layers to decouple frontend logic from data fetch #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"evergreen-ui": "^6.4.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
Expand Down
38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

9 changes: 0 additions & 9 deletions src/App.test.tsx

This file was deleted.

26 changes: 0 additions & 26 deletions src/App.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions src/domain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Feed {
constructor(id: string, name: string, url: string) {
this.id = id;
this.name = name;
this.url = url;
};
id: string;
name: string;
url: string;
}

class FeedEntry {
constructor(id: string, feedId: string, content: string) {
this.id = id;
this.feedId = feedId;
this.content = content;
}
id: string;
feedId: string;
content: string;
}

export { Feed, FeedEntry }
5 changes: 3 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';

import './index.css';
import App from './App';
import Main from './presentation/main';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<React.StrictMode>
<App />
<Main />
</React.StrictMode>,
document.getElementById('root')
);
Expand Down
1 change: 0 additions & 1 deletion src/logo.svg

This file was deleted.

81 changes: 81 additions & 0 deletions src/presentation/main/feed_reader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { useState } from 'react';
import { Card, EmptyState, HandUpIcon, Pane, Text, Badge } from 'evergreen-ui';
import { Feed } from '../../domain';
import { FeedsService, FeedEntriesService } from '../../services';

const service = new FeedsService.Fetch();
const entryService = new FeedEntriesService.Fetch();

const FeedList = (props: any) => {
const feeds = service.all();

return (
<Pane
width='20vw'
maxWidth='20vw'
alignItems='left'
display='flex'
flexDirection='column'
borderRight
>
{feeds.map((feed) => (
<Pane display='flex' flexDirection='row'>
<Pane flex={1} alignItems='left' display='flex' width='70vw'>
<Text onClick={() => props.selectFeed(feed)} cursor='pointer'>
{feed.name}
</Text>
</Pane>

<Pane>
<Badge color="neutral">0</Badge>
</Pane>
</Pane>
))}
</Pane>
)
};

interface EntryListProps {
feedId?: string;
}

const EntryList = ({ feedId }: EntryListProps) => {
const entries = entryService.findBy({ feedId });

return (
<Pane width='80vw' alignItems='center' display='flex' height='auto'>
{entries.length === 0 ?
<EmptyState
background="light"
title="Yay! Looks like you've read all your feed!"
orientation="vertical"
icon={<HandUpIcon color="#C1C4D6" />}
iconBgColor="#EDEFF5"
/> :
entries.map((entry) => (
<Card>
{entry.content}
</Card>
))}
</Pane>
)
};

const FeedReader = () => {
const [feed, setFeed] = useState<Feed | null>(null);

return (
<Pane
display='flex'
height='100vh'
flexDirection='row'
justifyContent='center'
>
<FeedList selectFeed={setFeed} />

<EntryList feedId={feed?.id} />
</Pane>
)
};

export default FeedReader;
25 changes: 25 additions & 0 deletions src/presentation/main/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { Component } from 'react';
import { Pane } from 'evergreen-ui'

import NavBar from './nav_bar';
import FeedReader from './feed_reader';

class Main extends Component {
render() {
return (
<Pane
display='flex'
alignItems='left'
flexDirection='column'
justifyContent='center'
width='100%'
>
<NavBar />

<FeedReader />
</Pane>
);
}
}

export default Main;
24 changes: 24 additions & 0 deletions src/presentation/main/nav_bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { Avatar, Pane, Text } from 'evergreen-ui';

const NavBar = () => (
<Pane
display='flex'
width='100vw'
alignItems='center'
justifyContent='center'
flexDirection='row'
borderBottom
clearfix
>
<Pane flex={1} height={60} alignItems='center' display='flex'>
<Text>FTH</Text>
</Pane>

<Pane>
<Avatar name='Bruno Arueira' />
</Pane>
</Pane>
)

export default NavBar;
25 changes: 25 additions & 0 deletions src/services/feed_entries_service/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { FeedEntry } from '../../domain';

const entries = [
new FeedEntry('0', '0', 'Something'),
new FeedEntry('1', '0', 'Foo'),
new FeedEntry('2', '0', 'Bar'),
new FeedEntry('3', '1', 'Baz'),
new FeedEntry('4', '1', 'Another')
];

export interface FetchFindByProps {
feedId?: string;
}

export interface Fetch {
findBy(prop: FetchFindByProps): FeedEntry[];
}

class FetchImpl implements Fetch {
findBy(prop: FetchFindByProps): FeedEntry[] {
return entries.filter((feedEntry) => feedEntry.feedId === prop.feedId);
}
}

export default FetchImpl;
5 changes: 5 additions & 0 deletions src/services/feed_entries_service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Fetch from './fetch';

export {
Fetch
}
16 changes: 16 additions & 0 deletions src/services/feeds_service/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Feed } from '../../domain';

export interface Fetch {
all(): Feed[];
}

class FetchImpl implements Fetch {
all(): Feed[] {
return [
new Feed('0', 'Bruno Arueira', 'https://brunoarueira.com/feed.xml'),
new Feed('1', 'Hacker News', 'https://news.ycombinator.com/news.xml')
];
}
}

export default FetchImpl;
5 changes: 5 additions & 0 deletions src/services/feeds_service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Fetch from './fetch';

export {
Fetch
}
4 changes: 4 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as FeedsService from './feeds_service';
import * as FeedEntriesService from './feed_entries_service';

export { FeedsService, FeedEntriesService };
Loading