Last active
April 28, 2019 19:18
-
-
Save jermsam/4acf90d5ffef3536167759937c41eb54 to your computer and use it in GitHub Desktop.
File Causing build errors
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
| require('dotenv').config() | |
| const path = require('path') | |
| const Dotenv = require('dotenv-webpack') | |
| const withCSS = require('@zeit/next-css') | |
| /* Without CSS Modules, with PostCSS */ | |
| // module.exports = withCSS() | |
| /* With CSS Modules */ | |
| // module.exports = withCSS({ cssModules: true }) | |
| /* With additional configuration on top of CSS Modules */ | |
| module.exports = withCSS({ | |
| // cssModules: true, | |
| webpack: function (config) { | |
| config.plugins.push( | |
| // Read the .env file | |
| new Dotenv({ | |
| path: path.join(__dirname, '.env'), | |
| systemvars: true | |
| }) | |
| ) | |
| config.module.rules.push({ | |
| test: /\.(png|svg|eot|otf|ttf|woff|woff2|icon)$/, | |
| use: { | |
| loader: 'url-loader', | |
| options: { | |
| limit: 8192, | |
| publicPath: '/_next/static/', | |
| outputPath: 'static/', | |
| name: '[name].[ext]' | |
| } | |
| } | |
| }) | |
| return config; | |
| } | |
| }); |
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
| /* eslint-disable no-console */ | |
| import React, { Component } from 'react'; | |
| import _ from 'lodash'; | |
| import { Search } from 'semantic-ui-react'; | |
| import { Router } from '../../routes'; | |
| import { app } from '../../feathers'; | |
| export default class StudentSearch extends Component { | |
| _isMounted = false; | |
| state = { isLoading: false, results: [], student: '' } | |
| componentDidMount() { | |
| this._isMounted = true; | |
| } | |
| componentWillUnmount() { | |
| this._isMounted = false; | |
| } | |
| resetComponent = () => this.setState({ isLoading: false, results: [], student: '' }); | |
| handleResultSelect = (e, { result: { id, title } }) => { | |
| console.log('selected id: ', id); | |
| if (this._isMounted) { | |
| this.setState({ student: title }); | |
| } | |
| Router.push(`/dashboard?userId=${id}`); | |
| }; | |
| handleSearchChange = (e, { value }) =>this.findStudent(value) | |
| findStudent=async(value)=>{ | |
| if (this._isMounted) { | |
| this.setState({ isLoading: true, student: value }); | |
| } | |
| try{ | |
| const {data}=await app.service('stories').find() | |
| const source= data.map(({ title, goal, user }) => { | |
| if (user) { | |
| const { id, avatar, firstname, lastname } = user; | |
| return { | |
| id, | |
| title: `${firstname} ${lastname}`, | |
| image: `${this.processSource(avatar)}`, | |
| description: `${title}`, | |
| price: `$ ${goal}` | |
| }; | |
| } | |
| // const { title, goal } = story; | |
| return { | |
| id: null, | |
| title: ``, | |
| image: ``, | |
| description: ``, | |
| price: `` | |
| }; | |
| }) | |
| const { student } = this.state; | |
| if (student.length < 1) return this.resetComponent(); | |
| const re = new RegExp(_.escapeRegExp(student), 'i'); | |
| const isMatch = result => re.test(result && result.title); | |
| if (this._isMounted) { | |
| this.setState({ | |
| isLoading: false, | |
| results: _.filter(source, isMatch) | |
| }); | |
| } | |
| } | |
| catch({message}){ | |
| console.log("Error: ",message) | |
| } | |
| return null; | |
| } | |
| processSource = avatar =>avatar | |
| ? `${avatar}` | |
| : 'https://react.semantic-ui.com/images/avatar/small/matt.jpg'; | |
| render() { | |
| const { isLoading, student, results } = this.state; | |
| return ( | |
| <Search | |
| style={{ zIndex: 3 }} | |
| placeholder="Search for student by name" | |
| loading={isLoading} | |
| onResultSelect={this.handleResultSelect} | |
| onSearchChange={_.debounce(this.handleSearchChange, 500, { | |
| leading: true | |
| })} | |
| {...{ results }} | |
| value={student} | |
| {...this.props} | |
| size="massive" | |
| /> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment