Skip to content

Commit

Permalink
fix: switching character
Browse files Browse the repository at this point in the history
  • Loading branch information
songkeys committed Aug 24, 2022
1 parent 2d583d9 commit 19ff61c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion components/common/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function Avatar({
const { isLoading, data: character } = useCharacter(
characterId ?? initialCharacter?.characterId,
{
enabled: Boolean(characterId) && !Boolean(initialCharacter) && !src,
enabled: Boolean(characterId) && !src,
initialData: initialCharacter,
}
);
Expand All @@ -43,6 +43,8 @@ export default function Avatar({

src_ = ipfsLinkToHttpLink(src_);

// console.log({ isLoading, initialCharacter, character, src_ });

return (
<Avatar_
className="bg-coolgray-100"
Expand Down
3 changes: 0 additions & 3 deletions components/common/Character/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function CharacterName({
const { data, isLoading } = useCharacter(
characterId ?? initialCharacter.characterId,
{
enabled: Boolean(characterId) && !Boolean(initialCharacter),
initialData: initialCharacter,
}
);
Expand Down Expand Up @@ -60,15 +59,13 @@ export function CharacterHandle({
const { data: data1, isLoading: isLoading1 } = useCharacter(
characterId ?? initialCharacter?.characterId,
{
enabled: Boolean(characterId) && !Boolean(initialCharacter),
initialData: initialCharacter,
}
);

const { data: data2, isLoading: isLoading2 } = useCharacterByHandle(
handle ?? initialCharacter?.handle,
{
enabled: Boolean(handle) && !Boolean(initialCharacter),
initialData: initialCharacter,
}
);
Expand Down
14 changes: 9 additions & 5 deletions components/common/ConnectButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function AccountList() {

const modals = useModals();

const [shouldNavigate, setShouldNavigate] = useState(true);
const [shouldNavigate, shouldNavigateHandles] = useDisclosure(false); // FIXME: a closure bug?
const router = useRouter();

const hasNoResult = !isLoading && !data?.pages.some((page) => page.count > 0);
Expand Down Expand Up @@ -288,9 +288,13 @@ function AccountList() {
size="xs"
className="my-2"
checked={shouldNavigate}
onChange={(event) =>
setShouldNavigate(event.currentTarget.checked)
}
onChange={(event) => {
if (event.currentTarget.checked) {
shouldNavigateHandles.open();
} else {
shouldNavigateHandles.close();
}
}}
/>
</div>
),
Expand All @@ -301,7 +305,7 @@ function AccountList() {
if (shouldNavigate) {
setTimeout(() => {
router.push(composeCharacterHref(c.handle));
}, 500);
}, 1000);
}
},
});
Expand Down
1 change: 1 addition & 0 deletions utils/apis/indexer/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function useCurrentCharacterId() {
return useLocalStorage<number>({
key: CurrentCharacterIdKey,
serialize: (cid) => cid.toString(),
getInitialValueInEffect: false,
});
}
export function useDisconnectCurrentCharacter() {
Expand Down

0 comments on commit 19ff61c

Please sign in to comment.