Skip to content

Commit

Permalink
Fix bugs with last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmartineau committed Nov 9, 2023
1 parent 74c2ad8 commit 4e2282c
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 27 deletions.
7 changes: 4 additions & 3 deletions src/components/BookmarkForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { CONTENT, DEFAULT_BOOKMARK_FORM_URL_PLACEHOLDER } from '../constants';
import { useToggle } from '../hooks/useToggle';
import { MetadataResponse } from '../types/api';
import { type Bookmark, type BookmarkFormValues } from '../types/db';
import { Database } from '../types/supabase';
import { MetaTag, getDbMetadata } from '../utils/fetching/meta';
import { getScrapeData } from '../utils/fetching/scrape';
import { getErrorMessage } from '../utils/get-error-message';
Expand Down Expand Up @@ -76,7 +77,7 @@ export const BookmarkForm = ({
const isNew = type === 'new';
const router = useRouter();
const bookmarkformClass = cn(className, 'bookmark-form flex flex-col gap-s');
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();
const [formSubmitting, , setFormSubmitting] = useToggle(false);
const [bookmarkTags, setBookmarkTags] = useState<MetaTag[]>([]);
const [formError, setFormError] = useState<string>('');
Expand Down Expand Up @@ -128,7 +129,7 @@ export const BookmarkForm = ({
} else {
await supabaseClient
.from('bookmarks')
.update({ ...formData, modified_at: new Date() })
.update({ ...formData, modified_at: new Date().toString() })
.match({ id });
toast({
title: 'Item edited',
Expand Down Expand Up @@ -219,7 +220,7 @@ export const BookmarkForm = ({
const { data } = await supabaseClient.rpc('check_url', {
url_input: url.hostname,
});
setPossibleMatchingItems(data);
setPossibleMatchingItems(data as Bookmark[]);
} catch (err) {
setPossibleMatchingItems(null);
}
Expand Down
6 changes: 1 addition & 5 deletions src/components/CmdK/CmdK.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ export const CmdK = ({ serverDbMeta }: CmdKProps) => {
const [tweetItems, setTweetItems] = useState<Tweet[]>([]);
const [searchTerm, setSearchTerm] = useState('');
const dbMeta = serverDbMeta;
// useRealtimeDictionary<DbMetaResponse>({
// table: 'bookmarks',
// initialData: serverDbMeta,
// });

const handleSetGroupByDate = (newState: boolean) => {
if (profile?.settings_group_by_date !== newState) {
Expand All @@ -93,7 +89,7 @@ export const CmdK = ({ serverDbMeta }: CmdKProps) => {

const throttledMutate = throttle(async (value: string) => {
await fetchSearch(value).then((data) => {
setBookmarkItems(data?.bookmarksSearch?.data ?? []);
setBookmarkItems((data?.bookmarksSearch?.data as Bookmark[]) ?? []);
setTweetItems(data?.tweetsSearch?.data ?? []);
});
}, 500);
Expand Down
3 changes: 1 addition & 2 deletions src/components/CmdK/fetchSearch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use client';

import { Database } from '@/src/types/supabase';
import { createBrowserClient } from '@/src/utils/supabase/client';

export const fetchSearch = async (searchTerm: string) => {
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();
const bookmarksSearch = await supabaseClient
.from('bookmarks')
.select('*', { count: 'exact' })
Expand Down
3 changes: 1 addition & 2 deletions src/components/FeedItemActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import urlJoin from 'proper-url-join';

import { useClickBookmark } from '../hooks/useClickBookmark';
import { useToggle } from '../hooks/useToggle';
import { Database } from '../types/supabase';
import { createBrowserClient } from '../utils/supabase/client';
import { BookmarkFeedItemProps } from './BookmarkFeedItem';
import { BookmarkForm } from './BookmarkForm';
Expand All @@ -40,7 +39,7 @@ export const FeedItemActions = ({
allowDeletion,
isInFeed = true,
}: FeedItemActionsProps) => {
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();
const [isToggled, , setToggleState] = useToggle();
const router = useRouter();
const handleClickRegister = useClickBookmark();
Expand Down
5 changes: 2 additions & 3 deletions src/components/FeedItemFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import title from 'title';

import { useClickBookmark } from '../hooks/useClickBookmark';
import { Bookmark } from '../types/db';
import { Database } from '../types/supabase';
import { getRelativeDate } from '../utils/dates';
import { fullPath } from '../utils/fullPath';
import { simpleUrl } from '../utils/simpleUrl';
Expand All @@ -39,7 +38,7 @@ export interface FeedItemFooterProps extends Bookmark {
}

export const FeedItemFooter = (props: FeedItemFooterProps) => {
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();
const {
url,
tags,
Expand All @@ -65,7 +64,7 @@ export const FeedItemFooter = (props: FeedItemFooterProps) => {
.from('bookmarks')
.update({
star: !star,
modified_at: new Date(),
modified_at: new Date().toString(),
})
.match({ id });
};
Expand Down
3 changes: 1 addition & 2 deletions src/components/UpdateInfoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, { useState } from 'react';
import { useForm } from 'react-hook-form';

import { useToggle } from '../hooks/useToggle';
import { Database } from '../types/supabase';
import { getErrorMessage } from '../utils/get-error-message';
import { createBrowserClient } from '../utils/supabase/client';
import { FormGroup } from './FormGroup';
Expand All @@ -22,7 +21,7 @@ interface UpdateInfoProps {
}

export const UpdateInfoForm = ({ user }: UpdateInfoProps) => {
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();
const [formError, setFormError] = useState<string>('');
const [formSubmitting, , setFormSubmitting] = useToggle();
const {
Expand Down
5 changes: 2 additions & 3 deletions src/components/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ReactNode, createContext, useCallback, useContext } from 'react';

import { useRealtimeProfile } from '../hooks/useRealtime';
import { UserProfile } from '../types/db';
import { Database } from '../types/supabase';
import { createBrowserClient } from '../utils/supabase/client';

export type UseUpdateReturn = (action: UIStateAction) => void;
Expand Down Expand Up @@ -41,7 +40,7 @@ interface UserProviderProps extends Pick<UserContextType, 'profile' | 'id'> {

export const UserProvider = ({ children, id, profile }: UserProviderProps) => {
const realtimeProfile = useRealtimeProfile(profile);
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();

const handleUpdateUISettings = useCallback(
async (action: UIStateAction) => {
Expand All @@ -63,7 +62,7 @@ export const UserProvider = ({ children, id, profile }: UserProviderProps) => {
}
await supabaseClient
.from('profiles')
.update({ [column]: value, updated_at: new Date() })
.update({ [column]: value, updated_at: new Date().toString() })
.match({ id });
},
[id, realtimeProfile?.settings_pinned_tags, supabaseClient],
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/useClickBookmark.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use client';

import { Database } from '../types/supabase';
import { createBrowserClient } from '../utils/supabase/client';

export const useClickBookmark = () => {
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();

const handleClickRegister = async (id: string) => {
const selectItem = await supabaseClient
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/useRealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useEffect, useState } from 'react';

import { Bookmark, UserProfile } from '../types/db';
import { Database } from '../types/supabase';
import { createBrowserClient } from '../utils/supabase/client';
import { FeedItemModel } from './useGroupByDate';

Expand All @@ -21,7 +20,7 @@ export const useRealtimeFeed = ({
table = 'bookmarks',
}: RealtimeFeedProps) => {
const [items, setItems] = useState<FeedItemModel[]>(initialData);
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();

useEffect(() => {
setItems(initialData);
Expand Down Expand Up @@ -88,7 +87,7 @@ export const useRealtimeFeed = ({
*/
export const useRealtimeProfile = (initialData: UserProfile | null) => {
const [profile, setProfile] = useState<UserProfile | null>(initialData);
const supabaseClient = createBrowserClient<Database>();
const supabaseClient = createBrowserClient();

useEffect(() => {
setProfile(initialData);
Expand Down
5 changes: 3 additions & 2 deletions src/utils/supabase/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Database } from '@/src/types/supabase';
import { createBrowserClient as _createBrowserClient } from '@supabase/ssr';

export const createBrowserClient = <DB>() =>
_createBrowserClient<DB>(
export const createBrowserClient = () =>
_createBrowserClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
);

0 comments on commit 4e2282c

Please sign in to comment.