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

Organize folders #196

Open
wants to merge 4 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
22 changes: 22 additions & 0 deletions issue-tracker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ You can run the app by navigating to `relay-examples/issue-tracker/` and then ru

This will start the development server (including Relay Compiler) and open a browser to [localhost:3000](http://localhost:3000).

## Working on IssueTracker
There are few key parts of IssueTracker:

```shell
├── public
├── schema
└── src
├── __generated__
├── components
├── hooks
├── pages
│   ├── IssueDetail
│   │   └── __generated__
│   └── Issues
│   └── __generated__
└── routing
```
- `schema`: Contains `graphql` schema
- `components`: Contains foundational components used by other pages (e.g ErrorBoundary, SuspenseImage)
- `hooks`: Contains all hooks available on this project
- `pages`: Contains the modules for our routes and their own components
- `routing`: Contains configurations and utility functions related to routes
## About the App

This app uses a number of technologies including (among others):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import JSResource from './JSResource';
import JSResource from '../JSResource';

export default function SuspenseImage(props) {
const { src } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import graphql from 'babel-plugin-relay/macro';
import React from 'react';
import { useFragment } from 'react-relay/hooks';
import { ConnectionHandler } from 'relay-runtime';
import useMutation from './useMutation';
import useMutation from '../../hooks/useMutation';

const { useCallback, useState } = React;

Expand Down
23 changes: 23 additions & 0 deletions issue-tracker/src/pages/IssueDetail/IssueDetailComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ReactMarkdown from 'react-markdown';
import SuspenseImage from '../../components/SuspenseImage';
import React from 'react';

export default function IssueDetailComment(props) {
const { comment } = props;
return (
<div className="issue-comment">
<SuspenseImage
className="issue-comment-author-image"
title={`${comment.author.login}'s avatar`}
src={comment.author.avatarUrl}
/>
<div className="issue-comment-author-name">{comment.author.login}</div>
<div className="issue-comment-body">
<ReactMarkdown
source={comment.body}
renderers={{ image: SuspenseImage }}
/>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import graphql from 'babel-plugin-relay/macro';
import React from 'react';
import { usePaginationFragment } from 'react-relay/hooks';
import ReactMarkdown from 'react-markdown';
import SuspenseImage from './SuspenseImage';
import IssueDetailComment from './IssueDetailComment';

const { useCallback, useTransition, Suspense, SuspenseList } = React;

Expand Down Expand Up @@ -73,34 +72,15 @@ export default function IssueDetailComments(props) {
return (
<>
<SuspenseList revealOrder="forwards">
{comments.map(edge => {
if (edge == null || edge.node == null) {
return null;
}
const comment = edge.node;
return (
{comments
.filter(edge => edge != null || edge.node != null)
.map(edge => (
// Wrap each comment in a separate suspense fallback to allow them to commit
// individually; SuspenseList ensures they'll reveal in-order.
<Suspense fallback={null} key={edge.__id}>
<div className="issue-comment">
<SuspenseImage
className="issue-comment-author-image"
title={`${comment.author.login}'s avatar`}
src={comment.author.avatarUrl}
/>
<div className="issue-comment-author-name">
{comment.author.login}
</div>
<div className="issue-comment-body">
<ReactMarkdown
source={comment.body}
renderers={{ image: SuspenseImage }}
/>
</div>
</div>
<IssueDetailComment comment={edge.node} />
</Suspense>
);
})}
))}
</SuspenseList>
{hasNext ? (
<button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import graphql from 'babel-plugin-relay/macro';
import React from 'react';
import { usePreloadedQuery } from 'react-relay/hooks';
import ReactMarkdown from 'react-markdown';
import SuspenseImage from './SuspenseImage';
import IssueDetailComments from './IssueDetailComments';
import IssueActions from './IssueActions';
import IssueDetailComment from './IssueDetailComment';
import IssueDetailComments from './IssueDetailComments';

/**
* The root component for the issue detail route.
Expand Down Expand Up @@ -52,20 +51,9 @@ export default function IssueDetailRoot(props) {
View on GitHub
</a>
</div>
<div className="issue-comment">
<SuspenseImage
className="issue-comment-author-image"
title={`${issue.author.login}'s avatar`}
src={issue.author.avatarUrl}
/>
<div className="issue-comment-author-name">{issue.author.login}</div>
<div className="issue-comment-body">
<ReactMarkdown
source={issue.body}
renderers={{ image: SuspenseImage }}
/>
</div>
</div>
{/** The author's comment is divided from comment list */}
<IssueDetailComment comment={issue} />

<IssueDetailComments issue={issue} />
<IssueActions issue={issue} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ export default function Issues(props) {

return (
<div className="issues">
{data.issues.edges.map(edge => {
if (edge == null || edge.node == null) {
return null;
}
return (
{data.issues.edges
.filter(edge => edge != null || edge.node != null)
.map(edge => (
<div className="issues-issue" key={edge.__id}>
{/* Note how we also spread IssuesListItem's fragment above */}
<IssuesListItem issue={edge.node} />
</div>
);
})}
))}
<button
name="load more issues"
type="button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import graphql from 'babel-plugin-relay/macro';
import React from 'react';
import { useFragment } from 'react-relay/hooks';
import Link from './routing/Link';
import Link from '../../routing/Link';

/**
* Renders a single item (issue) in the issues list.
Expand Down
10 changes: 6 additions & 4 deletions issue-tracker/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ const routes = [
* especially useful with nested routes, where React.lazy would not fetch the
* component until its parents code/data had loaded.
*/
component: JSResource('HomeRoot', () => import('./HomeRoot')),
component: JSResource('HomeRoot', () =>
import('./pages/Issues/HomeRoot'),
),
/**
* A function to prepare the data for the `component` in parallel with loading
* that component code. The actual data to fetch is defined by the component
* itself - here we just reference a description of the data - the generated
* query.
*/
prepare: params => {
const IssuesQuery = require('./__generated__/HomeRootIssuesQuery.graphql');
const IssuesQuery = require('./pages/Issues/__generated__/HomeRootIssuesQuery.graphql');
return {
issuesQuery: loadQuery(
RelayEnvironment,
Expand All @@ -61,10 +63,10 @@ const routes = [
{
path: '/issue/:id',
component: JSResource('IssueDetailRoot', () =>
import('./IssueDetailRoot'),
import('./pages/IssueDetail/IssueDetailRoot'),
),
prepare: params => {
const IssueDetailQuery = require('./__generated__/IssueDetailRootQuery.graphql');
const IssueDetailQuery = require('./pages/IssueDetail/__generated__/IssueDetailRootQuery.graphql');
return {
issueDetailQuery: loadQuery(
RelayEnvironment,
Expand Down
2 changes: 1 addition & 1 deletion issue-tracker/src/routing/RouteRenderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import RoutingContext from './RoutingContext';
import ErrorBoundary from '../ErrorBoundary';
import ErrorBoundary from '../components/ErrorBoundary';
import './RouteRenderer.css';

const { useContext, useEffect, useTransition, Suspense, useState } = React;
Expand Down