Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit fb1b6fb

Browse files
committed
[ui] Prevent navigating to results page if no theme usage selected in Squirrel theme editor
1 parent bceee27 commit fb1b6fb

File tree

8 files changed

+465
-410
lines changed

8 files changed

+465
-410
lines changed

package-lock.json

+265-255
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@types/react": "^18.0.28",
1313
"@types/react-dom": "^18.0.11",
1414
"@types/wicg-file-system-access": "^2020.9.5",
15-
"antd": "^5.2.1",
15+
"antd": "^5.4.6",
1616
"file-saver": "^2.0.5",
1717
"immer": "^9.0.21",
1818
"install": "^0.13.0",
@@ -74,4 +74,4 @@
7474
},
7575
"main": "main.js",
7676
"homepage": "https://pdog18.github.io/rime-soak/"
77-
}
77+
}

src/pages/Home.tsx

+25-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ import CustomPhrase from "./customPhrase/CustomPhrase"
1010
import WeaselCustomTheme from "./theme/weasel/CustomWeaselTheme"
1111
import KeyBinder from "./keyBinder/KeyBinder"
1212
import SquirrelPlayground from "./theme/squirrel/SquirrelPlayground"
13+
import { useEffect, useState } from "react"
14+
import useSquirrelStore from "./theme/squirrel/SquirrelStore"
15+
16+
const weasel = navigator.userAgent.indexOf("Win") !== -1
1317

