Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapawar1 committed Apr 21, 2024
1 parent b50d89d commit b9014d1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
19 changes: 13 additions & 6 deletions src/app/(tabs)/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import PreviewCard from '../../../components/PreviewCard/PreviewCard';
import RecentSearchCard from '../../../components/RecentSearchCard/RecentSearchCard';
import { fetchGenres } from '../../../queries/genres';
import { fetchAllStoryPreviews } from '../../../queries/stories';
import { StoryPreview, RecentSearch, Genre, StoryPreviewWithPreloadedReactions } from '../../../queries/types';
import {
StoryPreview,
RecentSearch,
Genre,
StoryPreviewWithPreloadedReactions,
} from '../../../queries/types';
import colors from '../../../styles/colors';
import globalStyles from '../../../styles/globalStyles';
import { GenreType } from '../genre';
Expand Down Expand Up @@ -62,9 +67,13 @@ const setRecentStory = async (recentStories: StoryPreview[]) => {
};

function SearchScreen() {
const [allStories, setAllStories] = useState<StoryPreviewWithPreloadedReactions[]>([]);
const [allStories, setAllStories] = useState<
StoryPreviewWithPreloadedReactions[]
>([]);
const [allGenres, setAllGenres] = useState<Genre[]>([]);
const [searchResults, setSearchResults] = useState<StoryPreviewWithPreloadedReactions[]>([]);
const [searchResults, setSearchResults] = useState<
StoryPreviewWithPreloadedReactions[]
>([]);
const [search, setSearch] = useState('');
const [filterVisible, setFilterVisible] = useState(false);
const [recentSearches, setRecentSearches] = useState<RecentSearch[]>([]);
Expand All @@ -75,9 +84,7 @@ function SearchScreen() {

useEffect(() => {
(async () => {
fetchAllStoryPreviews().then((stories) =>
setAllStories(stories),
);
fetchAllStoryPreviews().then(stories => setAllStories(stories));
fetchGenres().then((genres: Genre[]) => setAllGenres(genres));
getRecentSearch().then((searches: RecentSearch[]) =>
setRecentSearches(searches),
Expand Down
8 changes: 4 additions & 4 deletions src/components/PreviewCard/PreviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ function PreviewCard({
excerpt,
tags,
pressFunction,
reactions: preloadedReactions = null
reactions: preloadedReactions = null,
}: PreviewCardProps) {
const [reactions, setReactions] = useState<string[] | null>(preloadedReactions);
const [reactions, setReactions] = useState<string[] | null>(
preloadedReactions,
);
useEffect(() => {
if (preloadedReactions != null) {
return;
}

(async () => {
console.log("fetching reactions");

const temp = await fetchAllReactionsToStory(storyId);
if (temp != null) {
setReactions(temp.map(r => r.reaction));
Expand Down
11 changes: 9 additions & 2 deletions src/queries/stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Story, StoryPreview, StoryCard, StoryPreviewWithPreloadedReactions } from './types';
import {
Story,
StoryPreview,
StoryCard,
StoryPreviewWithPreloadedReactions,
} from './types';
import supabase from '../utils/supabase';

export async function fetchAllStoryPreviews(): Promise<StoryPreviewWithPreloadedReactions[]> {
export async function fetchAllStoryPreviews(): Promise<
StoryPreviewWithPreloadedReactions[]
> {
const { data, error } = await supabase.rpc('fetch_all_story_previews');

if (error) {
Expand Down
1 change: 0 additions & 1 deletion src/queries/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface StoryPreviewWithPreloadedReactions {
reactions: string[];
}


export interface Author {
id: number;
name: string;
Expand Down

0 comments on commit b9014d1

Please sign in to comment.