diff --git a/beta/src/components/Layout/HomeContent.js b/beta/src/components/Layout/HomeContent.js index ae894b1b7..f800f393a 100644 --- a/beta/src/components/Layout/HomeContent.js +++ b/beta/src/components/Layout/HomeContent.js @@ -2,7 +2,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. */ -import {createContext, useState, useContext, Suspense} from 'react'; +import {createContext, useState, useContext, useId, Suspense} from 'react'; import cn from 'classnames'; import ButtonLink from '../ButtonLink'; import {IconRestart} from '../Icon/IconRestart'; @@ -103,12 +103,12 @@ export function HomeContent() {

- Try React for a part of your page + Add interactivity wherever you need it

- You don’t have to rewrite your entire app with React. Add - React as a <script> tag in your HTML, and - render interactive components anywhere on the page. + Each React component receives some data and returns what + should appear on the screen. Pass different data, and React + will update the screen to match it.

@@ -116,10 +116,9 @@ export function HomeContent() {

- React does not make assumptions about the rest of your stack. - Whether you use a traditional server environment like Python - or Ruby, a static HTML page generator, or write HTML by hand, - you can add interactivity with React. + You don’t have to rewrite your entire app to React. Add React + as a {' - - - - - `}

+
{`import { useState } from 'react'; + +function FilterableVideoList({ videos }) { + const [query, setQuery] = useState(''); + const filteredVideos = filterVideos(videos, query); + return ( + <> + setQuery(newQuery)} + /> + + + ); +}`}
-
- - -
-

- Interesting links -

- -

Thank you for visiting my page!

-
-
-
+
+ + +
@@ -943,7 +949,6 @@ function ConfPage({conf, isLoading, confPromise, playlistPromise}) { - }> @@ -1003,33 +1008,61 @@ function Talks({conf, playlistPromise}) { if (playlistPromise && !playlistPromise._resolved) { throw playlistPromise; } - return ; + return ; } -function VideoList({videos, children}) { - let headingText = 'No Videos Yet'; - if (videos.length > 0) { - headingText = videos.length + ' Videos'; +function FilterableVideoList({allVideos}) { + const [query, setQuery] = useState(''); + const foundVideos = findVideos(allVideos, query); + const emptyHeading = `No matches for "${query}"`; + return ( + <> + + + + ); +} + +function findVideos(videos, query) { + const keywords = query + .toLowerCase() + .split(' ') + .filter((s) => s !== ''); + if (keywords.length === 0) { + return videos; + } + return videos.filter((video) => { + const words = video.title.toLowerCase().split(' '); + return words.some((w) => keywords.some((kw) => w.startsWith(kw))); + }); +} + +function VideoList({videos, emptyHeading}) { + let heading = emptyHeading; + const count = videos.length; + if (count > 0) { + heading = count + ' Video'; + if (count > 1) heading += 's'; } return (

- {headingText} + {heading}

{videos.map((video) => ( ))} - {children}
); } -function Search({}) { +function SearchInput({value, onChange}) { + const id = useId(); return (
-