1418
const items = [
1519
{
16-
key: "/default",
20+
key: "/",
1721
label: "基本",
1822
children: <Default />,
1923
},
@@ -25,7 +29,7 @@ const items = [
2529
{
2630
key: "/theme",
2731
label: "皮肤",
28-
children: navigator.userAgent.indexOf("Win") !== -1 ? <WeaselCustomTheme /> : <SquirrelPlayground />,
32+
children: weasel ? <WeaselCustomTheme /> : <SquirrelPlayground />,
2933
},
3034
{
3135
key: "/punctuation",
@@ -53,16 +57,23 @@ const Home = () => {
5357
const location = useLocation()
5458
const navigate = useNavigate()
5559

56-
const needChangeDefaultActive = items.filter((item) => item.key === location.pathname).length === 1
60+
const [activeKey, changeActiveKey] = useState(() => sessionStorage.getItem("activeKey") ?? `${location.pathname}`)
61+
62+
useEffect(() => {
63+
sessionStorage.setItem("activeKey", activeKey)
64+
}, [activeKey])
65+
66+
const squirrelState = useSquirrelStore()
5767

58-
const activeKey = needChangeDefaultActive ? location.pathname : "/default"
59-
// todo 如果依旧处于 Home 界面,手动输入 pathName 时需要重新渲染,这是 Tabs#defaultActiveKey 的问题,可能需要替换该组件
6068
return (
6169
<>
6270
<Tabs
6371
centered={true}
64-
defaultActiveKey={activeKey}
72+
activeKey={activeKey}
6573
style={{ height: "100%", minHeight: "100vh", backgroundColor: "#f3f3f3" }}
74+
onChange={(activeKey) => {
75+
changeActiveKey(activeKey)
76+
}}
6677
items={items.map((item) => {
6778
return {
6879
...item,
@@ -75,7 +86,14 @@ const Home = () => {
7586
type="primary"
7687
tooltip={<div>Save</div>}
7788
onClick={() => {
78-
navigate("/result")
89+
if (!weasel && activeKey === "/theme" && squirrelState.selectTheme === "none") {
90+
squirrelState.showToolTip(true)
91+
setTimeout(() => {
92+
squirrelState.showToolTip(false)
93+
}, 3000)
94+
} else {
95+
navigate("/result")
96+
}
7997
}}
8098
/>
8199
</>

src/pages/Result.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ const Result: React.FC = () => {
201201
style={{ alignSelf: "start", margin: "0 10vw" }}
202202
type="primary"
203203
onClick={() => {
204-
navigate("/")
204+
navigate(-1)
205+
// navigate()
205206
}}
206207
>
207208
返回

src/pages/theme/squirrel/SquirrelPlayground.tsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import SquirrelCheckBox from "./components/SquirrelCheckBox"
66
import SquirrelNumberInput from "./components/SquirrelNumberInput"
77
import SquirrelSelect from "./components/SquirrelSelect"
88
import { useState } from "react"
9-
109
import SquirrelColorPickers from "./components/SquirrelColorPickers"
10+
import { Tooltip } from "antd"
1111

1212
const SquirrelCustomTheme = () => {
1313
const state = useSquirrelStore<SquirrelStyleState>((state) => state)
1414
const preset_color_schemes = state.styleCustom.patch.preset_color_schemes
1515
const updateStyleLayout = state.updateStyleLayout
1616
const updateSquirrelColor = state.updateSquirrelColor
1717
const updateSelectTheme = state.updateSelectTheme
18+
const hintSelectThme = state.hintSelectThme
1819

1920
const {
2021
corner_radius,
@@ -68,13 +69,15 @@ const SquirrelCustomTheme = () => {
6869
}}
6970
>
7071
<SquirrelOutline title="使用主题">
71-
<SquirrelSelect
72-
flexDirection="column"
73-
name={"select:"}
74-
options={["none", "both", "light", "dark"]}
75-
value={state.selectTheme}
76-
onChange={updateSelectTheme}
77-
/>
72+
<Tooltip open={hintSelectThme} placement={"right"} title="选中使用的主题" color={"purple"} key={"purple"}>
73+
<SquirrelSelect
74+
flexDirection="column"
75+
name={"select:"}
76+
options={["none", "both", "light", "dark"]}
77+
value={state.selectTheme}
78+
onChange={updateSelectTheme}
79+
/>
80+
</Tooltip>
7881
</SquirrelOutline>
7982
<SquirrelOutline title="排列方向">
8083
<SquirrelSelect

src/pages/theme/squirrel/SquirrelStore.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,21 @@ const initLayout: SquirrelLayouts = {
100100
interface SquirrelStyleConfig {}
101101
interface SquirrelStyleState {
102102
selectTheme: ThemeSelectType
103+
hintSelectThme: boolean
103104
styleCustom: {
104105
patch: Patch
105106
}
106107
changeColorScheme: (color_scheme: string, config: SquirrelStyleConfig) => void
107108
updateStyleLayout: (path: string, value: string | number | boolean) => void
108109
updateSquirrelColor: (isDark: boolean, colorname: string, value: number) => void
109110
updateSelectTheme: (name: string, value: string) => void
111+
showToolTip: (show: boolean) => void
110112
generateYAML: () => string | null
111113
}
112114

113115
const useSquirrelStore = create<SquirrelStyleState>()((set, get) => ({
114116
selectTheme: "none",
117+
hintSelectThme: false,
115118
styleCustom: {
116119
patch: {
117120
"style/color_scheme": "solarized_light",
@@ -198,6 +201,13 @@ const useSquirrelStore = create<SquirrelStyleState>()((set, get) => ({
198201
})
199202
),
200203

204+
showToolTip: (show) =>
205+
set(
206+
produce((state: SquirrelStyleState) => {
207+
state.hintSelectThme = show
208+
})
209+
),
210+
201211
generateYAML: () => {
202212
const state = get()
203213

src/pages/theme/squirrel/components/SquirrelColorPickers.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export default function SquirrelColorPickers(props: SquirrelColorPickersProps) {
5353
const { inline_preedit, onChange } = props
5454

5555
const preeditColors = ["text_color", "hilited_text_color", "hilited_back_color", "preedit_back_color"]
56-
console.log(inline_preedit)
5756

5857
const convertedColors = Object.entries(props)
5958
.filter(([key, value]) => key.endsWith("_color") && typeof value === "number")
@@ -63,7 +62,7 @@ export default function SquirrelColorPickers(props: SquirrelColorPickersProps) {
6362
return (
6463
<div style={{ display: "flex", margin: "0 1vw", gap: "16px", flexWrap: "wrap" }}>
6564
{convertedColors.map(([name, color]) => (
66-
<div>
65+
<div key={name}>
6766
<div style={{ marginBottom: "6px" }}>{convertColorName(name)}</div>
6867
<RgbaColorPicker
6968
style={{ zoom: "0.7" }}

0 commit comments

Comments
 (0)