diff --git a/src/pages/settings/preference.tsx b/src/pages/settings/preference.tsx index b3c9c79..82c84ee 100644 --- a/src/pages/settings/preference.tsx +++ b/src/pages/settings/preference.tsx @@ -10,12 +10,14 @@ import { log, LogType, now } from 'utils' // todo: use components from Input.tsx export const PreferencesSetting = () => { + const { ndk, fetchEventFromUserRelays, publish } = useNDKContext() 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 { userWotLevel } = useAppSelector((state) => state.wot) + + const [wotLevel, setWotLevel] = useState(userWotLevel) + const [isSaving, setIsSaving] = useState(false) useEffect(() => { if (user?.pubkey) { @@ -80,9 +82,22 @@ export const PreferencesSetting = () => { const ndkEvent = new NDKEvent(ndk, signedEvent) await publish(ndkEvent) - dispatch(setUserWotLevel(wotLevel)) + .then((publishedOnRelays) => { + toast.success( + `Preferences published to following relays: \n\n${publishedOnRelays.join( + '\n' + )}` + ) - setIsSaving(false) + dispatch(setUserWotLevel(wotLevel)) + }) + .catch((err) => { + console.error(err) + toast.error('Error: Failed to publish preferences!') + }) + .finally(() => { + setIsSaving(false) + }) } return ( diff --git a/src/store/reducers/wot.ts b/src/store/reducers/wot.ts index 87a3881..4288c65 100644 --- a/src/store/reducers/wot.ts +++ b/src/store/reducers/wot.ts @@ -19,10 +19,10 @@ export interface IWOT { const initialState: IWOT = { siteWot: [], siteWotStatus: WOTStatus.IDLE, - siteWotLevel: 3, + siteWotLevel: 0, userWot: [], userWotStatus: WOTStatus.IDLE, - userWotLevel: 3 + userWotLevel: 0 } export const wotSlice = createSlice({