From 5c80834c3002e1e466e802c559b94d79575af91b Mon Sep 17 00:00:00 2001 From: Haoyu Xu Date: Sun, 26 Feb 2023 13:45:49 -0500 Subject: [PATCH] feat(directory): performance and style optimization --- directory/src/App.css | 7 +- directory/src/component/main_border.jsx | 4 +- directory/src/component/popup.css | 8 +- directory/src/component/popup.jsx | 2 + directory/src/context/useConfigContext.jsx | 2 +- directory/src/routes/path/home.css | 25 ++++- directory/src/routes/path/home.jsx | 116 ++++++++++----------- directory/src/routes/root.css | 15 ++- directory/src/routes/root.jsx | 7 +- 9 files changed, 103 insertions(+), 83 deletions(-) diff --git a/directory/src/App.css b/directory/src/App.css index ffaebd1..cf34d27 100644 --- a/directory/src/App.css +++ b/directory/src/App.css @@ -4,6 +4,7 @@ :root { --text-color: rgba(255, 255, 255, 0.87); + --secondary-text-color: #686a72; --date-color: rgba(255, 255, 255, 0.2); --border-color: #707070; --link-highlight-color: #33b5e5; @@ -16,16 +17,12 @@ font-family: "Geometos", "Noto Sans SC", sans-serif; font-size: 16px; - line-height: 24px; + line-height: 1.1em; font-weight: 400; color: var(--text-color); background-color: var(--root-background-color); min-height: 100vh; - - font-synthesis: none; - text-rendering: optimizeLegibility; - } #root { diff --git a/directory/src/component/main_border.jsx b/directory/src/component/main_border.jsx index 3707de2..f3980cd 100644 --- a/directory/src/component/main_border.jsx +++ b/directory/src/component/main_border.jsx @@ -2,6 +2,8 @@ import './main_border.css'; export default function MainBorder(props) { return ( -
+
+ {props.children} +
) } \ No newline at end of file diff --git a/directory/src/component/popup.css b/directory/src/component/popup.css index d905e53..05794a7 100644 --- a/directory/src/component/popup.css +++ b/directory/src/component/popup.css @@ -41,18 +41,18 @@ .popup .title { font-size: 3rem; font-weight: 700; - border-bottom: 1px solid var(--border-color); display: flex; flex-direction: row; justify-content: space-between; align-content: center; align-items: center; - padding-bottom: 1rem; + text-transform: uppercase; + font-family: "Geometos", "Noto Sans SC", sans-serif; } .popup .content { - line-height: 1.5rem; - padding: 1rem; + line-height: 1.3em; + padding: 1rem 1rem 0 1rem; } .popup .overlay { diff --git a/directory/src/component/popup.jsx b/directory/src/component/popup.jsx index b98b56e..06afe17 100644 --- a/directory/src/component/popup.jsx +++ b/directory/src/component/popup.jsx @@ -4,6 +4,7 @@ import { } from 'react' import './popup.css' import ReturnButton from '@/component/return_button'; +import MainBorder from '@/component/main_border'; export default function Popup(props) { const [hidden, setHidden] = useState(true) @@ -20,6 +21,7 @@ export default function Popup(props) { {props.title}
+
{props.children}
diff --git a/directory/src/context/useConfigContext.jsx b/directory/src/context/useConfigContext.jsx index bc048c5..8e4c438 100644 --- a/directory/src/context/useConfigContext.jsx +++ b/directory/src/context/useConfigContext.jsx @@ -3,7 +3,7 @@ import { createContext, useState, useEffect } from "react" export const ConfigContext = createContext() export function ConfigProvider(props) { - const [config, setConfig] = useState(null) + const [config, setConfig] = useState([]) useEffect(() => { fetch("/_assets/directory.json").then(res => res.json()).then(data => { diff --git a/directory/src/routes/path/home.css b/directory/src/routes/path/home.css index f8b3e7a..b00fa8d 100644 --- a/directory/src/routes/path/home.css +++ b/directory/src/routes/path/home.css @@ -24,8 +24,16 @@ background-image: repeating-linear-gradient(90deg, var(--home-item-background-linear-gradient-color) 0, var(--home-item-background-linear-gradient-color) 1px, transparent 1px, transparent 5px); } +.home .item-group .item .item-background-filler { + border-right: 1px solid var(--home-item-background-linear-gradient-color); + position: absolute; + top: 0; + left: 0; + right: -1px; + bottom: 0; +} + .home .item-group .item .item-outline { - content: ""; display: block; position: absolute; opacity: 0; @@ -94,20 +102,23 @@ font-weight: bold; } -.home .item-group .item .item-info .item-title-container .item-title, -.home .item-group .item .item-info .item-text-wrapper { +.home .item-group .item .item-info .item-title-container .item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; } +.home .item-group .item .item-info .item-title-container .item-title { + line-height: 1.1em; + height: 1.25rem; +} + .home .item-group .item .item-info .item-title-container .item-type { width: 1.5rem; fill: var(--text-color) } .home .item-group .item .item-info .item-text { - color: var(--text-color); font-size: 0.75rem; font-family: "Geometos"; margin-top: 1rem; @@ -123,4 +134,10 @@ visibility: hidden; transition: all cubic-bezier(0.65, 0.05, 0.36, 1) 0.3s; background-image: linear-gradient(70deg, transparent 40%, currentColor 150%); +} + +.home .item-group .item .item-info .item-text-wrapper { + overflow: hidden; + text-overflow: ellipsis; + color: var(--secondary-text-color); } \ No newline at end of file diff --git a/directory/src/routes/path/home.jsx b/directory/src/routes/path/home.jsx index 053065b..a5e4e5c 100644 --- a/directory/src/routes/path/home.jsx +++ b/directory/src/routes/path/home.jsx @@ -19,7 +19,7 @@ export default function Home() { const _trackEvt = useUmami('/') const { setTitle, - setTabs, + tabs, setTabs, currentTab, setCurrentTab } = useContext(HeaderContext) const { config } = useContext(ConfigContext) const { @@ -28,6 +28,7 @@ export default function Home() { alternateLang, i18n } = useContext(LanguageContext) + const [content, setContent] = useState([]) useEffect(() => { setTitle('dynamic_compile') @@ -46,70 +47,63 @@ export default function Home() { setCurrentTab('all') }, []) - const renderContent = () => { - const list = config?.filter((v) => currentTab === 'all' || currentTab === v.type) - const content = [] - if (list) { - console.log(list) - let items = {} - list.forEach(element => { - if (items[element.date]) { - items[element.date].push(toItemEl(element)) - } else { - items[element.date] = [toItemEl(element)] - } - }); - items = Object.keys(items).sort().reverse().reduce((r, k) => { - r[k] = items[k] - return r - }, {}) - for (const [date, group] of Object.entries(items)) { - content.push( -
-
- {group.map((v) => v)} -
{date}
-
- -
- ) + useEffect(() => { + const value = config.reduce((acc, cur) => { + const date = cur.date + if (acc[date]) { + acc[date].push(cur) + } else { + acc[date] = [cur] } - } - return content - } - const toItemEl = (item) => { - return ( - -
-
- {item.codename[language]} -
-
-
-
{item.codename[language]}
-
- -
-
-
- {item.codename[language.startsWith("en") ? alternateLang : textDefaultLang]} -
-
-
- - ) - } - const content = useMemo(() => renderContent(), [currentTab, config, language]) + return acc + }, {}) + setContent(Object.values(value).sort((a, b) => new Date(b[0].date) - new Date(a[0].date))) + }, [config]) + + const isShown = (type) => currentTab === 'all' || currentTab === type return (
- {content} + { + content.map((v) => { + const length = v.filter((v) => isShown(v.type)).length + return ( +