Skip to content

Commit

Permalink
Add like login error
Browse files Browse the repository at this point in the history
  • Loading branch information
cau777 committed Sep 23, 2022
1 parent 00cfff6 commit 851e115
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions client/components/home/SnippetPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {mergeClasses} from "../../src/attributes";
import SnippetComments from "./SnippetComments";
import {useRouter} from "next/router";
import {formatPostTime} from "../../src/i18n";
import {useTranslation} from "next-i18next";

type Props = Snippet & { limitHeight?: boolean, compact?: boolean };

Expand All @@ -29,7 +30,8 @@ const SnippetPost: FC<Props> = (props) => {
const [likeState, setLikeState] = useState<LikeState>();
const [error, setError] = useState<string>();
const context = useContext(AuthContext);
let router = useRouter();
const router = useRouter();
const {t} = useTranslation();

const date = formatPostTime(props.created_at, router.locale!);

Expand Down Expand Up @@ -65,7 +67,10 @@ const SnippetPost: FC<Props> = (props) => {
useAsyncEffect(updateLikeState, [context.loggedIn]);

async function like() {
if (!likeState || !context.loggedIn) return; // TODO: logged tooltip
if (!likeState || !context.loggedIn){
setError(t("errorLikeLogin"));
return;
}
if (likeState.hasLiked) {
let result = await fromTable(supabase, "Likes")
.delete()
Expand Down
1 change: 0 additions & 1 deletion client/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import AssertProfileComplete from "../components/AssertProfileComplete";
import {appWithTranslation, useTranslation} from "next-i18next";

// TODO: PWA
//TODO: change auth deploy
function MyApp({Component, pageProps}: AppProps) {
const {t} = useTranslation();

Expand Down
1 change: 1 addition & 0 deletions client/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"errorUsernameCharset": "Username can't have special characters",
"errorPostNotFound": "This post could not be found",
"errorInvalidSearch": "Invalid search",
"errorLikeLogin": "You must log in to like posts",

"altRandomAvatar": "Randomly generated robot avatar",
"profileImageUpdateSoon": "Your profile image will be updated soon",
Expand Down
1 change: 1 addition & 0 deletions client/public/locales/pt-BR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"errorUsernameCharset": "O nome de usuário não pode conter caracteres especiais",
"errorPostNotFound": "Essa publicação não pôde ser encontrada",
"errorInvalidSearch": "Pesquisa inválida",
"errorLikeLogin": "Você deve entrar para curtir publicações",

"altRandomAvatar": "Avatar de robô gerado aleatoriamente",
"profileImageUpdateSoon": "Sua foto de perfil será atualizada em breve",
Expand Down

0 comments on commit 851e115

Please sign in to comment.