Giter VIP home page Giter VIP logo

linkedin-clone's Introduction

Linkedin Clone - Course by Sonny Sangha here

Live site here

Node 14.17.6

Firebase ^8.2.0

--Notes from Sonny--

  • -- "React Context API is great, but REDUX is what's used in production. USE REDUX."

Tools Used

Things I Added

  • Complete Mobile View Makeover

  • Added Date & Time to user posts

    • Take the Firebase timestamp property from the user post

    File: Feed.js ... ... function convertTimestamp(timestamp) {

          const newTimestamp = new Date(timestamp.toDate()).toUTCString();
          
          return newTimestamp;
      }
      ...
      ...
      {/* FEED POSTS */}
              {posts.map(({id, data: { name, description, message, photoUrl, timestamp }}) => (
                  
    
                  <Post  
                      key={id}
                      name={name}
                      description={description}
                      message={message}
                      photoUrl={photoUrl}
                      timestamp={convertTimestamp(timestamp)}
                  />
              ))}
    

Screenshot Reference

linked-in-clone-screenshot

  • Issues

    • Had a little trouble with this line

    • timestamp: firebase.firestore.FieldValue.serverTimestamp() in Feed.js

        const sendPost = event => {
                
                db.collection('posts').add({
                    ...
                    ...
                    timestamp: firebase.firestore.FieldValue.serverTimestamp(),
                });
      
        }
      
      • Did not realize that line was the problem for some time
      • Getting error ./src/Feed.js Module not found: Can't resolve 'firebase' in 'C:\Users\username\Desktop\linkedin-clone\src'
    • Nothing to do with the Firebase version installed, Node or installing Firebase in the 'project/src' folder

    • Solution: In Feed.js, change

      • import firebase from 'firebase' to
      • import firebase from 'firebase/app'
      • I believe the problem was I was trying to call getTimestamp() from firebase itself and not my particular app
      • reference
  • Code Snippets

    • Grabbing the user posts from Firestore and passing them into State within our app as an array [] of posts

      • Comments

        • useEffect fires code when the Feed Component loads and whenever the Feed Component re-renders, IF we don't pass in a second argument

        • if we pass in an empty array [], as second arg, then useEffect only fires on initial load and never again

        • then take those posts as a SNAPSHOT from the firestore database and pass them into our App's state with setPosts()

        • snapshot.docs.map((doc) => ( ...) open parenthesis means implicit return -> return what ever is mapped over

          File: Feed.js

            function Feed() {
          
                const [posts, setPosts] = useState([]);
          
                useEffect(() => {
                    
                        db.collection('posts').onSnapshot((snapshot) => 
                                        
                            setPosts(snapshot.docs.map((doc) => (       
                                {
                                    id: doc.id,
                                    data: doc.data()
                                }
                            ))
                        ));
                }, []); 
          
                ...
            }
          

    - Grabbing user post input and setting to State, while adding the new Post to Firestore database

    File: Feed.js

      function Feed () {
    
          ...
          const [input, setInput] = setState('');
          ...
          const sendPost = (event) => {
                  event.preventDefault();
    
                  db.collection('posts').add({
                      name: 'Sonny Sangha',
                      description: 'this is a test',
                      message: input,
                      photoUrl: '',
                      timestamp: firebase.firestore.fieldValue.serverTimestamp()
                  });
    
          }
          ... 
          <input value={input} onChange={event => setInput(event.target.value)} type='text' />
          ...
      }
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.