-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4154 from traPtitech/Natsuki/theme-alter
テーマ設定のUI改善
- Loading branch information
Showing
6 changed files
with
180 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
src/components/Modal/SettingsThemeEditModal/SettingsThemeEditModal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<template> | ||
<modal-frame title="カスタムテーマ" icon-name=""> | ||
<div :class="$style.content"> | ||
<textarea-autosize v-model="editedTheme" :class="$style.jsonField" /> | ||
<div :class="$style.buttonContainer"> | ||
<form-button label="キャンセル" type="tertiary" @click="clearModal" /> | ||
<form-button | ||
label="更新する" | ||
:disabled="!isChanged" | ||
type="primary" | ||
@click="applyTheme" | ||
/> | ||
</div> | ||
</div> | ||
</modal-frame> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, ref, watchEffect } from 'vue' | ||
import type { Theme } from '/@/lib/theme/schema' | ||
import { themeSchema } from '/@/lib/theme/schema' | ||
import { dequal } from 'dequal' | ||
import { useToastStore } from '/@/store/ui/toast' | ||
import { reactive } from 'vue' | ||
import { useThemeSettings } from '/@/store/app/themeSettings' | ||
const useEditedThemes = ( | ||
props: { custom: Theme }, | ||
changeTheme: (theme: Theme) => void, | ||
clearModal: () => void | ||
) => { | ||
const { addErrorToast } = useToastStore() | ||
const appliedThemeStringified = computed(() => { | ||
const theme = props.custom | ||
return JSON.stringify(theme, null, '\t') | ||
}) | ||
const editedTheme = ref(appliedThemeStringified.value) | ||
watchEffect(() => { | ||
editedTheme.value = appliedThemeStringified.value | ||
}) | ||
const isChanged = computed(() => { | ||
try { | ||
return !dequal(JSON.parse(editedTheme.value), props.custom) | ||
} catch { | ||
return true | ||
} | ||
}) | ||
const failedUpdateTheme = (text: string) => { | ||
addErrorToast(`テーマの更新に失敗しました: ${text}`) | ||
} | ||
const applyTheme = () => { | ||
try { | ||
const themeObj = JSON.parse(editedTheme.value) | ||
const res = themeSchema.safeParse(themeObj) | ||
if (res.success) { | ||
changeTheme(res.data) | ||
clearModal() | ||
} else { | ||
failedUpdateTheme( | ||
`構文エラー: ${res.error.issues | ||
.map( | ||
issue => | ||
`[${issue.code}](${issue.path.join('.')}) ${issue.message}` | ||
) | ||
.join()}` | ||
) | ||
} | ||
} catch { | ||
failedUpdateTheme('無効なJSON') | ||
} | ||
} | ||
return { editedTheme, isChanged, applyTheme } | ||
} | ||
</script> | ||
|
||
<script lang="ts" setup> | ||
import FormButton from '/@/components/UI/FormButton.vue' | ||
import TextareaAutosize from '/@/components/UI/TextareaAutosize.vue' | ||
import ModalFrame from '../Common/ModalFrame.vue' | ||
import { useModalStore } from '/@/store/ui/modal' | ||
const { clearModal } = useModalStore() | ||
const state = reactive(useThemeSettings()) | ||
const changeTheme = (theme: Theme) => { | ||
state.custom = theme | ||
} | ||
const { editedTheme, isChanged, applyTheme } = useEditedThemes( | ||
state, | ||
changeTheme, | ||
clearModal | ||
) | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.content { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
gap: 32px; | ||
align-self: stretch; | ||
} | ||
.jsonField { | ||
@include color-ui-primary; | ||
@include background-secondary; | ||
width: 100%; | ||
display: flex; | ||
max-height: 292px; | ||
align-items: flex-start; | ||
align-self: stretch; | ||
border-radius: 4px; | ||
border: solid 2px transparent; | ||
padding: 4px; | ||
&:focus-within { | ||
border-color: $theme-accent-focus-default; | ||
} | ||
} | ||
.buttonContainer { | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: center; | ||
align-content: center; | ||
gap: 8px 16px; | ||
align-self: stretch; | ||
flex-wrap: wrap; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.