Skip to content

Commit 2128fa7

Browse files
authored
refactor: TabbedModal to use NewModal and DI (#5612)
* refactor: tabbed modal to use NewModal * refactor: use DI for instance settings modal instead of passing down props * pnpm prepr
1 parent 93c8163 commit 2128fa7

11 files changed

Lines changed: 582 additions & 236 deletions

File tree

apps/app-frontend/src/components/ui/instance_settings/GeneralSettings.vue

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,31 @@ import { useRouter } from 'vue-router'
1818
import ConfirmDeleteInstanceModal from '@/components/ui/modal/ConfirmDeleteInstanceModal.vue'
1919
import { trackEvent } from '@/helpers/analytics'
2020
import { duplicate, edit, edit_icon, list, remove } from '@/helpers/profile'
21+
import { injectInstanceSettings } from '@/providers/instance-settings'
2122
22-
import type { GameInstance, InstanceSettingsTabProps } from '../../../helpers/types'
23+
import type { GameInstance } from '../../../helpers/types'
2324
2425
const { handleError } = injectNotificationManager()
2526
const { formatMessage } = useVIntl()
2627
const router = useRouter()
2728
2829
const deleteConfirmModal = ref()
2930
30-
const props = defineProps<InstanceSettingsTabProps>()
31+
const { instance } = injectInstanceSettings()
3132
32-
const title = ref(props.instance.name)
33-
const icon: Ref<string | undefined> = ref(props.instance.icon_path)
34-
const groups = ref(props.instance.groups)
33+
const title = ref(instance.name)
34+
const icon: Ref<string | undefined> = ref(instance.icon_path)
35+
const groups = ref(instance.groups)
3536
3637
const newCategoryInput = ref('')
3738
38-
const installing = computed(() => props.instance.install_stage !== 'installed')
39+
const installing = computed(() => instance.install_stage !== 'installed')
3940
4041
async function duplicateProfile() {
41-
await duplicate(props.instance.path).catch(handleError)
42+
await duplicate(instance.path).catch(handleError)
4243
trackEvent('InstanceDuplicate', {
43-
loader: props.instance.loader,
44-
game_version: props.instance.game_version,
44+
loader: instance.loader,
45+
game_version: instance.game_version,
4546
})
4647
}
4748
@@ -52,7 +53,7 @@ const availableGroups = computed(() => [
5253
5354
async function resetIcon() {
5455
icon.value = undefined
55-
await edit_icon(props.instance.path, null).catch(handleError)
56+
await edit_icon(instance.path, null).catch(handleError)
5657
trackEvent('InstanceRemoveIcon')
5758
}
5859
@@ -70,7 +71,7 @@ async function setIcon() {
7071
if (!value) return
7172
7273
icon.value = value
73-
await edit_icon(props.instance.path, icon.value).catch(handleError)
74+
await edit_icon(instance.path, icon.value).catch(handleError)
7475
7576
trackEvent('InstanceSetIcon')
7677
}
@@ -101,19 +102,19 @@ watch(
101102
[title, groups, groups],
102103
async () => {
103104
if (removing.value) return
104-
await edit(props.instance.path, editProfileObject.value).catch(handleError)
105+
await edit(instance.path, editProfileObject.value).catch(handleError)
105106
},
106107
{ deep: true },
107108
)
108109
109110
const removing = ref(false)
110111
async function removeProfile() {
111112
removing.value = true
112-
const path = props.instance.path
113+
const path = instance.path
113114
114115
trackEvent('InstanceRemove', {
115-
loader: props.instance.loader,
116-
game_version: props.instance.game_version,
116+
loader: instance.loader,
117+
game_version: instance.game_version,
117118
})
118119
119120
await router.push({ path: '/' })
@@ -218,7 +219,7 @@ const messages = defineMessages({
218219
:src="icon ? convertFileSrc(icon) : icon"
219220
size="108px"
220221
class="!border-4 group-hover:brightness-75"
221-
:tint-by="props.instance.path"
222+
:tint-by="instance.path"
222223
no-shadow
223224
/>
224225
<div class="absolute top-0 right-0 m-2">

apps/app-frontend/src/components/ui/instance_settings/HooksSettings.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@ import { computed, ref, watch } from 'vue'
1010
1111
import { edit } from '@/helpers/profile'
1212
import { get } from '@/helpers/settings.ts'
13+
import { injectInstanceSettings } from '@/providers/instance-settings'
1314
14-
import type { AppSettings, Hooks, InstanceSettingsTabProps } from '../../../helpers/types'
15+
import type { AppSettings, Hooks } from '../../../helpers/types'
1516
1617
const { handleError } = injectNotificationManager()
1718
const { formatMessage } = useVIntl()
1819
19-
const props = defineProps<InstanceSettingsTabProps>()
20+
const { instance } = injectInstanceSettings()
2021
2122
const globalSettings = (await get().catch(handleError)) as AppSettings
2223
2324
const overrideHooks = ref(
24-
!!props.instance.hooks.pre_launch ||
25-
!!props.instance.hooks.wrapper ||
26-
!!props.instance.hooks.post_exit,
25+
!!instance.hooks.pre_launch || !!instance.hooks.wrapper || !!instance.hooks.post_exit,
2726
)
28-
const hooks = ref(props.instance.hooks ?? globalSettings.hooks)
27+
const hooks = ref(instance.hooks ?? globalSettings.hooks)
2928
3029
const editProfileObject = computed(() => {
3130
const editProfile: {
@@ -41,7 +40,7 @@ const editProfileObject = computed(() => {
4140
watch(
4241
[overrideHooks, hooks],
4342
async () => {
44-
await edit(props.instance.path, editProfileObject.value)
43+
await edit(instance.path, editProfileObject.value)
4544
},
4645
{ deep: true },
4746
)

apps/app-frontend/src/components/ui/instance_settings/InstallationSettings.vue

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ import {
2727
update_repair_modrinth,
2828
} from '@/helpers/profile'
2929
import { get_game_versions, get_loaders } from '@/helpers/tags'
30+
import { injectInstanceSettings } from '@/providers/instance-settings'
3031
31-
import type { InstanceSettingsTabProps, Manifest } from '../../../helpers/types'
32+
import type { Manifest } from '../../../helpers/types'
3233
3334
const { handleError } = injectNotificationManager()
3435
const { formatMessage } = useVIntl()
3536
const queryClient = useQueryClient()
3637
37-
const props = defineProps<InstanceSettingsTabProps>()
38-
const emit = defineEmits<{
39-
unlinked: []
40-
}>()
38+
const { instance, offline, isMinecraftServer, onUnlinked } = injectInstanceSettings()
4139
4240
const [
4341
fabric_versions,
@@ -75,9 +73,9 @@ const [
7573
])
7674
7775
const { data: modpackInfo } = useQuery({
78-
queryKey: computed(() => ['linkedModpackInfo', props.instance.path]),
79-
queryFn: () => get_linked_modpack_info(props.instance.path, 'must_revalidate'),
80-
enabled: computed(() => !!props.instance.linked_data?.project_id && !props.offline),
76+
queryKey: computed(() => ['linkedModpackInfo', instance.path]),
77+
queryFn: () => get_linked_modpack_info(instance.path, 'must_revalidate'),
78+
enabled: computed(() => !!instance.linked_data?.project_id && !offline),
8179
})
8280
8381
const repairing = ref(false)
@@ -103,13 +101,13 @@ function getManifest(loader: string) {
103101
provideAppBackup({
104102
async createBackup() {
105103
const allProfiles = await list()
106-
const prefix = `${props.instance.name} - Backup #`
104+
const prefix = `${instance.name} - Backup #`
107105
const existingNums = allProfiles
108106
.filter((p) => p.name.startsWith(prefix))
109107
.map((p) => parseInt(p.name.slice(prefix.length), 10))
110108
.filter((n) => !isNaN(n))
111109
const nextNum = existingNums.length > 0 ? Math.max(...existingNums) + 1 : 1
112-
const newPath = await duplicate(props.instance.path)
110+
const newPath = await duplicate(instance.path)
113111
await edit(newPath, { name: `${prefix}${nextNum}` })
114112
},
115113
})
@@ -120,30 +118,27 @@ provideInstallationSettings({
120118
const rows = [
121119
{
122120
label: formatMessage(commonMessages.platformLabel),
123-
value: formatLoaderLabel(props.instance.loader),
121+
value: formatLoaderLabel(instance.loader),
124122
},
125123
{
126124
label: formatMessage(commonMessages.gameVersionLabel),
127-
value: props.instance.game_version,
125+
value: instance.game_version,
128126
},
129127
]
130-
if (props.instance.loader !== 'vanilla' && props.instance.loader_version) {
128+
if (instance.loader !== 'vanilla' && instance.loader_version) {
131129
rows.push({
132130
label: formatMessage(messages.loaderVersion, {
133-
loader: formatLoaderLabel(props.instance.loader),
131+
loader: formatLoaderLabel(instance.loader),
134132
}),
135-
value: props.instance.loader_version,
133+
value: instance.loader_version,
136134
})
137135
}
138136
return rows
139137
}),
140-
isLinked: computed(() => !!props.instance.linked_data?.locked),
138+
isLinked: computed(() => !!instance.linked_data?.locked),
141139
isBusy: computed(
142140
() =>
143-
props.instance.install_stage !== 'installed' ||
144-
repairing.value ||
145-
reinstalling.value ||
146-
!!props.offline,
141+
instance.install_stage !== 'installed' || repairing.value || reinstalling.value || !!offline,
147142
),
148143
modpack: computed(() => {
149144
if (!modpackInfo.value) return null
@@ -154,9 +149,9 @@ provideInstallationSettings({
154149
versionNumber: modpackInfo.value.version?.version_number,
155150
}
156151
}),
157-
currentPlatform: computed(() => props.instance.loader),
158-
currentGameVersion: computed(() => props.instance.game_version),
159-
currentLoaderVersion: computed(() => props.instance.loader_version ?? ''),
152+
currentPlatform: computed(() => instance.loader),
153+
currentGameVersion: computed(() => instance.game_version),
154+
currentLoaderVersion: computed(() => instance.loader_version ?? ''),
160155
availablePlatforms: loaders?.value?.map((x) => x.name) ?? [],
161156
162157
resolveGameVersions(loader, showSnapshots) {
@@ -199,50 +194,50 @@ provideInstallationSettings({
199194
if (platform !== 'vanilla' && loaderVersionId) {
200195
editProfile.loader_version = loaderVersionId
201196
}
202-
await edit(props.instance.path, editProfile).catch(handleError)
197+
await edit(instance.path, editProfile).catch(handleError)
203198
},
204199
205200
afterSave: async () => {
206-
await install(props.instance.path, false).catch(handleError)
201+
await install(instance.path, false).catch(handleError)
207202
trackEvent('InstanceRepair', {
208-
loader: props.instance.loader,
209-
game_version: props.instance.game_version,
203+
loader: instance.loader,
204+
game_version: instance.game_version,
210205
})
211206
},
212207
213208
async repair() {
214209
repairing.value = true
215-
await install(props.instance.path, true).catch(handleError)
210+
await install(instance.path, true).catch(handleError)
216211
repairing.value = false
217212
trackEvent('InstanceRepair', {
218-
loader: props.instance.loader,
219-
game_version: props.instance.game_version,
213+
loader: instance.loader,
214+
game_version: instance.game_version,
220215
})
221216
},
222217
223218
async reinstallModpack() {
224219
reinstalling.value = true
225-
await update_repair_modrinth(props.instance.path).catch(handleError)
220+
await update_repair_modrinth(instance.path).catch(handleError)
226221
reinstalling.value = false
227222
trackEvent('InstanceRepair', {
228-
loader: props.instance.loader,
229-
game_version: props.instance.game_version,
223+
loader: instance.loader,
224+
game_version: instance.game_version,
230225
})
231226
},
232227
233228
async unlinkModpack() {
234-
await edit(props.instance.path, {
229+
await edit(instance.path, {
235230
linked_data: null as unknown as undefined,
236231
})
237232
await queryClient.invalidateQueries({
238-
queryKey: ['linkedModpackInfo', props.instance.path],
233+
queryKey: ['linkedModpackInfo', instance.path],
239234
})
240-
emit('unlinked')
235+
onUnlinked()
241236
},
242237
243238
getCachedModpackVersions: () => null,
244239
async fetchModpackVersions() {
245-
const versions = await get_project_versions(props.instance.linked_data!.project_id!).catch(
240+
const versions = await get_project_versions(instance.linked_data!.project_id!).catch(
246241
handleError,
247242
)
248243
return (versions ?? []) as Labrinth.Versions.v2.Version[]
@@ -255,25 +250,25 @@ provideInstallationSettings({
255250
},
256251
257252
async onModpackVersionConfirm(version) {
258-
await update_managed_modrinth_version(props.instance.path, version.id)
253+
await update_managed_modrinth_version(instance.path, version.id)
259254
await queryClient.invalidateQueries({
260-
queryKey: ['linkedModpackInfo', props.instance.path],
255+
queryKey: ['linkedModpackInfo', instance.path],
261256
})
262257
},
263258
264259
updaterModalProps: computed(() => ({
265260
isApp: true,
266261
currentVersionId:
267-
modpackInfo.value?.update_version_id ?? props.instance.linked_data?.version_id ?? '',
262+
modpackInfo.value?.update_version_id ?? instance.linked_data?.version_id ?? '',
268263
projectIconUrl: modpackInfo.value?.project?.icon_url,
269264
projectName: modpackInfo.value?.project?.title ?? 'Modpack',
270-
currentGameVersion: props.instance.game_version,
271-
currentLoader: props.instance.loader,
265+
currentGameVersion: instance.game_version,
266+
currentLoader: instance.loader,
272267
})),
273268
274269
isServer: false,
275270
isApp: true,
276-
showModpackVersionActions: !props.isMinecraftServer,
271+
showModpackVersionActions: !isMinecraftServer.value,
277272
repairing,
278273
reinstalling,
279274
})

apps/app-frontend/src/components/ui/instance_settings/JavaSettings.vue

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,31 @@ import JavaSelector from '@/components/ui/JavaSelector.vue'
1414
import useMemorySlider from '@/composables/useMemorySlider'
1515
import { edit, get_optimal_jre_key } from '@/helpers/profile'
1616
import { get } from '@/helpers/settings.ts'
17+
import { injectInstanceSettings } from '@/providers/instance-settings'
1718
18-
import type { AppSettings, InstanceSettingsTabProps } from '../../../helpers/types'
19+
import type { AppSettings } from '../../../helpers/types'
1920
2021
const { handleError } = injectNotificationManager()
2122
const { formatMessage } = useVIntl()
2223
23-
const props = defineProps<InstanceSettingsTabProps>()
24+
const { instance } = injectInstanceSettings()
2425
2526
const globalSettings = (await get().catch(handleError)) as unknown as AppSettings
2627
27-
const overrideJavaInstall = ref(!!props.instance.java_path)
28-
const optimalJava = readonly(await get_optimal_jre_key(props.instance.path).catch(handleError))
29-
const javaInstall = ref({ path: optimalJava.path ?? props.instance.java_path })
28+
const overrideJavaInstall = ref(!!instance.java_path)
29+
const optimalJava = readonly(await get_optimal_jre_key(instance.path).catch(handleError))
30+
const javaInstall = ref({ path: optimalJava.path ?? instance.java_path })
3031
31-
const overrideJavaArgs = ref((props.instance.extra_launch_args?.length ?? 0) > 0)
32-
const javaArgs = ref(
33-
(props.instance.extra_launch_args ?? globalSettings.extra_launch_args).join(' '),
34-
)
32+
const overrideJavaArgs = ref((instance.extra_launch_args?.length ?? 0) > 0)
33+
const javaArgs = ref((instance.extra_launch_args ?? globalSettings.extra_launch_args).join(' '))
3534
36-
const overrideEnvVars = ref((props.instance.custom_env_vars?.length ?? 0) > 0)
35+
const overrideEnvVars = ref((instance.custom_env_vars?.length ?? 0) > 0)
3736
const envVars = ref(
38-
(props.instance.custom_env_vars ?? globalSettings.custom_env_vars)
39-
.map((x) => x.join('='))
40-
.join(' '),
37+
(instance.custom_env_vars ?? globalSettings.custom_env_vars).map((x) => x.join('=')).join(' '),
4138
)
4239
43-
const overrideMemorySettings = ref(!!props.instance.memory)
44-
const memory = ref(props.instance.memory ?? globalSettings.memory)
40+
const overrideMemorySettings = ref(!!instance.memory)
41+
const memory = ref(instance.memory ?? globalSettings.memory)
4542
const { maxMemory, snapPoints } = (await useMemorySlider().catch(handleError)) as unknown as {
4643
maxMemory: number
4744
snapPoints: number[]
@@ -79,7 +76,7 @@ watch(
7976
memory,
8077
],
8178
async () => {
82-
await edit(props.instance.path, editProfileObject.value)
79+
await edit(instance.path, editProfileObject.value)
8380
},
8481
{ deep: true },
8582
)

0 commit comments

Comments
 (0)