Giter Club home page Giter Club logo

vue-for-react-developers's Introduction

Vue Chat Application

Vue for React Developers JS / TS Guild Event

Hi and welcome! This repository contains a chat application created with the Vue 3 Composition API.

Workshop slides 16.1.2024

Original workshop slides

Contents


Getting started

Ensure your Node.js version is >=12.2.0 with node --version. If not, it's time to upgrade for which I recommend nvm.

Run these commands in your command line to get a local development version of this project up and running on your machine.

# Clone the repository
git clone https://github.com/knowit-finland-javascript-guild/vue-for-react-developers.git

# Install dependencies
cd vue-for-react-developers
npm install

# Start the app
npm run dev

The app should now be running at localhost:5173

IDE Setup

The recommended IDE setup is VSCode and the Volar extension.

This should allow for precise auto-formatting and most of the good stuff you want when developing.


Project Structure

This application is written in Javascript. Vue 3 supports TypeScript but it has not been used here.

This project's structure is roughly the following:

.
├── node_modules/
├── public/
├── src/
│   ├── assets/
│   ├── components/
│   ├── compositionFunctions/
│   └── App.vue                # Start here
├── package.json
└── README.md

Get started by exploring App.vue.

The src/compositionFunctions directory contains functions that are very similar to React hooks. A direct parallel between the two can't really be made, but a convention is to name both with a use prefix.

Components

Components have been written as single file components using the <script setup> syntax. This means that a component's template, script and style are all contained within a single file. The <script setup> syntax replaces Vue's setup() function, making the entire component less verbose. Understanding what this means is not required in the scope of this workshop and exercise, but you can read more about it in the Vue docs.


Exercise

To flesh out your Vue skills, an exercise has been prepared. The first part will task you with wiring the pieces of an existing application together. The second part will have you create a new component for the same application.

If you get stuck at any point, search the project for the string "Hint:". These point to critical points where functionality could be added.

Exercise 1: Complete the chat app

To start, switch to the correct branch:

git switch exercise-1

The application mostly works but we can't send any messages. Let's fix that by doing the following things.

1. Fix the Compose component

The Compose.vue component has a button that should send the typed message, but it doesn't. This is because the <Button /> component doesn't have any functionality attached to it. Fix this by:

  1. Making clicks on the button call the send() function.
  2. Making the send() function emit a send event with the text input's value as an argument.

2. Fix the Chat component

With the Compose component fixed, the Chat component should now be receiving send events from it. However, nothing is registered to handle these events.

Create a function that mutates the reactive messages variable. It should append new messages to the existing array of messages (open messages.js to find out what format messages are stored in). Make sure to attach this function to the Compose component's send event.

You should now have a working, albeit very one-sided, chat app!

Bonus: See if you could send messages simply by pressing the enter key in the text input field.

Exercise 2: Extend the Chat App

The second part of the exercise is to extend the chat app with an "emoji picker".

Extended chat app

To start, switch to the correct branch:

git switch exercise-2

Basic messaging functionality has already been implemented in this branch. Your job is to accomplish the following three goals.

Reminder: If you get stuck at any point, search the project for the string "Hint:". These point to critical points where functionality could be added.

1. Create an emoji picker component.

Create a set of buttons that can be clicked to send the respective emoji to the chat.

To start, take a look at the Button.vue component. You can use its icon prop to pass in the name of an emoji you want to display. useIcons.js will provide a list of available emojis.

2. Send emoji messages

Figure out how to send messages from your emoji picker to the message list in Chat.vue. Give these messages a different type value so you can render them in a different way than normal text messages in the following step.

Start from the Compose.vue component and see how it does things, though you're probably already familiar with it from the last exercise.

3. Render emoji messages

Finally, render emoji messages in the chat. They should now have a different type value than regular chat messages.

Head to ChatMessage.vue and look into conditional rendering. Don't worry if things don't look perfect - the main point of this exercise isn't CSS.


Resources

You'll find the workshop slides here.

The following resources are pretty handy:

vue-for-react-developers's People

Contributors

misacorp avatar

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.