-
Notifications
You must be signed in to change notification settings - Fork 4
Class to functional components #193
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
Merged
Merged
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
5c16865
Converted class to functional component for Page in privacy.jsx
Willjianger9 c95e791
Converted submit
Willjianger9 a8e3d3d
Converted requests
Willjianger9 e64da5f
Community guide conversion
Willjianger9 b20262c
Tag pages conversion
Willjianger9 3ecfdd0
Sports conversion
Willjianger9 82a0f73
sponsored conversion
Willjianger9 d6a6c0d
quad conversion
Willjianger9 1b095ac
Convert pages/post/[slug].jsx from class to functional component
Willjianger9 97ec94e
Convert pages/page/[slug].jsx from class to functional component
Willjianger9 d7b3228
opinion conversion from class to functional
Willjianger9 41fd8a9
new conversion from class to functional
Willjianger9 796a801
arts conversion
Willjianger9 7d4f3ff
join conversion
Willjianger9 799ed7c
editorial conversion
Willjianger9 7aa18e8
intern desc converison
Willjianger9 f9456f6
comment conversion
Willjianger9 df12f4f
home page conversion
Willjianger9 e014976
infocus conversion
Willjianger9 88282f5
video conversion
Willjianger9 d6194e1
uncategorized conversion
Willjianger9 f2c57f8
Spectrum conversion
Willjianger9 aaaad31
podcasts conversion
Willjianger9 83db5a3
illo conversion
Willjianger9 916da5c
graphics conversion
Willjianger9 ff26655
cartoon conv
Willjianger9 e79732b
Rest of conversions
Willjianger9 e12506f
PR changes
Willjianger9 e8db42c
Fix
Willjianger9 43320e4
Merge branch 'master' into class-to-functional-components
NarekGermirlian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,18 @@ | ||
| import PageWrapper from "../layouts/PageWrapper"; | ||
| import React, { Component } from "react"; | ||
| import React, { useEffect } from "react"; | ||
|
|
||
| class Page extends Component { | ||
| render() { | ||
| // If the window isn't loaded yet, don't let it throw an error | ||
| if (typeof window === "undefined") { | ||
| <p> | ||
| Oops! We meant to redirect you to https://dailybruin.com/category/arts | ||
| </p>; | ||
| } else { | ||
| // Redirect | ||
| window.location.href = "https://dailybruin.com/category/arts-entertainment"; | ||
| } | ||
| return null; | ||
| } | ||
| function Page() { | ||
| useEffect(() => { | ||
| // Redirect on client-side, runs once on mount | ||
| window.location.href = "https://dailybruin.com/category/arts-entertainment"; | ||
| }, []); | ||
|
|
||
| // Show message during server-side rendering (before redirect happens) | ||
| return ( | ||
| <p> | ||
| Oops! We meant to redirect you to https://dailybruin.com/category/arts | ||
| </p> | ||
| ); | ||
| } | ||
|
|
||
| export default PageWrapper(Page); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,52 @@ | ||
| import PageWrapper from "../../layouts/PageWrapper"; | ||
| import React, { Component } from "react"; | ||
| import React from "react"; | ||
| import Error from "next/error"; | ||
| import { Config } from "../../config.js"; | ||
| import Head from "next/head"; | ||
|
|
||
| import AuthorLayout from "../../layouts/Author"; | ||
|
|
||
| class Author extends Component { | ||
| static async getInitialProps(context) { | ||
| const { slug } = context.query; | ||
| const authorRes = await fetch( | ||
| `${Config.apiUrl}/wp-json/wp/v2/users?slug=${slug}` | ||
| ); | ||
| const author = await authorRes.json(); | ||
| const postsRes = await fetch( | ||
| `${Config.apiUrl}/wp-json/wp/v2/posts?_embed&filter[author_name]=${slug}&categories_exclude=27179,27127` // 27179 is the category id of breaking feed posts | ||
| ); | ||
| const posts = await postsRes.json(); | ||
| const classifiedsRes = await fetch( | ||
| `${Config.apiUrl}/wp-json/wp/v2/classifieds?_embed&Featured=3` | ||
| ); | ||
| const classifieds = await classifiedsRes.json(); | ||
| return { author, posts, classifieds }; | ||
| } | ||
| render() { | ||
| if (this.props.author == undefined || this.props.author.length == 0) { | ||
| return <Error statusCode={404} />; | ||
| } | ||
| return ( | ||
| <> | ||
| <Head> | ||
| <title>{this.props.author[0].name + " - Daily Bruin"}</title> | ||
| </Head> | ||
| <AuthorLayout | ||
| author={this.props.author[0]} | ||
| posts={this.props.posts} | ||
| classifieds={this.props.classifieds.map(c => { | ||
| return { | ||
| category: { | ||
| name: c._embedded["wp:term"][1][0].name, | ||
| url: c._embedded["wp:term"][1][0].link | ||
| }, | ||
| content: { name: c.content.rendered, url: c.link } | ||
| }; | ||
| })} | ||
| /> | ||
| </> | ||
| ); | ||
| function Author({ author, posts, classifieds }) { | ||
| if (author == undefined || author.length == 0) { | ||
| return <Error statusCode={404} />; | ||
| } | ||
| return ( | ||
| <> | ||
| <Head> | ||
| <title>{author[0].name + " - Daily Bruin"}</title> | ||
| </Head> | ||
| <AuthorLayout | ||
| author={author[0]} | ||
| posts={posts} | ||
| classifieds={classifieds.map(c => { | ||
| return { | ||
| category: { | ||
| name: c._embedded["wp:term"][1][0].name, | ||
| url: c._embedded["wp:term"][1][0].link | ||
| }, | ||
| content: { name: c.content.rendered, url: c.link } | ||
| }; | ||
| })} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| Author.getInitialProps = async (context) => { | ||
| const { slug } = context.query; | ||
| const authorRes = await fetch( | ||
| `${Config.apiUrl}/wp-json/wp/v2/users?slug=${slug}` | ||
| ); | ||
| const author = await authorRes.json(); | ||
| const postsRes = await fetch( | ||
| `${Config.apiUrl}/wp-json/wp/v2/posts?_embed&filter[author_name]=${slug}&categories_exclude=27179,27127` // 27179 is the category id of breaking feed posts | ||
| ); | ||
| const posts = await postsRes.json(); | ||
| const classifiedsRes = await fetch( | ||
| `${Config.apiUrl}/wp-json/wp/v2/classifieds?_embed&Featured=3` | ||
| ); | ||
| const classifieds = await classifiedsRes.json(); | ||
| return { author, posts, classifieds }; | ||
| }; | ||
|
|
||
| export default PageWrapper(Author); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove Component from import