fix: change default value for wotLevel #151

Merged
freakoverse merged 1 commits from wot-fixes into staging 2024-11-18 10:20:45 +00:00
2 changed files with 22 additions and 7 deletions

View File

@ -10,12 +10,14 @@ import { log, LogType, now } from 'utils'
// todo: use components from Input.tsx // todo: use components from Input.tsx
export const PreferencesSetting = () => { export const PreferencesSetting = () => {
const { ndk, fetchEventFromUserRelays, publish } = useNDKContext()
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const [wotLevel, setWotLevel] = useState(3)
const [isSaving, setIsSaving] = useState(false)
const { ndk, fetchEventFromUserRelays, publish } = useNDKContext()
const user = useAppSelector((state) => state.user.user) const user = useAppSelector((state) => state.user.user)
const { userWotLevel } = useAppSelector((state) => state.wot)
const [wotLevel, setWotLevel] = useState(userWotLevel)
const [isSaving, setIsSaving] = useState(false)
useEffect(() => { useEffect(() => {
if (user?.pubkey) { if (user?.pubkey) {
@ -80,9 +82,22 @@ export const PreferencesSetting = () => {
const ndkEvent = new NDKEvent(ndk, signedEvent) const ndkEvent = new NDKEvent(ndk, signedEvent)
await publish(ndkEvent) await publish(ndkEvent)
dispatch(setUserWotLevel(wotLevel)) .then((publishedOnRelays) => {
toast.success(
`Preferences published to following relays: \n\n${publishedOnRelays.join(
'\n'
)}`
)
dispatch(setUserWotLevel(wotLevel))
})
.catch((err) => {
console.error(err)
toast.error('Error: Failed to publish preferences!')
})
.finally(() => {
setIsSaving(false) setIsSaving(false)
})
} }
return ( return (

View File

@ -19,10 +19,10 @@ export interface IWOT {
const initialState: IWOT = { const initialState: IWOT = {
siteWot: [], siteWot: [],
siteWotStatus: WOTStatus.IDLE, siteWotStatus: WOTStatus.IDLE,
siteWotLevel: 3, siteWotLevel: 0,
userWot: [], userWot: [],
userWotStatus: WOTStatus.IDLE, userWotStatus: WOTStatus.IDLE,
userWotLevel: 3 userWotLevel: 0
} }
export const wotSlice = createSlice({ export const wotSlice = createSlice({