投稿時間:2022-12-06 01:35:48 RSSフィード2022-12-06 01:00 分まとめ(36件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
AWS AWS Government, Education, and Nonprofits Blog Calming airport data turbulence with EASE https://aws.amazon.com/blogs/publicsector/calming-airport-data-turbulence-ease/ Calming airport data turbulence with EASEAirports receive data from dozens of disparate sources but this data can lack the collective unity needed to see the bigger picture The Cincinnati Northern Kentucky International Airport CVG saw an opportunity to turn down the proverbial volume on their data Using AWS CVG created a first of its kind tool using data for predictive analytics and proactive notifications now known as Enterprise Awareness amp Situational Exceptions EASE 2022-12-05 15:20:41
AWS AWS Japan Blog AWSのデジタル統制に関するお客様との約束 https://aws.amazon.com/jp/blogs/news/aws%E3%81%AE%E3%83%87%E3%82%B8%E3%82%BF%E3%83%AB%E7%B5%B1%E5%88%B6%E3%81%AB%E9%96%A2%E3%81%99%E3%82%8B%E3%81%8A%E5%AE%A2%E6%A7%98%E3%81%A8%E3%81%AE%E7%B4%84%E6%9D%9F/ 統制 2022-12-05 15:46:50
python Pythonタグが付けられた新着投稿 - Qiita Meraki APIで無線APにPingを打たせて結果をMackerelに投稿してみる https://qiita.com/tomotomobooks/items/1f9cd69d41f756c815c0 mackerel 2022-12-06 00:52:29
python Pythonタグが付けられた新着投稿 - Qiita Python 標準ライブラリ types の紹介 https://qiita.com/fgshun/items/63fe396f043fb7553330 pythontypes 2022-12-06 00:45:18
python Pythonタグが付けられた新着投稿 - Qiita python で、代入文(warlrus演算子)を使おう!②(備忘録) https://qiita.com/1023shogo2013/items/2013be629eb608805ade vegetablestomatomelongo 2022-12-06 00:28:51
python Pythonタグが付けられた新着投稿 - Qiita Deepface(顔認証・表情推定・年齢推定)を触ってみた https://qiita.com/ysenkun/items/b8b8704e6b7ae6625680 deepface 2022-12-06 00:18:43
js JavaScriptタグが付けられた新着投稿 - Qiita 【本格的にJavaScriptを学ぶ】歴史編 https://qiita.com/Kuwa_african/items/25b9f0487723af09d590 javascript 2022-12-06 00:31:50
js JavaScriptタグが付けられた新着投稿 - Qiita コメントアウト雑まとめ(HTML,CSS,JavaSprict,Ruby,Rails) https://qiita.com/sakamoto_takuya/items/acafc6d74db30602ebd8 cssjavasprictrubyrails 2022-12-06 00:24:12
js JavaScriptタグが付けられた新着投稿 - Qiita 複数のウィンドウを同時にスクロールさせるChrome拡張作った話 https://qiita.com/gacky35/items/4b0aac15cc7d6b6a34b5 chrome 2022-12-06 00:01:00
Ruby Rubyタグが付けられた新着投稿 - Qiita コメントアウト雑まとめ(HTML,CSS,JavaSprict,Ruby,Rails) https://qiita.com/sakamoto_takuya/items/acafc6d74db30602ebd8 cssjavasprictrubyrails 2022-12-06 00:24:12
AWS AWSタグが付けられた新着投稿 - Qiita Amazon CodeCatalyst 触ってみた! https://qiita.com/wagasa2/items/f2efc24aaf1e1e4e82f3 amazoncodecatalyst 2022-12-06 00:17:37
AWS AWSタグが付けられた新着投稿 - Qiita [re:Invent 2022] ゲームバックエンドによく使われるRDSのBlue/Greenデプロイ新機能を使ってみた https://qiita.com/falken/items/9bc7683e936e126c1433 awsforgamesadventcalendar 2022-12-06 00:10:50
AWS AWSタグが付けられた新着投稿 - Qiita AWSのサービスをAWS CloudShell で操作する https://qiita.com/oh_4shiki/items/7c12971b5cb02042cec2 adventcalendar 2022-12-06 00:07:31
golang Goタグが付けられた新着投稿 - Qiita Goでdiffコマンド書いて実際の実装と比べてみた https://qiita.com/nsym__m/items/7bbdb162f513022bc461 techcommitadventcalendar 2022-12-06 00:01:06
Azure Azureタグが付けられた新着投稿 - Qiita サービスエンドポイントについて https://qiita.com/ss12345/items/dcfa7bd7960ac13678fd azure 2022-12-06 00:45:48
Ruby Railsタグが付けられた新着投稿 - Qiita コメントアウト雑まとめ(HTML,CSS,JavaSprict,Ruby,Rails) https://qiita.com/sakamoto_takuya/items/acafc6d74db30602ebd8 cssjavasprictrubyrails 2022-12-06 00:24:12
技術ブログ Developers.IO Alteryx Serverのコレクションのユーザー/グループの管理 – Alteryx Serverアドベントカレンダー2022 https://dev.classmethod.jp/articles/alteryxserver-adventcalendar-20221206/ developersioalteryxs 2022-12-05 15:45:02
技術ブログ Developers.IO Snowflake Marketplace上でtruestar社が提供するPrepper Open Data Bank – Japanese Calendar Dataを試してみた #SnowflakeDB https://dev.classmethod.jp/articles/snowflake-marketplace-truestar-japanese-calendar/ SnowflakeMarketplace上でtruestar社が提供するPrepperOpenDataBankJapaneseCalendarDataを試してみたSnowflakeDB※本エントリは、Snowflakeをもっと使いこなそうAdventCalendarの日目の記事となります。 2022-12-05 15:30:01
技術ブログ Developers.IO re:Inventでの体験まとめ〜Classmethod Sales Team編〜 https://dev.classmethod.jp/articles/sales-reinvent2022/ awsreinvent 2022-12-05 15:15:11
技術ブログ Developers.IO AWS re:Invent 2022に関するDevelopersIO投稿まとめ(2022年12月05日分) #reinvent https://dev.classmethod.jp/articles/aws-reinvent-2022-devio-entries-matome-2022-12-05/ awsreinvent 2022-12-05 15:07:25
海外TECH DEV Community Things I learned giving CSS workshops https://dev.to/bartveneman/things-i-learned-giving-css-workshops-2bho Things I learned giving CSS workshopsBeing so frustrated at the capacity of modern day Frontend Devs to write proper HTML and CSS I decided to host a worskhop For everyone interested individually minimal hours each These are the things I learned About the devs but also about myself and frontend in general The setupBring a design you like A magazine a dashboard some conference site whatever motivates you to build We ll start writing some meaningful HTML as we walk through the design no wrapper lt div gt s allowed without purpose After the HTML is mostly done we start writing CSS Work until satisfied or energy has run out The lowsDevs writing lt input gt elements without lt label gt and without lt form gt No description of the field no place to send the data to… Devs wanting to write their own event handler to listen for keydown on said input to check if enter was pressed Please use a regular lt form gt instead because hitting enter in the input field or pressin enter space while the submit button is focused will submit the form Apply display flex until it looks good Trust me flexbox is great but not the solution for all your problems Wrap a div around pretty much anything because it might come handy when starting to write the CSS No it doesn t and using a particular CSS framework put you in a mindset that you need to wrap every single element if you want to somehow align them Even though the framework didn t advertise that at all Nobody seems to have an idea about how position absolute works Like it s some kind of magic box and tinkering with it will eventually solve their issue Devs didn t recognise that their DevTools were telling them why their properties values weren t working DevTools do an excellent job these days of showing a warning when a declaration isn t applied because a parent element is missing a certain property or some other reason Clearly folks had never heard of this option Some folks thought it s only possible to create rows and columns using lt div gt s I don t even… The highsWe got to spend roughtly on writing the HTML in workshop that was supposed to teach them about CSS and everyone loved it no exceptions Folks were generally unaware of all the options available in HTML Also they were very open to the idea of building the HTML first and then solving the styling with CSS instead of trying to let their HTML match the design as closely as possible Devs were really grateful for doing a walkthrough of these things together as they felt it s so different from what they ve always done but faster and with better results Folks are pretty excited when they see what s prossible in modern CSS with pretty good browser support CSS Grid Flexbox magic accent color and way more Devs were pretty much aware that images need an alt attribute but what to write in it is a mystery to them Frequently asked questions during the workshopHow do I know when to use px em or even something else A recent article from Josh Comeau answers most of their questions rem in most cases em for some and hardly ever anything else in our field at least How does CSS Grid even work It looks way too magical to me Usually I refer them to either CSS Tricks or Wes Bos excellent course on the topic 2022-12-05 15:33:55
海外TECH DEV Community Creating an upvote system with React and Socket.io 🥳 🔝 https://dev.to/novu/creating-an-upvote-system-with-react-and-socketio-5aoj Creating an upvote system with React and Socket io What is this article about Upvotes became a great way to understand what your visitors want You can take websites like ProductHunt and public roadmaps like Gleap Upvoty Prodcamp have the ability to let user share their thoughts in votes Even Reddit one of the most popular social media lets people upvote or downvote your posts We are going to build something similar with images In this article you ll learn how to create an upvoting application that allows users to upload images using Websockets and upvote their favorite photos You ll also learn how to send emails via EmailJS to notify users when their images gain a vote Why Socket io Websockets Websockets allows us to use bi directional communication with the server It means that if we put in an upvote we can inform the other user about the new upvote without refreshing the page or using long polling Socket io is a popular JavaScript library that allows us to create real time bi directional communication between software applications and a Node js server It is optimised to process a large volume of data with minimal delay and provides better functionalities such as fallback to HTTP long polling or automatic reconnection Novu the first open source notification infrastructureJust a quick background about us Novu is the first open source notification infrastructure We basically help to manage all the product notifications It can be In App the bell icon like you have in Facebook Websockets Emails SMSs and so on I would be super happy if you could give us a star And let me also know in the comments ️ How to create a real time connection with React and Socket ioHere we ll set up the project environment for the image upvoting application You will also learn how to add Socket io to a React and Node js application and connect both development servers for real time communication via Socket io Create the project folder containing two sub folders named client and server mkdir upvote appcd upvote appmkdir client serverNavigate into the client folder via your terminal and create a new React js project cd clientnpx create react app Install Socket io client API React Toastify and React Router  React Router is a JavaScript library that enables us to navigate between pages in a React application and React Toastify is used to display colourful notifications to the users npm install socket io client react router dom react toastifyDelete the redundant files such as the logo and the test files from the React app and update the App js file to display Hello World as below function App return lt div gt lt p gt Hello World lt p gt lt div gt export default App Add the Socket io client API to the React app as below import io from socket io client http localhost is where the server host URL const socket io connect http localhost function App return lt div gt lt p gt Hello World lt p gt lt div gt export default App Navigate into the server folder and create a package json file cd server amp npm init yInstall Express js CORS Nodemon and Socket io Server API npm install express cors nodemon socket io react iconsExpress js is a fast minimalist framework that provides several features for building web applications in Node js  CORS is a Node js package that allows communication between different domains Nodemon is a Node js tool that automatically restarts the server after detecting file changes and Socket io allows us to configure a real time connection on the server Create an index js file the entry point to the web server touch index jsSet up a Node js server using Express js The code snippet below returns a JSON object when you visit the http localhost api in your browser index jsconst express require express const app express const PORT app use express urlencoded extended true app use express json app get api req res gt res json message Hello world app listen PORT gt console log Server listening on PORT Import the HTTP and the CORS library to allow data transfer between the client and the server domains const express require express const app express const PORT New importsconst http require http Server app const cors require cors app use express urlencoded extended true app use express json app use cors app get api req res gt res json message Hello world http listen PORT gt console log Server listening on PORT Next add Socket io to the project to create a real time connection Before the app get block copy the code below New imports const socketIO require socket io http cors origin http localhost Add this before the app get blocksocketIO on connection socket gt console log socket id user just connected socket on disconnect gt socket disconnect console log A user disconnected From the code snippet above the socket io connection function establishes a connection with the React app then creates a unique ID for each socket and logs the ID to the console whenever a user visits the web page When you refresh or close the web page the socket fires the disconnect event showing that a user has disconnected from the socket Configure Nodemon by adding the start command to the list of scripts in the package json file The code snippet below starts the server using Nodemon In server package json scripts test echo Error no test specified amp amp exit start nodemon index js You can now run the server with Nodemon by using the command below npm start Building the user interfaceHere we ll create the user interface for the upvoting application to enable users to sign in upload images and upvote any picture of their choice There are two rules required when building the upvoting application users can only vote once users can not upvote their own images Later in the tutorial I will guide you on how you can build such a efficient upvoting system Navigate into the client src folder and create a components folder containing the Login js Register js Photos js UploadPhoto js MyPhotos and SharePhoto js files cd clientmkdir componentscd componentstouch Login js Register js Photos js UploadPhoto js MyPhoto js SharePhoto jsFrom the code snippet above The Login component is the application s home page It prompts users to sign in to the application The Register component enables new users to create an account before they can sign in to the application The Photos component is the home page displayed to the users after authentication Users can view all the available images on this page and upvote them The UploadPhoto is only visible to authenticated users and allows users to upload images to the list of photos on the web application The MyPhoto page allows users to view only their uploaded images and share their profile links with friends The SharePhoto component is a dynamic route that shows all the images uploaded by a user Update the App js file to render the newly created components on different routes via React Router as below import React from react React Router configuration amp routesimport BrowserRouter Routes Route from react router dom import Photos from components Photos import Login from components Login import Register from components Register import UploadPhoto from components UploadPhoto import MyPhotos from components MyPhotos import SharePhoto from components SharePhoto React Toastify configurationimport ToastContainer from react toastify import react toastify dist ReactToastify css Websockets configurationimport io from socket io client const App gt const socket io connect http localhost return lt gt lt BrowserRouter gt lt Routes gt lt Route path element lt Login socket socket gt gt lt Route path register element lt Register socket socket gt gt lt Route path photos element lt Photos socket socket gt gt lt Route path photo upload element lt UploadPhoto socket socket gt gt lt Route path user photos element lt MyPhotos socket socket gt gt lt Route path share user element lt SharePhoto socket socket gt gt lt Routes gt lt BrowserRouter gt lt ToastContainer gt lt gt export default App Navigate into the src index css file and copy the code below It contains all the CSS required for styling this project import url Grotesk wght amp display swap margin box sizing border box font family Space Grotesk sans serif color ba body padding margin button border none outline none cursor pointer input padding px px navbar width min height vh padding px display flex align items center justify content space between background color fee position sticky top z index nav BtnGroup a nav BtnGroup button padding px width px font size px cursor pointer outline none background color fff border none border radius px text decoration none nav BtnGroup a margin right px nav BtnGroup a hover nav BtnGroup button hover background color ce color fff login register width min height vh display flex align items center justify content center flex direction column login form register form width px display flex flex direction column input padding px px margin bottom px border radius px border px solid ecc loginBtn registerBtn padding px font size px cursor pointer background color fee color ba border none outline none border radius px margin bottom px loginBtn hover registerBtn hover background color ce color fff link color ce cursor pointer text decoration none photoContainer width min height vh padding px display flex align items center justify content center flex wrap wrap photoContainer gt margin px photo width px height px position relative border radius px box shadow px px rgba imageContainer width position relative height photo image width height position absolute object fit cover border radius px upvoteIcon background color fff padding px px position absolute bottom px right px cursor pointer border radius px display flex flex direction column align items center upvoteIcon hover background color fee uploadContainer width min height vh display flex align items center justify content center uploadText width uploadText form display flex flex direction column uploadText gt h margin bottom px uploadBtn margin top px padding px background color ce color fff copyDiv width display flex align items center justify content center copyContainer margin top px padding px cursor pointer background color ce border radius px The Login pageCopy the code below into the Login component The application accepts the username and password from the user import React useEffect useState from react import Link from react router dom import useNavigate from react router dom const Login socket gt const navigate useNavigate const username setUsername useState const password setPassword useState const handleSignIn e gt if username trim amp amp password trim e preventDefault console log username password setPassword setUsername return lt div className login gt lt h style marginBottom px gt Login lt h gt lt form className login form method POST onSubmit handleSignIn gt lt label htmlFor username gt Username lt label gt lt input type text className input name username id username required value username onChange e gt setUsername e target value gt lt label htmlFor password gt Password lt label gt lt input type password className input name password id password required minLength value password onChange e gt setPassword e target value gt lt button className loginBtn gt LOG IN lt button gt lt p style textAlign center gt Don t have an account lt Link className link to register gt Create one lt Link gt lt p gt lt form gt lt div gt export default Login The Register pageCopy the code below into the Register js file to accepts the user s email username and password import React useState useEffect from react import Link from react router dom import useNavigate from react router dom const Register socket gt const navigate useNavigate const username setUsername useState const password setPassword useState const email setEmail useState const handleRegister e gt e preventDefault if username trim amp amp password trim amp amp email trim console log username email password setPassword setUsername setEmail return lt div className register gt lt h style marginBottom px gt Register lt h gt lt form className register form method POST onSubmit handleRegister gt lt label htmlFor email gt Email Address lt label gt lt input type email className input name email id email required value email onChange e gt setEmail e target value gt lt label htmlFor username gt Username lt label gt lt input type text className input name username id username required value username onChange e gt setUsername e target value gt lt label htmlFor password gt Password lt label gt lt input type password className input name password id password required minLength value password onChange e gt setPassword e target value gt lt button className registerBtn gt REGISTER lt button gt lt p style textAlign center gt Already have an account lt Link className link to gt Sign in lt Link gt lt p gt lt form gt lt div gt export default Register The Photos componentThis component is divided into two sub components which are the navigation and the main container containing the available images Copy the code below into the Photos js file import React useEffect useState from react import Nav from Nav import PhotoContainer from PhotoContainer const Home socket gt const photos setPhotos useState id image url vote count id image url vote count return lt div gt lt Nav gt lt PhotoContainer photos photos socket socket gt lt div gt export default Home Create the Nav and PhotoContainer sub components touch Nav js PhotoContainer jsCopy the code below into the Nav js file import React from react import Link from react router dom const Nav gt return lt nav className navbar gt lt h gt PhotoShare lt h gt lt div className nav BtnGroup gt lt Link to user photos style marginRight px gt My Photos lt Link gt lt Link to photo upload gt Upload Photo lt Link gt lt div gt lt nav gt export default Nav Update the PhotoContainer js file as below import React useEffect from react import MdOutlineArrowUpward from react icons md const PhotoContainer photos socket gt const handleUpvote id gt console log Upvote id return lt main className photoContainer gt photos map photo gt lt div className photo key photo id gt lt div className imageContainer gt lt img src photo image url alt photo id className photo image gt lt div gt lt button className upvoteIcon onClick gt handleUpvote photo id gt lt MdOutlineArrowUpward style fontSize px marginBottom px gt lt p style fontSize px color ce gt photo vote count lt p gt lt button gt lt div gt lt main gt export default PhotoContainer The UploadPhoto componentUpdate the UploadPhoto js to contain the code below import React useState from react import useNavigate from react router dom const UploadPhoto socket gt const navigate useNavigate const photoURL setPhotoURL useState const handleSubmit e gt e preventDefault console log photoURL return lt main className uploadContainer gt lt div className uploadText gt lt h gt Upload Image lt h gt lt form method POST onSubmit handleSubmit gt lt label gt Paste the image URL lt label gt lt input type text name fileImage value photoURL onChange e gt setPhotoURL e target value gt lt button className uploadBtn gt UPLOAD lt button gt lt form gt lt div gt lt main gt export default UploadPhoto The MyPhotos componentHere you ll learn how to copy and paste content with a click of a button using the React copy to clipboard library Within the MyPhotos component users can copy their profile URLs and share them with others React copy to clipboard is a package that allows us to copy and paste contents via a button click in React Install the React copy to clipboard library by running the code below npm install react copy to clipboardCopy the code below into the MyPhotos js file import React useEffect useState from react React Router configsimport Link from react router dom import useNavigate from react router dom import PhotoContainer from PhotoContainer React copy to clipboard configimport CopyToClipboard from react copy to clipboard const MyPhotos socket gt const navigate useNavigate const photos setPhotos useState const userLink setUserLink useState navigates users to the homepage for now const handleSignOut gt localStorage removeItem id localStorage removeItem myEmail navigate This function runs immediately the content is copied const copyToClipBoard gt alert Copied return lt div gt lt nav className navbar gt lt h gt PhotoShare lt h gt lt div className nav BtnGroup gt lt Link to photo upload gt Upload Photo lt Link gt lt button onClick handleSignOut gt Sign out lt button gt lt div gt lt nav gt lt div className copyDiv gt lt CopyToClipboard text userLink onCopy copyToClipBoard className copyContainer gt lt span className shareLink gt Copy your share link lt span gt lt CopyToClipboard gt lt div gt lt PhotoContainer socket socket photos photos gt lt div gt export default MyPhotos From the code snippet above CopyToClipboard is a component provided by React copy to clipboard that accepts two props text the content and the function that runs after copying the content onCopy The code snippet above represents the page layout We ll create the functionality in the subsequent sections The SharePhoto componentCopy the code below into the SharePhoto js file import React useEffect useState from react import useParams from react router dom import Nav from Nav import PhotoContainer from PhotoContainer const SharePhoto socket gt const navigate useNavigate const photos setPhotos useState This accepts the username from the URL share user const user useParams return lt div gt lt Nav gt lt PhotoContainer socket socket photos photos gt lt div gt export default SharePhoto Congratulations You ve completed the user interface for the upvoting application For the remaining part of this article you ll learn how to send data between the React js application and the Node js server How to create an authentication flow with Socket ioHere I ll guide you through creating an authentication flow via Socket io A user can create an account and log in and out of the application The user registration workflowUpdate the handleRegister function within the Register js component to send the user s email username and password to the server const handleRegister e gt e preventDefault if username trim amp amp password trim amp amp email trim triggers a register event socket emit register username email password setPassword setUsername setEmail Listen to the event on server as done below socketIO on connection socket gt console log socket id user just connected Create a listener to the event socket on register data gt data will be an object containing the data sent from the React app console log data socket on disconnect gt socket disconnect console log A user disconnected We ve successfully retrieved the data sent from the React app on the server Next let s save the users details First create an empty array to hold all the user details and a function that generates a random string as ID outside the socket io blockconst database const generateID gt Math random toString substring Update the event listener to save the user s details const database const generateID gt Math random toString substring socket on register data gt Destructure the user details from the object const username email password data Filters the database array to check if there is no existing user with the same email or username let result database filter user gt user email email user username username If none saves the data to the array the empty images array is required for the image uploads if result length database push id generateID username password email images returns an event stating that the registration was successful return socket emit registerSuccess Account created successfully This runs only when there is an error the user already exists socket emit registerError User already exists Next listen to the two events likely to be triggered when a user registers on the web application Import toast from React Toastifyimport toast from react toastify Add a useEffect hook that listens to both both eventsuseEffect gt socket on registerSuccess data gt toast success data navigates to the login page navigate socket on registerError error gt toast error error socket navigate The Login workflowUpdate the handleSignIn function within the Login js component to send the username and password of the user to the backend server const handleSignIn e gt if username trim amp amp password trim e preventDefault triggers a login event socket emit login username password setPassword setUsername Create a listener to the event on the server socketIO on connection socket gt other functions socket on login data gt data contains the username and password console log data Update the event listener to log the user into the web application as below socket on login data gt Destructures the credentials from the object const username password data Filters the array for existing objects with the same email and password let result database filter user gt user username username amp amp user password password If there is none it returns this error message if result length return socket emit loginError Incorrect credentials Returns the user s email amp id if the user exists socket emit loginSuccess message Login successfully data id result id email result email Listen to the two likely events within the Login js file useEffect gt socket on loginSuccess data gt toast success data message Saves the user s id and email to local storage for easy identification amp for making authorized requests localStorage setItem id data data id localStorage setItem myEmail data data email Redirects the user to the Photos component navigate photos Notifies the user of the error message socket on loginError error gt toast error error socket navigate Congratulations We ve created the authentication flow for the application Lastly let s protect the remaining routes by allowing only authenticated users to view the pages Copy the code snippet below into the UploadPhoto MyPhotos SharePhoto and Photos components useEffect gt function authenticateUser const id localStorage getItem id If ID is false redirects the user to the login page if id navigate authenticateUser navigate Adding and displaying images with Socket ioIn this section you ll learn how to upload images to the server and display them within the React application via Socket io Uploading images to the server via Socket ioNavigate into the UploadPhoto component and update the handleSubmit function as below const handleSubmit e gt e preventDefault Gets the id and email from the local storage const id localStorage getItem id const email localStorage getItem myEmail triggers an event to the server containing the user s credentials and the image url socket emit uploadPhoto id email photoURL Create the event listener on the server that adds the image to the database socket on uploadPhoto data gt Gets the id email and image URL const id email photoURL data Search the database for the user let result database filter user gt user id id creates the data structure for the image const newImage id generateID image url photoURL vote count votedUsers ref email adds the new image to the images array result images unshift newImage sends a new event containing the server response socket emit uploadPhotoMessage Upload Successful Listen for the server s response within the React application useEffect gt socket on uploadPhotoMessage data gt Displays the server s response toast success data navigate photos socket navigate Displaying the images within the React applicationHere we ll update the Photos MyPhotos and SharePhoto components to display the images The Photos component displays all the available photos within the application The MyPhotos component displays only the images uploaded by the user The SharePhoto component displays the images uploaded by a user via its username The Photos componentAdd a useEffect hook within the Photos js file that retrieves all the images from the server when the component mounts useEffect gt search can be anything socket emit allPhotos search socket Listen to the event and return all the available images on the server socket on allPhotos data gt an array to contain all the images let images loop through the items in the database for let i i lt database length i collect the images into the array images images concat database i images sends all the images through another event socket emit allPhotosMessage message Photos retrieved successfully photos images Update the useEffect hook within the Photos component to retrieve the images as below useEffect gt socket emit allPhotos search retrieve all the images from the server socket on allPhotosMessage data gt setPhotos data photos socket The MyPhotos componentUpdate the useEffect hook within the MyPhotos component to trigger an event that sends the user s id to the server via Socket io useEffect gt function authenticateUser const id localStorage getItem id if id navigate else sends the user id to the server socket emit getMyPhotos id authenticateUser navigate socket Listen to the event on the server and return the user s images socket on getMyPhotos id gt Filter the database items let result database filter db gt db id id Returns the images and the username socket emit getMyPhotosMessage data result images username result username Retrieve the images and username from the server as done below useEffect gt socket on getMyPhotosMessage data gt sets the user s images setPhotos data data sets the user s profile link setUserLink http localhost share data username socket The SharePhoto componentUpdate the useEffect hook within the SharePhoto component to request for the user s images when the component mounts useEffect gt function authenticateUser const id localStorage getItem id if id navigate else user is the username from the profile link socket emit sharePhoto user authenticateUser socket navigate user Listen to the event on the server and return the user s images socket on sharePhoto name gt Filters the database via the username let result database filter db gt db username name Returns the images via another event socket emit sharePhotoMessage result images Retrieve the images from the server as below useEffect gt socket on sharePhotoMessage data gt setPhotos data socket Congratulations on making it thus far  You ve learnt how to manipulate the data within the database and retrieve the items for each route In the upcoming section I ll guide you through how to upvote the images How to upvote the imagesHere I will guide you through upvoting the images within the web application Recall that users can not upvote their photos and can only upvote once Update the handleUpvote function within the PhotoContainer js to send the user and the image ID to the server const handleUpvote id gt socket emit photoUpvote userID localStorage getItem id photoID id Listen to the event on the server and upvote the selected image via its ID socket on photoUpvote data gt const userID photoID data let images saves all the images not belonging to the user into the images array for let i i lt database length i ensures that only other users images are separated into the images array if database i id userID images images concat database i images Filter the images array for the image selected for upvote const item images filter image gt image id photoID Returns this error if the selected image doesn t belong to other users if item length lt return socket emit upvoteError error message You cannot upvote your photos Gets the list of voted users from the selected image const voters item votedUsers Checks if the user has not upvoted the image before const authenticateUpvote voters filter voter gt voter userID If true the first time the user is upvoting the image if authenticateUpvote length increases the vote count item vote count adds the user ID to the list of voters voters push userID triggers this event to reflect the change in vote count socket emit allPhotosMessage message Photos retrieved successfully photos images Returns the upvote response return socket emit upvoteSuccess message Upvote successful item nullifies duplicate votes if the user ID already exists in the array of voted users socket emit upvoteError error message Duplicate votes are not allowed Listen to the likely response from the server within the PhotoContainer js file useEffect gt socket on upvoteSuccess data gt toast success data message logs the email of the user who owns the image console log data item ref socket on upvoteError data gt toast error data error message socket From the code snippet above data item ref is required because we want to send email notifications to the users when they upvote their images How to send emails via EmailJS in ReactEmailJS is a JavaScript library that enables us to send emails via client side technologies only without a server With EmailJS you can send texts and email templates and add attachments to the emails Here I ll guide you through adding EmailJS to the React js application and how to send emails to users whenever their images gain a vote Install EmailJS to the React application by running the code below npm install emailjs browserCreate an EmailJS account here and add an email service provider to your account Create an email template as done in the image below Update the PhotoContainer js file to send the email template to users whenever their images gain a vote import emailjs from emailjs browser const PhotoContainer photos socket gt const handleUpvote id gt socket emit photoUpvote userID localStorage getItem id photoID id The function sends email to the user to email key const sendEmail email gt emailjs send YOUR SERVICE ID YOUR TEMPLATE ID to email email from email localStorage getItem myEmail YOUR PUBLIC KEY then result gt console log result text error gt console log error text useEffect gt socket on upvoteSuccess data gt toast success data message Pass the image owner email into the function sendEmail data item ref socket on upvoteError data gt toast error data error message socket return lt div gt lt div gt You can get your EmailJS Public key from the Account section of your EmailJS dashboard Congratulations You ve completed the project for this tutorial ConclusionSo far you ve learnt the following how to set up Socket io in a React and Node js application create an authentication with Socket io and React communicate between a server and a client via Socket io andsend emails with EmailJS This tutorial walks you through a project you can build using Socket io and React Feel free to improve the application by adding an authentication library and a real time database The source code for this tutorial is available here Thank you for reading Help me out If you feel like this article helped you understand WebSockets better I would be super happy if you could give us a star And let me also know in the comments ️ 2022-12-05 15:24:04
海外TECH DEV Community What are the coolest uses of AI you've seen in the last couple of weeks? https://dev.to/deepgram/what-are-the-coolest-uses-of-ai-youve-seen-in-the-last-couple-of-weeks-2np0 What are the coolest uses of AI you x ve seen in the last couple of weeks There have been some really interesting uses of AI floating around the web recently What have been the coolest or most interesting you ve seen 2022-12-05 15:10:27
Apple AppleInsider - Frontpage News Apple Pay South Korea launch delayed by regulators https://appleinsider.com/articles/22/12/05/apple-pay-south-korean-launch-delayed-by-regulators?utm_medium=rss Apple Pay South Korea launch delayed by regulatorsThe launch of Apple Pay in South Korea continues to slowly roll onwards with the latest delay in proceedings forced at the last minute by a regulatory review Apple PayApple s mobile payments platform has yet to arrive in South Korea and was expected to become available in late November However it appears the country s Financial Supervisory Service has delayed the launch further into the future Read more 2022-12-05 15:18:33
海外科学 NYT > Science Who Will Care for ‘Kinless’ Seniors? https://www.nytimes.com/2022/12/03/health/elderly-living-alone.html family 2022-12-05 15:12:01
海外TECH WIRED Elon Musk's Twitter Isn’t Ready for the Next Natural Disaster https://www.wired.com/story/elon-musks-twitter-isnt-ready-for-the-next-natural-disaster/ looser 2022-12-05 15:26:04
金融 RSS FILE - 日本証券業協会 J-IRISS https://www.jsda.or.jp/anshin/j-iriss/index.html iriss 2022-12-05 15:15:00
金融 金融庁ホームページ 金融審議会「市場制度ワーキング・グループ」(第23回)を開催します。 https://www.fsa.go.jp/news/r4/singi/20221205.html 金融審議会 2022-12-05 17:00:00
金融 金融庁ホームページ 国際金融センター特設ページを更新しました。 https://www.fsa.go.jp/internationalfinancialcenter/index.html alfinancialcenterjapan 2022-12-05 15:45:00
金融 金融庁ホームページ 鈴木財務大臣兼内閣府特命担当大臣閣議後記者会見の概要(令和4年12月2日)を掲載しました。 https://www.fsa.go.jp/common/conference/minister/2022b/20221202-1.html 内閣府特命担当大臣 2022-12-05 15:45:00
ニュース BBC News - Home Child aged 12 dies of invasive strep A in London https://www.bbc.co.uk/news/health-63860028?at_medium=RSS&at_campaign=KARANGA london 2022-12-05 15:33:43
ニュース BBC News - Home Raheem Sterling: No threat of violence in England star's break-in - police https://www.bbc.co.uk/news/uk-england-surrey-63858882?at_medium=RSS&at_campaign=KARANGA oxshott 2022-12-05 15:05:28
ニュース BBC News - Home Brussels attacks: Trial begins over 2016 attacks that killed 32 https://www.bbc.co.uk/news/world-europe-63834777?at_medium=RSS&at_campaign=KARANGA families 2022-12-05 15:11:30
ニュース BBC News - Home World Cup 2022: England a better team than France, but Kylian Mbappe's a superstar - Rio Ferdinand https://www.bbc.co.uk/sport/av/football/63864029?at_medium=RSS&at_campaign=KARANGA World Cup England a better team than France but Kylian Mbappe x s a superstar Rio FerdinandBBC pundits Alan Shearer Rio Ferdinand and Ashley Williams look ahead to England s quarter final with France believing France should fear England and that Gareth Southgate s side are the better team while France have world class individuals 2022-12-05 15:42:08
ニュース BBC News - Home Uruguay and four players face Fifa disciplinaries https://www.bbc.co.uk/sport/football/63863760?at_medium=RSS&at_campaign=KARANGA Uruguay and four players face Fifa disciplinariesFifa opens disciplinary proceedings against Uruguay s FA and four players over their conduct at the end of their final World Cup group game against Ghana 2022-12-05 15:23:34
ニュース BBC News - Home World Cup 2022: England's Bukayo Saka 'more than happy' to take penalty against France https://www.bbc.co.uk/sport/football/63863655?at_medium=RSS&at_campaign=KARANGA World Cup England x s Bukayo Saka x more than happy x to take penalty against FranceEngland winger Bukayo Saka says he would be more than happy if he is required to take a penalty against France in the World Cup quarter final 2022-12-05 15:18:05

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)