Skip to content

Commit

Permalink
supabase reaction queries, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
emilysunaryo committed Mar 13, 2024
1 parent 5bebbda commit 747ac64
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
74 changes: 74 additions & 0 deletions src/queries/reactions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Reactions } from './types';
import supabase from '../utils/supabase';

export async function addReactionToStory(
input_profile_id: number,
input_story_id: number,
input_reaction_id: number,
): Promise<void> {
const { data, error } = await supabase.rpc('add_reaction_to_story', {
story_id: input_story_id,
profile_id: input_profile_id,
reaction_id: input_reaction_id,
});
if (error) {
console.log(error);
throw new Error(
`An error occured when trying to insert author reaction to story: ${error}`,
);
} else {
return data;
}
}

export async function deleteReactionToStory(
input_profile_id: number,
input_story_id: number,
input_reaction_id: number,
): Promise<void> {
const { data, error } = await supabase.rpc('remove_reaction_from_story', {
story_id: input_story_id,
profile_id: input_profile_id,
reaction_id: input_reaction_id,
});
if (error) {
console.log(error);
throw new Error(
`An error occured when trying to delete reaction to story by a user: ${error}`,
);
} else {
return data;
}
}

export async function fetchStoryPreviewById(
storyId: number,
): Promise<StoryPreview[]> {
const { data, error } = await supabase.rpc('fetch_story_preview_by_id', {
input_story_id: storyId,
});
if (error) {
console.log(error);
throw new Error(
`An error occured when trying to fetch story preview by ID: ${error}`,
);
} else {
return data;
}
}

export async function fetchStoryPreviewById(
storyId: number,
): Promise<StoryPreview[]> {
const { data, error } = await supabase.rpc('fetch_story_preview_by_id', {
input_story_id: storyId,
});
if (error) {
console.log(error);
throw new Error(
`An error occured when trying to fetch story preview by ID: ${error}`,
);
} else {
return data;
}
}
9 changes: 3 additions & 6 deletions src/queries/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,9 @@ export async function fetchNewStories(): Promise<StoryCard[]> {
export async function fetchStoryPreviewById(
storyId: number,
): Promise<StoryPreview[]> {
const { data, error } = await supabase.rpc(
'current_fetch_story_preview_by_id',
{
input_story_id: storyId,
},
);
const { data, error } = await supabase.rpc('fetch_story_preview_by_id', {
input_story_id: storyId,
});
if (error) {
console.log(error);
throw new Error(
Expand Down
7 changes: 7 additions & 0 deletions src/queries/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ export interface GenreStories {
subgenre_name: string;
genre_story_previews: string[];
}

export interface Reactions {
profile_id: number;
story_id: number;
emoji_id: number;
emoji: string;
}

0 comments on commit 747ac64

Please sign in to comment.