fix: select state.version for selector hook
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
kieran 2024-05-01 10:52:24 +01:00
parent 6398e470ef
commit d3bcb75f3a
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
7 changed files with 13 additions and 9 deletions

View File

@ -18,7 +18,7 @@ export interface RelayProps {
export default function Relay(props: RelayProps) {
const navigate = useNavigate();
const state = useLogin(s => s.state);
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
const name = useMemo(() => getRelayName(props.addr), [props.addr]);
const connection = useRelayState(props.addr);

View File

@ -6,7 +6,7 @@ import useLogin from "./useLogin";
* Simple hook for adding / removing follows
*/
export default function useFollowsControls() {
const state = useLogin(s => s.state);
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
return {
isFollowing: (pk: string) => {

View File

@ -12,7 +12,7 @@ export class MutedWordTag implements ToNostrEventTag {
}
export default function useModeration() {
const state = useLogin(s => s.state);
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
function isMuted(id: string) {
const link = NostrLink.publicKey(id);

View File

@ -39,7 +39,7 @@ const HashTagsPage = () => {
export default HashTagsPage;
export function HashTagHeader({ tag, events, className }: { tag: string; events?: number; className?: string }) {
const state = useLogin(s => s.state);
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
const isFollowing = useMemo(() => {
return state.isOnList(EventKind.InterestsList, new NostrHashtagLink(tag));
}, [state, tag]);

View File

@ -6,14 +6,12 @@ import { Link } from "react-router-dom";
import TimelineFollows from "@/Components/Feed/TimelineFollows";
import { TaskList } from "@/Components/Tasks/TaskList";
import useFollowsControls from "@/Hooks/useFollowControls";
import useLogin from "@/Hooks/useLogin";
import { DeckContext } from "@/Pages/Deck/DeckLayout";
import messages from "@/Pages/messages";
const FollowsHint = () => {
const publicKey = useLogin(s => s.publicKey);
const { followList } = useFollowsControls();
if (followList.length === 0 && publicKey) {
if (followList.length === 0) {
return (
<FormattedMessage
{...messages.NoFollows}

View File

@ -17,7 +17,7 @@ import messages from "./messages";
const RelaySettingsPage = () => {
const { publisher, system } = useEventPublisher();
const relays = useRelays();
const { readonly, state } = useLogin(s => ({ state: s.state, readonly: s.readonly }));
const { readonly, state } = useLogin(s => ({ v: s.state.version, state: s.state, readonly: s.readonly }));
const [newRelay, setNewRelay] = useState<string>();
const otherConnections = useMemo(() => {
@ -92,7 +92,7 @@ export function CloseRelays() {
const country = getCountry();
const [location, setLocation] = useState<{ lat: number; lon: number }>(country);
const currentRelays = useRelays();
const state = useLogin(s => s.state);
const { state } = useLogin(s => ({ v: s.state.version, state: s.state }));
const relayUrls = Object.keys(currentRelays);
async function loadRelays() {

View File

@ -63,6 +63,7 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
// state object will be used in the getters as a fallback value
#stateObj?: UserStateObject<TAppData>;
#didInit = false;
#version = 0;
constructor(
readonly pubkey: string,
@ -92,6 +93,7 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
this.#profile.on("change", () => this.emit("change", UserStateChangeType.Profile));
this.#contacts.on("change", () => this.emit("change", UserStateChangeType.Contacts));
this.#relays.on("change", () => this.emit("change", UserStateChangeType.Relays));
this.on("change", () => this.#version++);
}
async init(signer: EventSigner | undefined, system: SystemInterface) {
@ -143,6 +145,10 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
}
}
get version() {
return this.#version;
}
/**
* Users profile
*/