From 19f5107f94a023ebf8e01c228d4863ce65bb83c8 Mon Sep 17 00:00:00 2001 From: Tim Sweeney Date: Thu, 10 Oct 2024 14:10:04 -0700 Subject: [PATCH] Human: Nearly there - just need to do data fetch now --- .../LeaderboardPage/EditableMarkdown.tsx | 26 ++++-- .../LeaderboardConfigEditor.tsx | 86 ++++++++++++++++++- .../pages/LeaderboardPage/LeaderboardPage.tsx | 43 ++++++---- 3 files changed, 130 insertions(+), 25 deletions(-) diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/EditableMarkdown.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/EditableMarkdown.tsx index 12d3262044bb..12705870a1b7 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/EditableMarkdown.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/EditableMarkdown.tsx @@ -1,6 +1,13 @@ import {Box, TextField, Typography} from '@mui/material'; -import React, {useCallback, useLayoutEffect, useRef, useState} from 'react'; +import React, { + useCallback, + useEffect, + useLayoutEffect, + useRef, + useState, +} from 'react'; import ReactMarkdown from 'react-markdown'; +import styled from 'styled-components'; interface EditableMarkdownProps { value: string; @@ -8,6 +15,12 @@ interface EditableMarkdownProps { placeholder: string; } +const StyledReactMarkdown = styled(ReactMarkdown)` + > *:first-child { + margin-top: 0; + } +`; + export const EditableMarkdown: React.FC = ({ value, onChange, @@ -75,6 +88,12 @@ export const EditableMarkdown: React.FC = ({ }); }; + useEffect(() => { + requestAnimationFrame(() => { + updateHeight(); + }); + }, [updateHeight, value]); + return ( {isEditing ? ( @@ -84,9 +103,6 @@ export const EditableMarkdown: React.FC = ({ value={value} onChange={e => { onChange(e.target.value); - requestAnimationFrame(() => { - updateHeight(); - }); }} onBlur={handleBlur} placeholder={placeholder} @@ -114,7 +130,7 @@ export const EditableMarkdown: React.FC = ({ }, }} onClick={handleEdit}> - {value || placeholder} + {value || placeholder} )} diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardConfigEditor.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardConfigEditor.tsx index 7aca64572e01..d2ed94eb4ca5 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardConfigEditor.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardConfigEditor.tsx @@ -12,7 +12,7 @@ import { Tabs, Typography, } from '@mui/material'; -import React, {useEffect, useState} from 'react'; +import React, {useEffect, useMemo, useState} from 'react'; import { fetchDatasetNamesForSpec, @@ -66,6 +66,16 @@ export const LeaderboardConfigEditor: React.FC<{ })); }; + const updateDescription = (newDescription: string) => { + setConfig(prevConfig => ({ + ...prevConfig, + config: { + ...prevConfig.config, + description: newDescription, + }, + })); + }; + const handleTabChange = (event: React.SyntheticEvent, newValue: number) => { setActiveTab(newValue); }; @@ -81,7 +91,8 @@ export const LeaderboardConfigEditor: React.FC<{ }}> - + + @@ -93,7 +104,13 @@ export const LeaderboardConfigEditor: React.FC<{ updateConfig={updateConfig} /> )} - {activeTab === 1 && } + {activeTab === 1 && ( + + )} + {activeTab === 2 && } void; +}> = ({description, updateDescription}) => { + const [localDescription, setLocalDescription] = useState(description); + + const debouncedUpdate = useMemo( + () => + debounce((value: string) => { + updateDescription(value); + }, 300), + [updateDescription] + ); + + useEffect(() => { + setLocalDescription(description); + }, [description]); + + const handleChange = (event: React.ChangeEvent) => { + const newValue = event.target.value; + setLocalDescription(newValue); + debouncedUpdate(newValue); + }; + + return ( + +