Skip to content

Commit

Permalink
fix: validate url
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed Jul 29, 2024
1 parent 7c62bdc commit 952a203
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 40 deletions.
37 changes: 33 additions & 4 deletions app/(app)/post/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@ import UserListItem from '../../../../src/components/uis/UserListItem';
import ControlItem from '../../../../src/components/uis/ControlItem';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Replies from '../../replies';
import {useCallback, useRef} from 'react';
import {useCallback, useRef, useEffect} from 'react';
import {FlashList} from '@shopify/flash-list';
import CustomPressable from 'dooboo-ui/uis/CustomPressable';
import {delayPressIn} from '../../../../src/utils/constants';
import {useRecoilState} from 'recoil';
import {authRecoilState} from '../../../../src/recoil/atoms';
import {useAppLogic} from '../../../../src/providers/AppLogicProvider';
import {fetchDeletePost, fetchPostById} from '../../../../src/apis/postQueries';
import {supabase} from '../../../../src/supabase';

const Container = styled.View`
background-color: ${({theme}) => theme.bg.basic};
flex: 1;
align-self: stretch;
`;

const Content = styled.View`
padding: 24px;
gap: 24px;
`;

Expand All @@ -49,9 +48,10 @@ export default function PostDetails(): JSX.Element {
data: post,
error,
isValidating,
mutate,
} = useSWR(id ? `post-${id}` : null, () => fetchPostById(id || ''));

console.log('post', id)
console.log('post', id);

const handleDeletePost = useCallback(async () => {
if (!post) return;
Expand Down Expand Up @@ -93,6 +93,35 @@ export default function PostDetails(): JSX.Element {
}
}, [post]);

useEffect(() => {
if (!id) return;

const channel = supabase
.channel('schema-db-changes')
.on(
'postgres_changes',
{
event: 'UPDATE',
schema: 'public',
table: 'posts',
filter: `id=eq.${id}`,
},
async (payload) => {
console.log('update', payload);
const updatedPost = await fetchPostById(id);

if (updatedPost) {
mutate(updatedPost, false); // Update the post data without revalidation
}
},
)
.subscribe();

return () => {
channel.unsubscribe();
};
}, [id, mutate]);

