Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix option categories for small screens (#403) #404

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
"@babel/preset-env": "^7.26.9",
"@crowdin/crowdin-api-client": "^1.41.2",
"@rsdoctor/webpack-plugin": "^0.4.13",
"@swc/core": "^1.10.18",
"@swc/core": "^1.11.5",
"@swc/jest": "^0.2.37",
"@types/chrome": "0.0.306",
"@types/chrome": "0.0.307",
"@types/decompress": "^4.2.7",
"@types/echarts": "^5.0.0",
"@types/generate-json-webpack-plugin": "^0.3.7",
"@types/jest": "^29.5.14",
"@types/node": "^22.13.5",
"@types/node": "^22.13.8",
"@types/psl": "^1.1.3",
"@types/punycode": "^2.1.4",
"@types/webpack": "^5.28.5",
"@vue/babel-plugin-jsx": "^1.2.5",
"babel-loader": "^9.2.1",
"copy-webpack-plugin": "^12.0.2",
"babel-loader": "^10.0.0",
"copy-webpack-plugin": "^13.0.0",
"css-loader": "^7.1.2",
"decompress": "^4.2.1",
"eslint": "^9.21.0",
Expand All @@ -56,14 +56,14 @@
"postcss": "^8.5.3",
"postcss-loader": "^8.1.1",
"postcss-rtlcss": "^5.6.0",
"puppeteer": "^24.2.1",
"sass": "^1.85.0",
"puppeteer": "^24.3.0",
"sass": "^1.85.1",
"sass-loader": "^16.0.5",
"style-loader": "^4.0.0",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "5.7.3",
"typescript": "5.8.2",
"url-loader": "^4.1.1",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1"
Expand Down
33 changes: 15 additions & 18 deletions src/pages/app/components/Option/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { ElCard, ElSelect } from "element-plus"
import { defineComponent, h, ref, useSlots, watch } from "vue"
import { useRouter } from "vue-router"
import ContentContainer from "../common/ContentContainer"
import { changeQuery, type OptionCategory, parseQuery } from "./common"
import { CATE_LABELS, changeQuery, type OptionCategory, parseQuery } from "./common"

const IGNORED_CATE: OptionCategory[] = ['dailyLimit']

const _default = defineComponent(() => {
const tab = ref<OptionCategory>(parseQuery() || 'appearance')
const router = useRouter()
watch(tab, () => changeQuery(tab.value, router))

const slots = useSlots()

return () => (
<ContentContainer
v-slots={{
Expand All @@ -18,27 +22,20 @@ const _default = defineComponent(() => {
modelValue={tab.value}
onChange={val => tab.value = val}
>
<ElSelect.Option
label={t(msg => msg.option.appearance.title)}
value={'appearance' satisfies OptionCategory}
/>
<ElSelect.Option
label={t(msg => msg.option.statistics.title)}
value={'statistics' satisfies OptionCategory}
/>
<ElSelect.Option
label={t(msg => msg.option.popup.title)}
value={'popup' satisfies OptionCategory}
/>
<ElSelect.Option
label={t(msg => msg.option.backup.title)}
value={'backup' satisfies OptionCategory}
/>
{Object.keys(slots)
.filter(key => !IGNORED_CATE.includes(key as OptionCategory) && key !== 'default')
.map((cate: OptionCategory) => (
<ElSelect.Option
label={t(CATE_LABELS[cate])}
value={cate}
/>
))
}
</ElSelect>
),
default: () => (
<ElCard class="option-select-card">
{h(useSlots()[tab.value])}
{h(slots[tab.value])}
</ElCard>
)
}}
Expand Down
52 changes: 7 additions & 45 deletions src/pages/app/components/Option/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import { t } from "@app/locale"
import { Refresh } from "@element-plus/icons-vue"
import { useShadow } from "@hooks"
import { ElIcon, ElMessage, ElTabPane, ElTabs } from "element-plus"
import { defineComponent, h, ref } from "vue"
import { defineComponent, h, ref, useSlots } from "vue"
import { useRouter } from "vue-router"
import ContentContainer from "../common/ContentContainer"
import { changeQuery, type OptionCategory, parseQuery } from "./common"
import { CATE_LABELS, changeQuery, type OptionCategory, parseQuery } from "./common"

const resetButtonName = "reset"

const _default = defineComponent({
props: {
limitDisabled: Boolean,
},
emits: {
reset: (_cate: OptionCategory, _callback: () => void) => Promise.resolve(true),
},
setup: (props, ctx) => {
setup: (_, ctx) => {
const tab = ref(parseQuery() || 'appearance')
const router = useRouter()
const [limitDisabled] = useShadow(() => props.limitDisabled)

const handleBeforeLeave = async (activeName: string, oldActiveName: string): Promise<boolean> => {
if (activeName === resetButtonName) {
Expand All @@ -40,44 +35,11 @@ const _default = defineComponent({
beforeLeave={handleBeforeLeave}
class="option-tab"
>
<ElTabPane
name={"appearance" satisfies OptionCategory}
label={t(msg => msg.option.appearance.title)}
>
{h(ctx.slots.appearance)}
</ElTabPane>
<ElTabPane
name={"statistics" satisfies OptionCategory}
label={t(msg => msg.option.statistics.title)}
>
{h(ctx.slots.statistics)}
</ElTabPane>
<ElTabPane
name={"popup" satisfies OptionCategory}
label={t(msg => msg.option.popup.title)}
>
{h(ctx.slots.popup)}
</ElTabPane>
{!limitDisabled.value && (
<ElTabPane
name={"dailyLimit" satisfies OptionCategory}
label={t(msg => msg.menu.limit)}
>
{h(ctx.slots.dailyLimit)}
{Object.entries(useSlots()).filter(([key]) => key !== 'default').map(([key, slot]) => (
<ElTabPane name={key} label={t(CATE_LABELS[key])}>
{h(slot)}
</ElTabPane>
)}
<ElTabPane
name={"accessibility" satisfies OptionCategory}
label={t(msg => msg.option.accessibility.title)}
>
{h(ctx.slots.accessibility)}
</ElTabPane>
<ElTabPane
name={"backup" satisfies OptionCategory}
label={t(msg => msg.option.backup.title)}
>
{h(ctx.slots.backup)}
</ElTabPane>
))}
<ElTabPane
name={resetButtonName}
v-slots={{
Expand Down
10 changes: 10 additions & 0 deletions src/pages/app/components/Option/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* https://opensource.org/licenses/MIT
*/

import { type I18nKey } from "@app/locale"
import { type Router, useRoute } from "vue-router"

export const ALL_CATEGORIES = ["appearance", "statistics", "popup", 'dailyLimit', 'accessibility', 'backup'] as const
Expand All @@ -28,4 +29,13 @@ export function changeQuery(cate: OptionCategory, router: Router) {
const query = {}
query[PARAM] = cate
router.replace({ query })
}

export const CATE_LABELS: Record<OptionCategory, I18nKey> = {
appearance: msg => msg.option.appearance.title,
statistics: msg => msg.option.statistics.title,
popup: msg => msg.option.popup.title,
dailyLimit: msg => msg.menu.limit,
accessibility: msg => msg.option.accessibility.title,
backup: msg => msg.option.backup.title,
}
8 changes: 3 additions & 5 deletions src/pages/app/components/Option/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
import { useMediaSize } from "@hooks"
import { MediaSize } from "@hooks/useMediaSize"
import { MediaSize, useMediaSize } from "@hooks/useMediaSize"
import { defineComponent, ref, type Ref } from "vue"
import { type JSX } from "vue/jsx-runtime"
import { type OptionCategory, type OptionInstance } from "./common"
Expand All @@ -20,7 +19,7 @@ import './style.sass'
import Tabs from "./Tabs"

const _default = defineComponent(() => {
const paneRefMap: { [key in OptionCategory]: Ref<OptionInstance> } = {
const paneRefMap: Record<OptionCategory, Ref<OptionInstance>> = {
appearance: ref(),
statistics: ref(),
popup: ref(),
Expand All @@ -31,7 +30,7 @@ const _default = defineComponent(() => {

const mediaSize = useMediaSize()

const slots: { [key in OptionCategory]: () => JSX.Element } = {
const slots: Record<OptionCategory, () => JSX.Element> = {
appearance: () => <AppearanceOption ref={paneRefMap.appearance} />,
statistics: () => <StatisticsOption ref={paneRefMap.statistics} />,
popup: () => <PopupOption ref={paneRefMap.popup} />,
Expand All @@ -49,7 +48,6 @@ const _default = defineComponent(() => {
? <Select v-slots={slots} />
: (
<Tabs
limitDisabled={mediaSize.value <= MediaSize.sm}
onReset={handleReset}
v-slots={slots}
/>
Expand Down