Skip to content

Commit

Permalink
Optimize Theme Setting Page
Browse files Browse the repository at this point in the history
  • Loading branch information
lylwx committed Nov 27, 2023
1 parent f0cd7b2 commit c78e18d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 32 deletions.
106 changes: 77 additions & 29 deletions Wox.UI.React/src/components/settings/WoxSettingThemes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import React, { useEffect, useImperativeHandle, useState } from "react"
import styled from "styled-components"
import WoxThemePreview from "../themes/WoxThemePreview.tsx"
import { WoxThemeHelper } from "../../utils/WoxThemeHelper.ts"
import { Box, Card, CardContent, Chip, Divider, Skeleton, Typography } from "@mui/material"
import { Box, List, ListItemButton, ListItemText, Skeleton } from "@mui/material"
import { Theme } from "../../entity/Theme.typings"
import { useWindowSize } from "usehooks-ts"
import WoxScrollbar from "../tools/WoxScrollbar.tsx"

export type WoxSettingThemesRefHandler = {}

Expand All @@ -14,6 +16,8 @@ export default React.forwardRef((_props: WoxSettingThemesProps, ref: React.Ref<W
const [selectedThemeIndex, setSelectedThemeIndex] = useState(0)
const [currentTheme, setCurrentTheme] = useState<Theme>({} as Theme)
const [themes, setThemes] = useState<Theme[]>([])
const size = useWindowSize()

useImperativeHandle(ref, () => ({}))

useEffect(() => {
Expand All @@ -38,39 +42,83 @@ export default React.forwardRef((_props: WoxSettingThemesProps, ref: React.Ref<W
</Box>
)}
{!loading && (
<Card sx={{ width: "100%", borderRadius: 0, background: "transparent", boxShadow: "initial" }}>
<Typography variant="h6" component="div" sx={{ padding: "5px 16px", color: "white" }}>
Available Themes
</Typography>
<Divider />
<CardContent>
{themes.map((item, index) => {
return index === selectedThemeIndex ? (
<Chip
label={item.ThemeName}
color={"primary"}
onClick={() => {
setSelectedThemeIndex(index)
setCurrentTheme(themes[index])
}}
/>
) : (
<Chip
label={item.ThemeName}
onClick={() => {
setSelectedThemeIndex(index)
setCurrentTheme(themes[index])
}}
/>
)
})}
</CardContent>
</Card>
<Box sx={{ display: "flex", flexGrow: 1, height: size.height - 400 }}>
<div className={"theme-list-container"}>
<WoxScrollbar
className={"theme-list-scrollbars"}
scrollbarProps={{
autoHeightMax: size.height - 400
}}
>
<List>
{themes.map((item, index) => {
return (
<ListItemButton
selected={index === selectedThemeIndex}
onClick={() => {
setSelectedThemeIndex(index)
}}
>
<ListItemText primary={item.ThemeName} secondary={<span className={"theme-author"}>{item.ThemeAuthor}</span>} />
</ListItemButton>
)
})}
</List>
</WoxScrollbar>
</div>
<div className={"theme-setting-container"}>&nbsp;</div>
</Box>
// <Card sx={{ width: "100%", borderRadius: 0, background: "transparent", boxShadow: "initial" }}>
// <Typography variant="h6" component="div" sx={{ padding: "5px 16px", color: "white" }}>
// Available Themes
// </Typography>
// <Divider />
// <CardContent>
// {themes.map((item, index) => {
// return index === selectedThemeIndex ? (
// <Chip
// label={item.ThemeName}
// color={"primary"}
// onClick={() => {
// setSelectedThemeIndex(index)
// setCurrentTheme(themes[index])
// }}
// />
// ) : (
// <Chip
// label={item.ThemeName}
// onClick={() => {
// setSelectedThemeIndex(index)
// setCurrentTheme(themes[index])
// }}
// />
// )
// })}
// </CardContent>
// </Card>
)}
</Style>
)
})

const Style = styled.div`
margin-top: -32px;
.theme-list-container,
.theme-setting-container {
flex: 1;
height: 100%;
}
.theme-list-container {
border-right: 1px solid #23272d;
}
.theme-author {
color: #787b8b;
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: calc(50vw - 280px);
}
`
6 changes: 3 additions & 3 deletions Wox.UI.React/src/components/themes/WoxThemePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default (props: { theme: Theme }) => {
Actions: [
{
Id: "e5ec9374-facf-4733-9439-a3b9e067c4c1",
Name: "打开",
Name: "Open",
Icon: {
ImageType: "svg",
ImageData:
Expand All @@ -32,7 +32,7 @@ export default (props: { theme: Theme }) => {
},
{
Id: "115697fe-a395-4254-aaed-a8b570848df5",
Name: "打开所在文件夹",
Name: "Open Folder",
Icon: {
ImageType: "svg",
ImageData:
Expand All @@ -43,7 +43,7 @@ export default (props: { theme: Theme }) => {
},
{
Id: "ec482e87-099b-49fa-a9b7-8e1829abe1ce",
Name: "复制路径",
Name: "Copy Path",
Icon: {
ImageType: "base64",
ImageData:
Expand Down

0 comments on commit c78e18d

Please sign in to comment.