You've already forked AstralRinth
forked from didirus/AstralRinth
refactor(ui): move Toggle component to Composition API + TS (#3281)
* refactor(frontend): move Toggle component to Composition API + TS **Toggle.vue**: - Enable composition API and TS - Added `disabled` to props - Remove redundant `checked` - Replace `modelValue` and `emits` with `defineModel` compiler macro **Others**: - Replace emit handling and `model-value` with `v-model` where simple logic was used - Not `FeatureFlagSettings.vue` (contained custom code on receiving emit) - Not `Mods.vue` (contained custom code on receiving emit) - Remove redundant `checked` attribute * fix(app): toggles not updating value
This commit is contained in:
@@ -5,7 +5,7 @@ import { handleError } from '@/store/notifications'
|
|||||||
import { defineMessages, useVIntl } from '@vintl/vintl'
|
import { defineMessages, useVIntl } from '@vintl/vintl'
|
||||||
import { get } from '@/helpers/settings'
|
import { get } from '@/helpers/settings'
|
||||||
import { edit } from '@/helpers/profile'
|
import { edit } from '@/helpers/profile'
|
||||||
import type { InstanceSettingsTabProps, AppSettings } from '../../../helpers/types'
|
import type { AppSettings, InstanceSettingsTabProps } from '../../../helpers/types'
|
||||||
|
|
||||||
const { formatMessage } = useVIntl()
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
@@ -114,7 +114,6 @@ const messages = defineMessages({
|
|||||||
<Toggle
|
<Toggle
|
||||||
id="fullscreen"
|
id="fullscreen"
|
||||||
:model-value="overrideWindowSettings ? fullscreenSetting : globalSettings.force_fullscreen"
|
:model-value="overrideWindowSettings ? fullscreenSetting : globalSettings.force_fullscreen"
|
||||||
:checked="fullscreenSetting"
|
|
||||||
:disabled="!overrideWindowSettings"
|
:disabled="!overrideWindowSettings"
|
||||||
@update:model-value="
|
@update:model-value="
|
||||||
(e) => {
|
(e) => {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Toggle, ThemeSelector, TeleportDropdownMenu } from '@modrinth/ui'
|
import { TeleportDropdownMenu, ThemeSelector, Toggle } from '@modrinth/ui'
|
||||||
import { useTheming } from '@/store/state'
|
import { useTheming } from '@/store/state'
|
||||||
import { get, set } from '@/helpers/settings'
|
import { get, set } from '@/helpers/settings'
|
||||||
import { watch, ref } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import { getOS } from '@/helpers/utils'
|
import { getOS } from '@/helpers/utils'
|
||||||
|
|
||||||
const themeStore = useTheming()
|
const themeStore = useTheming()
|
||||||
@@ -46,7 +46,6 @@ watch(
|
|||||||
<Toggle
|
<Toggle
|
||||||
id="advanced-rendering"
|
id="advanced-rendering"
|
||||||
:model-value="themeStore.advancedRendering"
|
:model-value="themeStore.advancedRendering"
|
||||||
:checked="themeStore.advancedRendering"
|
|
||||||
@update:model-value="
|
@update:model-value="
|
||||||
(e) => {
|
(e) => {
|
||||||
themeStore.advancedRendering = e
|
themeStore.advancedRendering = e
|
||||||
@@ -61,16 +60,7 @@ watch(
|
|||||||
<h2 class="m-0 text-lg font-extrabold text-contrast">Native Decorations</h2>
|
<h2 class="m-0 text-lg font-extrabold text-contrast">Native Decorations</h2>
|
||||||
<p class="m-0 mt-1">Use system window frame (app restart required).</p>
|
<p class="m-0 mt-1">Use system window frame (app restart required).</p>
|
||||||
</div>
|
</div>
|
||||||
<Toggle
|
<Toggle id="native-decorations" v-model="settings.native_decorations" />
|
||||||
id="native-decorations"
|
|
||||||
:model-value="settings.native_decorations"
|
|
||||||
:checked="settings.native_decorations"
|
|
||||||
@update:model-value="
|
|
||||||
(e) => {
|
|
||||||
settings.native_decorations = e
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-4 flex items-center justify-between">
|
<div class="mt-4 flex items-center justify-between">
|
||||||
@@ -78,16 +68,7 @@ watch(
|
|||||||
<h2 class="m-0 text-lg font-extrabold text-contrast">Minimize launcher</h2>
|
<h2 class="m-0 text-lg font-extrabold text-contrast">Minimize launcher</h2>
|
||||||
<p class="m-0 mt-1">Minimize the launcher when a Minecraft process starts.</p>
|
<p class="m-0 mt-1">Minimize the launcher when a Minecraft process starts.</p>
|
||||||
</div>
|
</div>
|
||||||
<Toggle
|
<Toggle id="minimize-launcher" v-model="settings.hide_on_process_start" />
|
||||||
id="minimize-launcher"
|
|
||||||
:model-value="settings.hide_on_process_start"
|
|
||||||
:checked="settings.hide_on_process_start"
|
|
||||||
@update:model-value="
|
|
||||||
(e) => {
|
|
||||||
settings.hide_on_process_start = e
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-4 flex items-center justify-between">
|
<div class="mt-4 flex items-center justify-between">
|
||||||
@@ -111,7 +92,6 @@ watch(
|
|||||||
<Toggle
|
<Toggle
|
||||||
id="toggle-sidebar"
|
id="toggle-sidebar"
|
||||||
:model-value="settings.toggle_sidebar"
|
:model-value="settings.toggle_sidebar"
|
||||||
:checked="settings.toggle_sidebar"
|
|
||||||
@update:model-value="
|
@update:model-value="
|
||||||
(e) => {
|
(e) => {
|
||||||
settings.toggle_sidebar = e
|
settings.toggle_sidebar = e
|
||||||
|
|||||||
@@ -57,16 +57,7 @@ watch(
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Toggle
|
<Toggle id="fullscreen" v-model="settings.force_fullscreen" />
|
||||||
id="fullscreen"
|
|
||||||
:model-value="settings.force_fullscreen"
|
|
||||||
:checked="settings.force_fullscreen"
|
|
||||||
@update:model-value="
|
|
||||||
(e) => {
|
|
||||||
settings.force_fullscreen = e
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center justify-between gap-4">
|
<div class="flex items-center justify-between gap-4">
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ watch(
|
|||||||
<Toggle
|
<Toggle
|
||||||
id="advanced-rendering"
|
id="advanced-rendering"
|
||||||
:model-value="getStoreValue(option)"
|
:model-value="getStoreValue(option)"
|
||||||
:checked="getStoreValue(option)"
|
|
||||||
@update:model-value="() => setStoreValue(option, !themeStore.featureFlags[option])"
|
@update:model-value="() => setStoreValue(option, !themeStore.featureFlags[option])"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -30,16 +30,7 @@ watch(
|
|||||||
option, you opt out and ads will no longer be shown based on your interests.
|
option, you opt out and ads will no longer be shown based on your interests.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Toggle
|
<Toggle id="personalized-ads" v-model="settings.personalized_ads" />
|
||||||
id="personalized-ads"
|
|
||||||
:model-value="settings.personalized_ads"
|
|
||||||
:checked="settings.personalized_ads"
|
|
||||||
@update:model-value="
|
|
||||||
(e) => {
|
|
||||||
settings.personalized_ads = e
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-4 flex items-center justify-between gap-4">
|
<div class="mt-4 flex items-center justify-between gap-4">
|
||||||
@@ -51,16 +42,7 @@ watch(
|
|||||||
longer be collected.
|
longer be collected.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Toggle
|
<Toggle id="opt-out-analytics" v-model="settings.telemetry" />
|
||||||
id="opt-out-analytics"
|
|
||||||
:model-value="settings.telemetry"
|
|
||||||
:checked="settings.telemetry"
|
|
||||||
@update:model-value="
|
|
||||||
(e) => {
|
|
||||||
settings.telemetry = e
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-4 flex items-center justify-between gap-4">
|
<div class="mt-4 flex items-center justify-between gap-4">
|
||||||
@@ -75,10 +57,6 @@ watch(
|
|||||||
as those added by mods. (app restart required to take effect)
|
as those added by mods. (app restart required to take effect)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Toggle
|
<Toggle id="disable-discord-rpc" v-model="settings.discord_rpc" />
|
||||||
id="disable-discord-rpc"
|
|
||||||
v-model="settings.discord_rpc"
|
|
||||||
:checked="settings.discord_rpc"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -179,7 +179,6 @@
|
|||||||
<Toggle
|
<Toggle
|
||||||
class="!mx-2"
|
class="!mx-2"
|
||||||
:model-value="!item.data.disabled"
|
:model-value="!item.data.disabled"
|
||||||
:checked="!item.data.disabled"
|
|
||||||
@update:model-value="toggleDisableMod(item.data)"
|
@update:model-value="toggleDisableMod(item.data)"
|
||||||
/>
|
/>
|
||||||
<ButtonStyled type="transparent" circular>
|
<ButtonStyled type="transparent" circular>
|
||||||
|
|||||||
@@ -40,12 +40,7 @@
|
|||||||
</span>
|
</span>
|
||||||
<span> Whether or not the subscription should be unprovisioned on refund. </span>
|
<span> Whether or not the subscription should be unprovisioned on refund. </span>
|
||||||
</label>
|
</label>
|
||||||
<Toggle
|
<Toggle id="unprovision" v-model="unprovision" />
|
||||||
id="unprovision"
|
|
||||||
:model-value="unprovision"
|
|
||||||
:checked="unprovision"
|
|
||||||
@update:model-value="() => (unprovision = !unprovision)"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<ButtonStyled color="brand">
|
<ButtonStyled color="brand">
|
||||||
@@ -114,7 +109,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { Badge, NewModal, ButtonStyled, DropdownSelect, Toggle } from "@modrinth/ui";
|
import { Badge, ButtonStyled, DropdownSelect, NewModal, Toggle } from "@modrinth/ui";
|
||||||
import { formatPrice } from "@modrinth/utils";
|
import { formatPrice } from "@modrinth/utils";
|
||||||
import { CheckIcon, XIcon } from "@modrinth/assets";
|
import { CheckIcon, XIcon } from "@modrinth/assets";
|
||||||
import { products } from "~/generated/state.json";
|
import { products } from "~/generated/state.json";
|
||||||
|
|||||||
@@ -225,7 +225,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<div class="preview">
|
<div class="preview">
|
||||||
<Toggle id="preview" v-model="previewMode" :checked="previewMode" />
|
<Toggle id="preview" v-model="previewMode" />
|
||||||
<label class="label" for="preview"> Preview </label>
|
<label class="label" for="preview"> Preview </label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -263,31 +263,31 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { type Component, computed, ref, onMounted, onBeforeUnmount, toRef, watch } from 'vue'
|
import { type Component, computed, onBeforeUnmount, onMounted, ref, toRef, watch } from 'vue'
|
||||||
import { Compartment, EditorState } from '@codemirror/state'
|
import { Compartment, EditorState } from '@codemirror/state'
|
||||||
import { EditorView, keymap, placeholder as cm_placeholder } from '@codemirror/view'
|
import { EditorView, keymap, placeholder as cm_placeholder } from '@codemirror/view'
|
||||||
import { markdown } from '@codemirror/lang-markdown'
|
import { markdown } from '@codemirror/lang-markdown'
|
||||||
import { indentWithTab, historyKeymap, history } from '@codemirror/commands'
|
import { history, historyKeymap, indentWithTab } from '@codemirror/commands'
|
||||||
import {
|
import {
|
||||||
|
AlignLeftIcon,
|
||||||
|
BoldIcon,
|
||||||
|
CodeIcon,
|
||||||
Heading1Icon,
|
Heading1Icon,
|
||||||
Heading2Icon,
|
Heading2Icon,
|
||||||
Heading3Icon,
|
Heading3Icon,
|
||||||
BoldIcon,
|
ImageIcon,
|
||||||
|
InfoIcon,
|
||||||
ItalicIcon,
|
ItalicIcon,
|
||||||
ScanEyeIcon,
|
LinkIcon,
|
||||||
StrikethroughIcon,
|
|
||||||
CodeIcon,
|
|
||||||
ListBulletedIcon,
|
ListBulletedIcon,
|
||||||
ListOrderedIcon,
|
ListOrderedIcon,
|
||||||
TextQuoteIcon,
|
|
||||||
LinkIcon,
|
|
||||||
ImageIcon,
|
|
||||||
YouTubeIcon,
|
|
||||||
AlignLeftIcon,
|
|
||||||
PlusIcon,
|
PlusIcon,
|
||||||
XIcon,
|
ScanEyeIcon,
|
||||||
|
StrikethroughIcon,
|
||||||
|
TextQuoteIcon,
|
||||||
UploadIcon,
|
UploadIcon,
|
||||||
InfoIcon,
|
XIcon,
|
||||||
|
YouTubeIcon,
|
||||||
} from '@modrinth/assets'
|
} from '@modrinth/assets'
|
||||||
import { markdownCommands, modrinthMarkdownEditorKeymap } from '@modrinth/utils/codemirror'
|
import { markdownCommands, modrinthMarkdownEditorKeymap } from '@modrinth/utils/codemirror'
|
||||||
import { renderHighlightedString } from '@modrinth/utils/highlight'
|
import { renderHighlightedString } from '@modrinth/utils/highlight'
|
||||||
|
|||||||
@@ -1,35 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<input
|
<input
|
||||||
:id="id"
|
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="switch stylized-toggle"
|
class="switch stylized-toggle"
|
||||||
|
:id="id"
|
||||||
|
:disabled="disabled"
|
||||||
:checked="checked"
|
:checked="checked"
|
||||||
@change="toggle"
|
@change="checked = !checked"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
export default {
|
defineProps<{
|
||||||
props: {
|
id?: string
|
||||||
id: {
|
disabled?: boolean
|
||||||
type: String,
|
}>()
|
||||||
required: true,
|
|
||||||
},
|
const checked = defineModel<boolean>()
|
||||||
modelValue: {
|
|
||||||
type: Boolean,
|
|
||||||
},
|
|
||||||
checked: {
|
|
||||||
type: Boolean,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
emits: ['update:modelValue'],
|
|
||||||
methods: {
|
|
||||||
toggle() {
|
|
||||||
if (!this.disabled) {
|
|
||||||
this.$emit('update:modelValue', !this.modelValue)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user