Skip to content

Commit

Permalink
chore: improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha authored and dr497 committed Jan 9, 2024
1 parent 9f56244 commit b9bd88b
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/screens/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,44 @@ export const SearchResult = ({
const connection = useSolanaConnection();
const { currentModal } = useModal();
const { setStatus } = useStatusModalContext();
const [search, setSearch] = useState(domain || "");
const [input, setInput] = useState(domain || "");
const results = useSearch({ connection: connection!, domain: search });
const [activeSearchQuery, setSearchQuery] = useState(domain || "");
// "inputFieldValue" is only responsible for what is displayed in input field, data
// is loaded based on "activeSearchQuery"
const [inputFieldValue, setInput] = useState(domain || "");
const results = useSearch({
connection: connection!,
domain: activeSearchQuery,
});
const suggestions = useDomainSuggestions({
connection: connection!,
domain: search,
domain: activeSearchQuery,
});
const navigation = useNavigation<profileScreenProp>();
const isFocused = useIsFocused();
const topDomainsSales = useTopDomainsSales(loadPopular);
const [showPopularDomains, togglePopularDomains] = useState(loadPopular);

useEffect(() => {
setSearch(domain || search);
setInput(domain || search);
setSearchQuery(domain || activeSearchQuery);
setInput(domain || activeSearchQuery);
}, [domain, isFocused]);

const handle = async () => {
if (!input) return;
if (!inputFieldValue) return;
togglePopularDomains(false);
if (isPubkey(input)) {
if (isPubkey(inputFieldValue)) {
return navigation.navigate("Home", {
screen: "search-profile",
params: { owner: input },
params: { owner: inputFieldValue },
});
}
if (!validate(input)) {
if (!validate(inputFieldValue)) {
return setStatus({
status: "error",
message: t`${input}.sol is not a valid domain`,
message: t`${inputFieldValue}.sol is not a valid domain`,
});
}
setSearch(trimTld(input));
setSearchQuery(trimTld(inputFieldValue));
};

return (
Expand All @@ -68,7 +73,7 @@ export const SearchResult = ({
<CustomTextInput
autoCapitalize="none"
onChangeText={(newText) => setInput(newText.toLowerCase())}
value={input}
value={inputFieldValue}
placeholder={t`Search for a domain`}
type="search"
editable={currentModal !== "Error"}
Expand All @@ -81,7 +86,7 @@ export const SearchResult = ({
<View style={tw`mt-4 w-[100%]`}>
<UiButton
onPress={handle}
disabled={!input}
disabled={!inputFieldValue}
content={t`Search your .SOL domain`}
/>
</View>
Expand Down

0 comments on commit b9bd88b

Please sign in to comment.