Skip to content

Commit 0fe0eb2

Browse files
committed
fix: sync accounts and tags
1 parent 27dd8a2 commit 0fe0eb2

File tree

4 files changed

+126
-6
lines changed

4 files changed

+126
-6
lines changed

src/components/selectors/accounts/hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
} from '../../../components/ui/third-party/extended/input-tags'
55

66
import { defaultColor } from '../../../config/constants/colors'
7-
import { getBulkTags } from '../../../config/constants/tags'
7+
import { BulkTags, getBulkTags } from '../../../config/constants/tags'
88

99
import { useGetAccounts } from '../../../hooks/accounts'
1010
import { useGetGroups } from '../../../hooks/groups'
@@ -73,7 +73,7 @@ export function useAccountSelectorData({
7373
const currentTags = parsedSelectedTags.map(({ value }) => value)
7474
const bulkTags = getBulkTags()
7575
const hasBulkTag = currentTags.some((tag) =>
76-
bulkTags.includes(tag.trim().toLowerCase())
76+
bulkTags.includes(tag.trim().toLowerCase() as BulkTags)
7777
)
7878

7979
if (hasBulkTag) {

src/routes/accounts/remove/-actions.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { GroupRecord } from '../../../types/groups'
22

33
import { useNavigate } from '@tanstack/react-router'
4+
import { useShallow } from 'zustand/react/shallow'
45

56
import {
67
useGetSaveQuestsActions,
@@ -12,9 +13,64 @@ import {
1213
} from '../../../hooks/accounts'
1314
import { useGetGroups } from '../../../hooks/groups'
1415

16+
import { useHomebaseNameStore } from '../../../state/stw-operations/homebase-name'
17+
import {
18+
useClaimRewardsSelectorStore,
19+
useKickAllPartySelectorStore,
20+
useLeavePartySelectorStore,
21+
} from '../../../state/stw-operations/party'
22+
import { useSaveQuestsStore } from '../../../state/stw-operations/save-quests'
23+
import { useXPBoostsFormStore } from '../../../state/stw-operations/xpboosts/forms/consume-personal'
24+
1525
import { toast } from '../../../lib/notifications'
1626
import { parseCustomDisplayName } from '../../../lib/utils'
1727

28+
function useClearForms() {
29+
const homebaseNameForm = useHomebaseNameStore(
30+
useShallow((state) => ({
31+
accounts: state.accounts,
32+
updateAccounts: state.updateAccounts,
33+
}))
34+
)
35+
const saveQuestsForm = useSaveQuestsStore(
36+
useShallow((state) => ({
37+
accounts: state.accounts,
38+
updateAccounts: state.updateAccounts,
39+
}))
40+
)
41+
const xpBoostsForm = useXPBoostsFormStore(
42+
useShallow((state) => ({
43+
accounts: state.accounts,
44+
updateAccounts: state.updateAccounts,
45+
}))
46+
)
47+
48+
return [homebaseNameForm, saveQuestsForm, xpBoostsForm]
49+
}
50+
51+
function useClearPartySelectors() {
52+
const kickAllPartySelector = useKickAllPartySelectorStore(
53+
useShallow((state) => ({
54+
accounts: state.value,
55+
updateAccounts: state.setValue,
56+
}))
57+
)
58+
const claimRewardsSelector = useClaimRewardsSelectorStore(
59+
useShallow((state) => ({
60+
accounts: state.value,
61+
updateAccounts: state.setValue,
62+
}))
63+
)
64+
const leavePartySelector = useLeavePartySelectorStore(
65+
useShallow((state) => ({
66+
accounts: state.value,
67+
updateAccounts: state.setValue,
68+
}))
69+
)
70+
71+
return [kickAllPartySelector, claimRewardsSelector, leavePartySelector]
72+
}
73+
1874
export function useHandleRemove() {
1975
const navigate = useNavigate()
2076
const { selected } = useGetSelectedAccount()
@@ -25,6 +81,10 @@ export function useHandleRemove() {
2581
const { selectedAccounts } = useGetSaveQuestsData()
2682
const { rawSaveQuestsUpdateAccounts } = useGetSaveQuestsActions()
2783

84+
// Clear forms
85+
const clearPartySelectors = useClearPartySelectors()
86+
const clearForms = useClearForms()
87+
2888
const handleRemove = () => {
2989
if (!selected) {
3090
return
@@ -41,6 +101,21 @@ export function useHandleRemove() {
41101
{} as GroupRecord
42102
)
43103

104+
clearPartySelectors.forEach((currentForm) => {
105+
currentForm.updateAccounts(
106+
currentForm.accounts.filter(
107+
(option) => option.value !== selected.accountId
108+
)
109+
)
110+
})
111+
clearForms.forEach((currentForm) => {
112+
currentForm.updateAccounts(
113+
currentForm.accounts.filter(
114+
(accountId) => accountId !== selected.accountId
115+
)
116+
)
117+
})
118+
44119
registerGroups(newGroups)
45120
rawSaveQuestsUpdateAccounts(
46121
selectedAccounts.filter(

src/routes/settings/-tags-management/-hooks.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ import { useEffect, useState } from 'react'
77

88
import { defaultColor } from '../../../config/constants/colors'
99

10+
import {
11+
useGetHomebaseNameActions,
12+
useGetHomebaseNameData,
13+
} from '../../../hooks/stw-operations/homebase-name'
1014
import {
1115
useGetSaveQuestsActions,
1216
useGetSaveQuestsData,
1317
} from '../../../hooks/stw-operations/save-quests'
18+
import {
19+
useGetXPBoostsActions,
20+
useGetXPBoostsFormData,
21+
} from '../../../hooks/stw-operations/xpboosts'
1422
import { useGetGroups } from '../../../hooks/groups'
1523
import { useGetTags } from '../../../hooks/tags'
1624

@@ -113,9 +121,15 @@ export function useFormUpdate({ rawData }: { rawData: Tag }) {
113121

114122
const { groupList, registerGroups } = useGetGroups()
115123

116-
const { selectedTags } = useGetSaveQuestsData()
124+
const saveQuestsData = useGetSaveQuestsData()
117125
const { rawSaveQuestsUpdateTags } = useGetSaveQuestsActions()
118126

127+
const homebaseNameData = useGetHomebaseNameData()
128+
const { rawHomebaseNameUpdateTags } = useGetHomebaseNameActions()
129+
130+
const xpBoostsFormData = useGetXPBoostsFormData()
131+
const { rawXPBoostsUpdateTags } = useGetXPBoostsActions()
132+
119133
useEffect(() => {
120134
setColor((rawData.color ?? defaultColor) as string)
121135
}, [rawData])
@@ -176,12 +190,24 @@ export function useFormUpdate({ rawData }: { rawData: Tag }) {
176190
)
177191

178192
registerGroups(newGroups)
193+
179194
rawSaveQuestsUpdateTags(
180-
selectedTags.map((currentTag) =>
195+
saveQuestsData.selectedTags.map((currentTag) =>
196+
currentTag === rawData.name ? newData.name : currentTag
197+
)
198+
)
199+
rawHomebaseNameUpdateTags(
200+
homebaseNameData.selectedTags.map((currentTag) =>
201+
currentTag === rawData.name ? newData.name : currentTag
202+
)
203+
)
204+
rawXPBoostsUpdateTags(
205+
xpBoostsFormData.selectedTags.map((currentTag) =>
181206
currentTag === rawData.name ? newData.name : currentTag
182207
)
183208
)
184209
tagsStore.updateTags(newTags, true)
210+
185211
window.electronAPI.updateTags(newTags)
186212
window.electronAPI.updateGroups(newGroups)
187213

@@ -202,10 +228,24 @@ export function useFormUpdate({ rawData }: { rawData: Tag }) {
202228
)
203229

204230
registerGroups(newGroups)
231+
205232
rawSaveQuestsUpdateTags(
206-
selectedTags.filter((currentTag) => currentTag !== tagName)
233+
saveQuestsData.selectedTags.filter(
234+
(currentTag) => currentTag !== tagName
235+
)
236+
)
237+
rawHomebaseNameUpdateTags(
238+
homebaseNameData.selectedTags.filter(
239+
(currentTag) => currentTag !== tagName
240+
)
241+
)
242+
rawXPBoostsUpdateTags(
243+
xpBoostsFormData.selectedTags.filter(
244+
(currentTag) => currentTag !== tagName
245+
)
207246
)
208247
tagsStore.updateTags(rawTagsRecord, true)
248+
209249
window.electronAPI.updateTags(rawTagsRecord)
210250
window.electronAPI.updateGroups(newGroups)
211251
}

src/routes/stw-operations/party/-hooks.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { useEffect, useState } from 'react'
1010
import { useGetAccounts } from '../../../hooks/accounts'
1111
import { useGetGroups } from '../../../hooks/groups'
1212
import { useClaimedRewards } from '../../../hooks/stw-operations/claimed-rewards'
13-
import { usePartyFriendsForm } from '../../../hooks/stw-operations/party'
13+
import {
14+
useInviteFriendsForm,
15+
usePartyFriendsForm,
16+
} from '../../../hooks/stw-operations/party'
1417

1518
import { checkIfCustomDisplayNameIsValid } from '../../../lib/validations/properties'
1619
import { toast } from '../../../lib/notifications'
@@ -205,6 +208,7 @@ export function useInviteActions({
205208
const [isInviting, setIsInviting] = useState(false)
206209
const [inputSearchValue, setInputSearchValue] = useState('')
207210
const { friends } = usePartyFriendsForm()
211+
const { setValue, value } = useInviteFriendsForm()
208212

209213
const friendOptions: Array<ComboboxOption> = Object.values(friends)
210214
.toSorted(
@@ -245,6 +249,7 @@ export function useInviteActions({
245249
useEffect(() => {
246250
const listener = window.electronAPI.notificationRemoveFriend(
247251
async ({ displayName, status }) => {
252+
setValue(value.filter((item) => friends[item.value] !== undefined))
248253
setIsSubmitting(false)
249254

250255
toast(

0 commit comments

Comments
 (0)