const content = (() => {
switch (true) {
case isValidating && !authId:
Expand Down
3 changes: 2 additions & 1 deletion app/(app)/post/[id]/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Content = styled.View`
const schema = yup.object().shape({
title: yup.string().required(t('post.write.titlePlaceholder')),
content: yup.string().required(t('post.write.contentPlaceholder')),
url: yup.string(),
url: yup.string().url(t('common.invalidUrl')),
});

type FormData = yup.InferType<typeof schema>;
Expand Down Expand Up @@ -189,6 +189,7 @@ export default function PostUpdate(): JSX.Element {
placeholder={t('post.write.urlPlaceholder')}
value={value}
decoration="boxed"
error={errors.url ? errors.url.message : ''}
/>
)}
rules={{required: true, validate: (value) => !!value}}
Expand Down
3 changes: 2 additions & 1 deletion app/(app)/post/write.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Content = styled.View`
const schema = yup.object().shape({
title: yup.string().required(t('post.write.titlePlaceholder')),
content: yup.string().required(t('post.write.contentPlaceholder')),
url: yup.string(),
url: yup.string().url(t('common.invalidUrl')),
});

type FormData = yup.InferType<typeof schema>;
Expand Down Expand Up @@ -179,6 +179,7 @@ export default function PostWrite(): JSX.Element {
placeholder={t('post.write.urlPlaceholder')}
value={value}
decoration="boxed"
error={errors.url ? errors.url.message : ''}
/>
)}
rules={{required: true, validate: (value) => !!value}}
Expand Down
35 changes: 18 additions & 17 deletions assets/langs/en.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
{
"common": {
"appErrorMessage": "Communication is not smooth.\nPlease check your network status.",
"ok": "OK",
"block": "Block",
"blockUser": "Block {{user}}",
"blockUserDesc": "If you block a user, you will not be able to access the user's content. Do you want to block this user?",
"blockUserSuccess": "User has been blocked",
"cancel": "Cancel",
"confirm": "Confirm",
"delete": "Delete",
"deleteSuccess": "Successfully deleted",
"deletedAccount": "Retired account.",
"image": "Image",
"invalidUrl": "Invalid URL",
"latest": "Latest",
"leaveComment": "Leave a comment",
"noComment": "No comments",
"notFound": "Not found",
"ok": "OK",
"or": "or",
"permissionGrantCamera": "Please grant camera permission to take pictures.",
"post": "Post",
"profile": "Profile",
"report": "Report",
"reportSubject": "Report {{subject}}",
"retry": "Retry",
"selectFromGallery": "Select from gallery",
"takeAPhoto": "Take a photo",
"unhandledError": "An unhandled error occurred.",
"update": "Update",
"updateApp": "Update App",
"user": "User",
"viewsWithCount": {
"one": "Views %{count}",
"other": "Views %{count}"
},
"reportSubject": "Report {{subject}}",
"report": "Report",
"block": "Block",
"blockUser": "Block {{user}}",
"blockUserDesc": "If you block a user, you will not be able to access the user's content. Do you want to block this user?",
"blockUserSuccess": "User has been blocked",
"delete": "Delete",
"user": "User",
"deleteSuccess": "Successfully deleted",
"unhandledError": "An unhandled error occurred.",
"update": "Update"
}
},
"error": {
"default": "Error occurred!"
Expand All @@ -47,6 +48,10 @@
"title": "Login Information"
},
"post": {
"update": {
"updateFailed": "Update failed!",
"updateSuccess": "Successfully updated!"
},
"write": {
"content": "Content",
"contentPlaceholder": "Enter the content",
Expand All @@ -58,10 +63,6 @@
"write": "Write",
"writeFailed": "Write failed!",
"writeSuccess": "Successfully written!"
},
"update": {
"updateFailed": "Update failed!",
"updateSuccess": "Successfully updated!"
}
},
"settings": {
Expand Down
35 changes: 18 additions & 17 deletions assets/langs/ko.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
{
"common": {
"appErrorMessage": "통신이 원활하지 않습니다.\n네트워크 상태를 확인해주세요.",
"block": "차단",
"blockUser": "{{user}} 차단",
"blockUserDesc": "사용자를 차단하면 해당 사용자의 콘텐츠에 접근할 수 없습니다. 이 사용자를 차단하시겠습니까?",
"blockUserSuccess": "사용자가 차단되었습니다",
"cancel": "취소",
"ok": "확인",
"confirm": "확인",
"delete": "삭제",
"deleteSuccess": "성공적으로 삭제되었습니다",
"deletedAccount": "탈퇴한 계정입니다.",
"image": "이미지",
"invalidUrl": "유효하지 않은 URL",
"latest": "최신순",
"leaveComment": "댓글 남기기",
"noComment": "댓글이 없습니다",
"notFound": "찾을 수 없습니다",
"ok": "확인",
"or": "또는",
"permissionGrantCamera": "촬영을 위해 카메라 권한을 부여해주세요.",
"post": "게시판",
"profile": "프로필",
"report": "신고",
"reportSubject": "Report {{subject}}",
"retry": "재시도",
"selectFromGallery": "갤러리에서 선택",
"takeAPhoto": "사진 찍기",
"unhandledError": "처리되지 않은 오류가 발생했습니다.",
"update": "업데이트",
"updateApp": "앱 업데이트",
"user": "사용자",
"viewsWithCount": {
"one": "조회수 %{count}",
"other": "조회수 %{count}"
},
"reportSubject": "Report {{subject}}",
"report": "신고",
"block": "차단",
"blockUser": "{{user}} 차단",
"blockUserDesc": "사용자를 차단하면 해당 사용자의 콘텐츠에 접근할 수 없습니다. 이 사용자를 차단하시겠습니까?",
"blockUserSuccess": "사용자가 차단되었습니다",
"delete": "삭제",
"user": "사용자",
"deleteSuccess": "성공적으로 삭제되었습니다",
"unhandledError": "처리되지 않은 오류가 발생했습니다.",
"update": "업데이트"
}
},
"error": {
"default": "오류가 발생했습니다!"
Expand All @@ -47,6 +48,10 @@
"title": "로그인 정보"
},
"post": {
"update": {
"updateFailed": "업데이트에 실패했습니다!",
"updateSuccess": "성공적으로 업데이트되었습니다!"
},
"write": {
"content": "내용",
"contentPlaceholder": "내용을 입력하세요",
Expand All @@ -58,10 +63,6 @@
"write": "글쓰기",
"writeFailed": "작성에 실패했습니다!",
"writeSuccess": "성공적으로 작성되었습니다!"
},
"update": {
"updateFailed": "업데이트에 실패했습니다!",
"updateSuccess": "성공적으로 업데이트되었습니다!"
}
},
"settings": {
Expand Down

0 comments on commit 952a203

Please sign in to comment.