投稿時間:2021-10-16 14:11:58 RSSフィード2021-10-16 14:00 分まとめ(18件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
TECH Engadget Japanese マイクロソフト「Xboxミニ冷蔵庫」を10月19日より予約受付。価格99.99ドル https://japanese.engadget.com/xbox-series-x-mini-fridge-043009257.html xboxseriesx 2021-10-16 04:30:09
js JavaScriptタグが付けられた新着投稿 - Qiita GR-ROSE と Node.js のプログラムの間でシリアル通信(一方向) https://qiita.com/youtoy/items/460a9458309b0b4a7dbd おわりにとりあえず、公式サンプルを流用したGRROSEとNodejsのプログラムの間でシリアル通信を試しました。 2021-10-16 13:11:26
js JavaScriptタグが付けられた新着投稿 - Qiita JavaScript入門(関数と宣言)① https://qiita.com/andota05/items/a32d5fee352f17ea1361 関数名・利用できる名前は変数名の命名規則と同じ変数の命名規則についてはこちらの記事をご参照ください仮引数・関数に渡す値が入る変数・複数ある場合はカンマで区切る処理内容関数の内容・で囲んだブロックの中に実行したい処理の内容を記載する返り値・関数が計算や処理した実行結果のこと・return文で実行結果を返すことができる・返り値は必須ではないため、関数で実行結果を返す必要がない場合は、retrun文を省略可能・省略した場合、未定義という意味のundefinedという結果が返される・また、return文以降の処理は実行されないため、処理の記載に注意が必要POINT「構成する要素ってなに」「にんじん・大根・豚肉」の具が入った豚汁で例えると豚汁の構成どんな物が入っているかは①具の「にんじん・大根・豚肉」と②具以外の「水・出汁・味噌」になる。 2021-10-16 13:10:57
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) ユーザーをグループに参加させたいです。 https://teratail.com/questions/364680?rss=all ユーザーをグループに参加させたいです。 2021-10-16 13:46:40
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) はじめてのAndroidプログラミング第4版 https://teratail.com/questions/364679?rss=all はじめてのAndroidプログラミング第版はじめてのAndroidプログラミング第版のchapter章のMyShcedulerのMainActicityのソースのlistがが赤文字になってしまい先に進めません。 2021-10-16 13:46:12
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) pythonスクリプトをexeファイルに変換しましたが、実行できず。。 https://teratail.com/questions/364678?rss=all pythonスクリプトをexeファイルに変換しましたが、実行できず。 2021-10-16 13:44:59
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) Pythonによるチェックサム(CRC)について https://teratail.com/questions/364677?rss=all PythonによるチェックサムCRCについてPythonでCRCを計算してデータ通信のチェックサムを行いたいです。 2021-10-16 13:37:35
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) CSSコーディング 内容が反映されない https://teratail.com/questions/364676?rss=all 内容 2021-10-16 13:35:09
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) サイト所有者のエラー:サイトキーのドメインが無効です https://teratail.com/questions/364675?rss=all サイト所有者のエラーサイトキーのドメインが無効です前提・実現したいこととあるサイトの模写コーディングを行っています。 2021-10-16 13:31:07
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) 'NavigableString' object has no attribute 'get'になる https://teratail.com/questions/364674?rss=all xNavigableStringxobjecthasnoattributexgetxになる初めてPythonを練習してます。 2021-10-16 13:30:16
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) セルに入力されたIDを読み込む方法 https://teratail.com/questions/364673?rss=all 直接 2021-10-16 13:26:36
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) postgresqlからmysqlに大量のテーブル内データをupsertしたい(laravel) https://teratail.com/questions/364672?rss=all postgresqlからmysqlに大量のテーブル内データをupsertしたいlaravel前提laravelnbsp読み取り専用のpostgresqlから、mysqlのテーブルにデータをupsertしたいです。 2021-10-16 13:08:23
AWS AWSタグが付けられた新着投稿 - Qiita AWSを使った動画配信についてメモ https://qiita.com/Masa79/items/2f8cb15a14eea6c1546f 2021-10-16 13:59:17
海外TECH DEV Community Build a full-stack Jamstack Application https://dev.to/hackmamba/build-a-full-stack-jamstack-application-5apm Build a full stack Jamstack ApplicationMany modern approaches for designing flexible and scalable web applications have become popular as browsers have evolved Jamstack is one of these cutting edge techniques to develop lightning fast web apps Jamstack combines the capabilities of JavaScript APIs and Markup to create modern browser friendly web apps which can function without any web servers In this tutorial you ll create a custom scrapbook application that allows you to store and access your daily memories from anywhere in the world Check out the live demo of the application you ll create Final demo Source codeBefore diving into this tutorial You should have a basic understanding of how to use ES features of JavaScript You should have beginner level experience of using React and React Hooks It would be advantageous if you have prior expertise with any design system in React Tech StackJamstack is unique because it allows you to integrate several technologies to create a full stack application You will use the following technologies to create this scrapbook Next js is a React framework that extends the amazing powers of React for creating multiple page apps easily Without using any backend frameworks like Express you may use Next js and its serverless functions to develop your app s frontend and backend Chakra UI provides a plethora of stylish and accessible react components for styling your web application You ll be using Airtable as a database solution for this application Airtable is a spreadsheet database hybrid with a fantastic API for integrating it into your application Cloudinary is a cloud media management platform where you ll upload photos of your scrapbook Auth enables you to integrate a user authentication system into your app It uses OAuth and provides a secure OAuth layer for your app Auth and Cloudinary both offer free plans You can create an account and use it for free to develop this application Table of ContentsGetting StartedConnecting Airtable to your appIntegrate Airtable with Next js Serverless functionsUploading files to CloudinaryCreate React Context for PostsSetup Authentication with AuthNext Steps Getting StartedFork this starter code sandbox template and get ready for coding the scrapbook application If you prefer to use local development you should have Node and NPM installed Running the following command creates a Next js and Chakra UI starter application with no configuration npx create next app example with chakra ui lt app name gt oryarn create next app example with chakra ui lt app name gt Now head over to Airtable and create a free account for yourself or log in if you already have one After logging in create a new base database from scratch by clicking on Add a base button and give it a meaningful name It makes a new base with some primary fields You can customize the table by double clicking on the columns Start customizing the table name to posts and add the following columns image URLcaption single line textcloudinaryId single line textuserId single line textdate DateThe base should look something like this Next navigate to Airtable API and select the base you d like to integrate Create a env file in the root directory and add some secrets as environment variables For connecting Airtable to our app you ll need the following secrets in the code API KEY the Airtable API key You can find it within the documentation by checking the Show API key box in the top right or on your account page BASE ID the id of the base you want to integrate You can find it on the documentation page TABLE NAME the name of the table in that base you can use a single base for multiple tables envAIRTABLE API KEY lt your airtable api key gt AIRTABLE BASE ID lt your airtable base id gt AIRTABLE TABLE NAME lt your airtable table name gt Install the Airtable JavaScript SDK to work with Airtable inside a Next js application npm install airtableAlso install the following dependencies to finish setting up your dev environment npm install auth nextjs auth multer next connect cloudinaryFor using Auth and Cloudinary in your application you need Auth Next js SDK auth nextjs auth and Cloudinary SDK cloudinary respectively Multer is for handling file inputs and Next connect is for dealing with middleware in Next js API Routes Connecting Airtable to Your AppNow create a new folder utils inside the src folder and add a new file Airtable js The code below connects your app to Airtable retrieves the data By default the Airtable returns unnecessary data The minifyRecords function returns the minified version of the record with necessary data utils Airtable jsconst Airtable require airtable AuthenticateAirtable configure apiKey process env AIRTABLE API KEY Initialize a baseconst base Airtable base process env AIRTABLE BASE ID Reference a tableconst table base process env AIRTABLE TABLE NAME To get an array of meaningful recordsconst minifyRecords records gt records map record gt id record id fields record fields export table minifyRecords Integrate Airtable with Next js Serverless FunctionsUsing API routes you can construct your own API in Next js Any file you add inside the pages api folder will be treated as an API endpoint api rather than a regular route You can handle any request that hits the endpoint using serverless functions Let s create an API endpoint to retrieve Airtable records src pages api getPosts js For retreving posts from Airtableimport table minifyRecords from utils Airtable export default async req res gt try get records from airtable const records await table select firstPage send an array of minified records as a response const minfiedRecords minifyRecords records res status json minfiedRecords catch error console error error res status json msg Something went wrong Setting up CloudinaryAfter uploading the scrapbook photos to Cloudinary you will need to store the secure url and public id to the Airtable database Go to your Cloudinary Dashboard copy the following secrets and paste them into the env file env CLOUDINARY CLOUD NAME lt your cloudinary cloud name gt CLOUDINARY API KEY lt your cloudinary api key gt CLOUDINARY API SECRET lt your cloudinary api secret gt After adding the environment variables create a new file cloudinary js inside utils directory to setup cloudinary utils cloudinary jsimport v as cloudinary from cloudinary cloudinary config cloud name process env CLOUDINARY CLOUD NAME api key process env CLOUDINARY API KEY api secret process env CLOUDINARY API SECRET export default cloudinary Uploading Files to CloudinaryYou can upload photos to Cloudinary using the uploader upload method of Cloudinary SDK By default Next js API routes cannot handle file input So you re going to use the multer that will append files to the request You ll also use next connect to deal with the middleware functions Learn more Create a new file createPost js inside api for uploading images src pages api createPost js For creating a new record in Airtableimport nextConnect from next connect import multer from multer import path from path import table minifyRecords from utils Airtable import cloudinary from utils cloudinary multer configconst upload multer storage multer diskStorage fileFilter req file cb gt let ext path extname file originalname if ext jpg amp amp ext jpeg amp amp ext png cb new Error File type is not supported false return cb null true const createPost nextConnect onError error req res res status json error error message Adds the middleware to Next Connect this should be the name of the form fieldcreatePost use upload single image createPost post async req res gt Uploading file to cloudinary const result await cloudinary uploader upload req file path Create a new record with required fields const post image result secure url caption req body caption cloudinaryId result public id userId req body userId Create a record with the above fields in Airtable the create method accepts and returns an array of records const newRecords await table create fields post res status json minifyRecords newRecords export default createPostexport const config api bodyParser false Try using Postman or something similar to test these endpoints If you run into any problems compare with the code snippet provided or try troubleshooting using the internet Displaying Scrapbook PostsNow that you have the API let s design an interface to display the data in our Next js application You can use the getServerSideProps function of Next js with serverside rendering to display data that is coming from an API Every time the page is rendered Next js runs the code contained within this function You can learn more about Next js server side rendering here Add the following code to the index js file The posts will be displayed as cards in a grid src pages index jsimport Container from components Container import Flex Grid Text from chakra ui react import Card from components Card export default function Index initialPosts return lt Container minH vh gt lt Flex flexDirection column justifyContent center alignItems center gt lt Flex w flexDirection column my gt initialPosts length lt Flex h vh vh w justifyContent center alignItems center gt lt Text fontSize xl xl opacity gt No Posts Added lt Text gt lt Flex gt lt Grid templateColumns repeat fr repeat fr repeat fr gap m auto w gt initialPosts map post gt return lt Card post post fields key post id gt lt Grid gt lt Flex gt lt Flex gt lt Container gt export async function getServerSideProps context try const res await fetch http localhost api getPosts return props initialPosts await res json catch error console log error return props err Something went wrong src components Card jsimport Box Text useColorModeValue from chakra ui react const Card post gt post lt Box w p flex borderWidth px bg useColorModeValue white gray borderColor useColorModeValue gray gray rounded lg shadow md gt lt Text textAlign right fontSize sm fontWeight bold mb gt new Date post date toString substr lt Text gt lt a href post image target blank rel noopener noreferrer gt lt img src post image alt post cloudinaryId loading lazy gt lt a gt lt Text fontSize md my noOfLines isTruncated gt post caption lt Text gt lt Box gt nullexport default Card Create React Context for PostsCreate a React context for Posts to share the state of posts across other components Create a new context folder inside src and add a new file posts js src context posts jsimport createContext useState from react const PostsContext createContext const PostsProvider children gt const posts setPosts useState const addPost async formData gt try sending the form data const res await fetch api createPost method POST body formData const newPost await res json updating the posts state setPosts prevPosts gt newPost prevPosts catch error console error error return lt PostsContext Provider value posts setPosts addPost gt children lt PostsContext Provider gt export PostsContext PostsProvider Wrap the app around the PostsProvider to use this context in your application src pages app jsimport PostsProvider from context posts import theme from utils theme function MyApp Component pageProps return lt PostsProvider gt lt ChakraProvider resetCSS theme theme gt lt ChakraProvider gt lt PostsProvider gt export default MyAppNow update the posts state to the initialPosts inside the index js file At this point you can see the cards populated with data from Airtable src pages index jsimport useContext useEffect from react import PostsContext from context posts export default function Index initialPosts const posts setPosts useContext PostsContext useEffect gt setPosts initialPosts initialPosts setPosts Creating a Form to Add PostCreate a form to add posts from a webpage Import the addPost function you created in context to submit the form data Before uploading the file you should include a preview of the uploaded photo See more about handling file input in JavaScript The toast in Chakra UI is something that displays a message in a separate modal In this component you ll use a toast to show the success message src components AddPost jsimport useContext useRef useState from react import Modal ModalOverlay ModalContent ModalHeader ModalFooter ModalBody ModalCloseButton Button FormControl FormLabel Input useDisclosure useToast from chakra ui react import PostsContext from context posts export const AddPost children gt const image setImage useState const caption setCaption useState const previewSource setPreviewSource useState const fileInputState setFileInputState useState const addPost useContext PostsContext const isOpen onOpen onClose useDisclosure const toast useToast const initialRef useRef const handleFileInput e gt const file e target files setPreviewSource URL createObjectURL file setImage file setFileInputState e target value const handleSubmit e gt e preventDefault if image return let formData new FormData formData append image image formData append caption caption addPost formData toast title Hurray description Post added status success duration isClosable true onClose setCaption setFileInputState setPreviewSource return lt gt lt Button fontWeight medium size md colorScheme yellow active transform scale onClick onOpen gt children lt Button gt lt Modal initialFocusRef initialRef isOpen isOpen onClose onClose gt lt ModalOverlay gt lt ModalContent gt lt ModalHeader fontWeight bold gt Add Post lt ModalHeader gt lt ModalCloseButton gt lt form onSubmit handleSubmit gt lt ModalBody pb gt lt FormControl gt lt FormLabel gt Photo lt FormLabel gt lt input type file name image ref initialRef onChange handleFileInput value fileInputState required gt lt FormControl gt previewSource amp amp lt img src previewSource alt chosen height px width px style margin px auto gt lt FormControl mt gt lt FormLabel gt Caption lt FormLabel gt lt Input placeholder Caption goes here type text value caption onChange e gt setCaption e target value gt lt FormControl gt lt ModalBody gt lt ModalFooter gt lt Button mr onClick onClose gt Cancel lt Button gt lt Button type submit colorScheme yellow mr gt Create lt Button gt lt ModalFooter gt lt form gt lt ModalContent gt lt Modal gt lt gt You ll be able to test the AddPost component after creating the navbar Your Navbar will have a title on the left Add post login logout and darkmode toggle buttons on the right Go ahead and create a new file Navbar js in components folder src components Navbar jsimport Link from next link import Button from chakra ui button import Flex Text from chakra ui layout import DarkModeSwitch from DarkModeSwitch import AddPost from AddPost const Navbar gt return lt Flex justifyContent space between w flexDirection column row m gt lt Text mb textAlign center fontWeight bold fontSize xl gt Scrapbook lt Text gt lt Flex justifyContent space between gt lt AddPost gt Add Post lt AddPost gt lt a href api auth login gt lt Button variant solid colorScheme blue mx size md gt Login lt Button gt lt a gt lt DarkModeSwitch gt lt Flex gt lt Flex gt export default NavbarAt this point you ll be able to add and display your scrapbook posts Let s add authentication using Auth Setup Authentication with AuthIf you are already an Auth user login to your account or create a free one today Create a new Regular web application You ll use the auth next js sdk to connect Auth with your application Select Next js when it asks what technology you re using The following secrets are required to configure Auth with your Next js application Go to the Settings tab and add the new Auth secrets to the env file env AUTH SECRET lt any secret string of length gt AUTH BASE URL http localhost lt Your application base URL gt AUTH ISSUER BASE URL lt URL of your tenant domain gt AUTH CLIENT ID lt Your application s client Id gt AUTH CLIENT SECRET lt Your application s client secret gt If you scroll down a little in the Settings tab you will find a section Application URIs Add the following callback URLs Add the base URL of your application if you re using codesandbox Allowed Callback URLs http localhost api auth callback​ api auth callbackAllowed Logout URLs http localhost Create a new file auth auth js inside the pages api directory Any route you add inside brackets will be treated as dynamic route src pages api auth auth jsimport handleAuth from auth nextjs auth export default handleAuth This generates required routes for authentication login logout and callback Under the hood Auth manages the user s authentication state using React Context Wrap the inner components of the pages app js file with the UserProvider to use the useUser hook provided by Auth in the entire application src pages app jsimport UserProvider from auth nextjs auth function MyApp Component pageProps return lt UserProvider gt lt PostsProvider gt lt PostsProvider gt lt UserProvider gt export default MyAppInside index js you can now use the useUser hook to retrieve user information Pass the user as a prop to the Navbar component to add login logout functionality Also let s display You have to log in if the user is not logged in src pages index js import useUser from auth nextjs auth export default function Index initialPosts const posts setPosts useContext PostsContext const user error isLoading useUser useEffect if isLoading return lt div gt Loading lt div gt if error return lt div gt error message lt div gt return lt Flex flexDirection column justifyContent center alignItems center gt lt Navbar user user gt user lt Flex w flexDirection column my gt posts length lt Flex h vh vh w justifyContent center alignItems center gt lt Text fontSize xl xl opacity gt No Posts Added lt Text gt lt Flex gt lt Grid templateColumns repeat fr repeat fr repeat fr gap m auto w gt posts map post gt console log post return lt Card post post fields key post id gt lt Grid gt lt Flex gt lt Flex h vh vh w justifyContent center alignItems center gt lt Text fontSize xl xl opacity gt You have to login lt Text gt lt Flex gt lt Flex gt export async function getServerSideProps context Update the Navbar js for logging in and out a user Also you should make sure that only a logged in user can add scrapbook posts src components Navbar jsimport Button from chakra ui button import Flex Text from chakra ui layout import DarkModeSwitch from DarkModeSwitch import AddPost from AddPost const Navbar user gt return lt Flex justifyContent space between w vw flexDirection column row m gt lt Text mb textAlign center fontWeight bold fontSize xl gt Scrapbook lt Text gt lt Flex justifyContent space between gt user amp amp lt AddPost gt Add Post lt AddPost gt user lt a href api auth logout gt lt Button variant solid colorScheme blue mx size md gt Logout lt Button gt lt a gt lt a href api auth login gt lt Button variant solid colorScheme blue mx size md gt Login lt Button gt lt a gt lt DarkModeSwitch gt lt Flex gt lt Flex gt export default Navbar Add Authentication to API RoutesOnly authenticated users should be able to access the API You must also associate each post with a specific user and display just the posts that belong to that person To obtain user information Auth provides withApiAuthRequired and getSession Update the API routes as follows pages api getPost js For retreving posts from Airtableimport getSession withApiAuthRequired from auth nextjs auth import table minifyRecords from utils Airtable export default withApiAuthRequired async req res gt const user await getSession req res try const records await table select filterByFormula userId user sub firstPage const minfiedItems minifyRecords records res status json minfiedItems catch error console error error res status json msg Something went wrong pages api createPost jsimport nextConnect from next connect import multer from multer import table minifyRecords from utils Airtable import cloudinary from utils cloudinary import getSession withApiAuthRequired from auth nextjs auth multer configconst upload multer storage multer diskStorage fileFilter req file cb gt let ext path extname file originalname if ext jpg amp amp ext jpeg amp amp ext png cb new Error File type is not supported false return cb null true const createPost nextConnect onError error req res res status json error error message Adds the middleware to Next ConnectcreatePost use upload single image createPost post async req res gt const user getSession req res Uploading file to cloudinary const result await cloudinary uploader upload req file path Create a new record with required fields const post image result secure url caption req body caption cloudinaryId result public id userId user sub Create a record with the above fields in Airtable the create method accepts and returns an array of records const newRecords await table create fields post res status json minifyRecords newRecords export default withApiAuthRequired createPost export const config api bodyParser false To access the protected API you should include the user s context such as Cookies along with the request Otherwise you will receive the error message not authenticated Change the fetch request within getServerSideProps to include the user s session token as a cookie src pages index js export async function getServerSideProps context try const res await fetch http localhost api posts headers Cookie context req headers cookie return props initialPosts await res json That s all Now you can see only the posts you have added Without logging in you won t be able to access the API routes Check my app here If you encounter any problems try to solve them using this source code If you prefer downloading here s the entire codebase on GitHub Next StepsIn this tutorial you have built a full stack Jamstack app with media management and authentication You can include some extra features like Updating and deleting the posts At present you can only upload small images Find a way to upload large images to your application You can perform media transformations with Cloudinary Optimize your images before uploading to save space in your cloud Try to display the user profile and include a route to update or delete the user Try thinking of some more crazy ways to add additional functionality and share them with the community For media management I prefer Cloudinary They allow you to store all of your media on a separate cloud other than your database Auth provides an extra layer of protection to your app You can personalize the login signup pages to reflect your brand Airtable is another powerful tool that I like because of its spreadsheet like user interface Based on your requirements you can use any database with Jamstack apps As previously said you can use Jamstack to develop full stack apps by combining various technologies based on your needs Content created for the Hackmamba Jamstack Content Hackathon with Auth and Cloudinary 2021-10-16 04:32:59
Apple AppleInsider - Frontpage News Amazon launches 7 must-have Apple bargains ahead of Black Friday https://appleinsider.com/articles/21/10/11/amazon-launches-7-must-have-apple-bargains-ahead-of-black-friday?utm_medium=rss Amazon launches must have Apple bargains ahead of Black FridayEarly Black Friday deals are heating up at Amazon with a variety of Apple products on sale this weekend Save on Macs AirPods and handy accessories AirPods ProAmazon s limited time discount on AirPods Pro has proven to be a top AirPods deal over the past seven days and rings in as the lowest price available across popular Apple resellers by at least Read more 2021-10-16 04:39:17
ニュース BBC News - Home Afghanistan: US offers to pay relatives of Kabul drone attack victims https://www.bbc.co.uk/news/world-us-canada-58935260?at_medium=RSS&at_campaign=KARANGA afghan 2021-10-16 04:31:12
ニュース BBC News - Home Sir David Amess: MPs express fears after constituency stabbing https://www.bbc.co.uk/news/uk-58931348?at_medium=RSS&at_campaign=KARANGA politicians 2021-10-16 04:43:00
北海道 北海道新聞 母子3人無理心中を図ったか 「子どもの首絞めた」と通報 https://www.hokkaido-np.co.jp/article/600712/ 無理心中 2021-10-16 13:07:00

コメント

このブログの人気の投稿

投稿時間: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件)