diff --git a/compiled-lang/en.json b/compiled-lang/en.json index b3affcc..509a2d5 100644 --- a/compiled-lang/en.json +++ b/compiled-lang/en.json @@ -1,12 +1,19 @@ { "078WAr": "See all", + "0iB3Cs": "Transaction added", "5ARyR8": "Personal Finance", "7vsu1w": "Sign in with Facebook", - "CHu6Xm": "Total Spend (month)", + "CG3a47": "All transactions", + "D3idYv": "Settings", "GMkXVd": "Recent Transactions", + "GZJpDf": "Analytics", + "LgAx49": "Category added", + "MTfefh": "No transactions", "Op5EHr": "Sign in with Google", "URe+qA": "Expense", - "a9m3iY": "{amount} $", - "bQAtuf": "Loading...", - "gJkHZk": "Income" + "VKb1MS": "Categories", + "dXSivY": "My account", + "gJkHZk": "Income", + "lbpe3v": "Signed out", + "xXbJso": "Sign out" } \ No newline at end of file diff --git a/lang/en.json b/lang/en.json index 6ae1c1b..64b5383 100644 --- a/lang/en.json +++ b/lang/en.json @@ -2,6 +2,9 @@ "078WAr": { "defaultMessage": "See all" }, + "0iB3Cs": { + "defaultMessage": "Transaction added" + }, "5ARyR8": { "defaultMessage": "Personal Finance", "description": "signin tag-line" @@ -9,28 +12,43 @@ "7vsu1w": { "defaultMessage": "Sign in with Facebook" }, - "CHu6Xm": { - "defaultMessage": "Total Spend (month)", - "description": "TotalSpendCard title" + "CG3a47": { + "defaultMessage": "All transactions" + }, + "D3idYv": { + "defaultMessage": "Settings" }, "GMkXVd": { "defaultMessage": "Recent Transactions" }, + "GZJpDf": { + "defaultMessage": "Analytics" + }, + "LgAx49": { + "defaultMessage": "Category added" + }, + "MTfefh": { + "defaultMessage": "No transactions" + }, "Op5EHr": { "defaultMessage": "Sign in with Google" }, "URe+qA": { "defaultMessage": "Expense" }, - "a9m3iY": { - "defaultMessage": "{amount} $", - "description": "monetary amount readout" + "VKb1MS": { + "defaultMessage": "Categories" }, - "bQAtuf": { - "defaultMessage": "Loading...", - "description": "default loading" + "dXSivY": { + "defaultMessage": "My account" }, "gJkHZk": { "defaultMessage": "Income" + }, + "lbpe3v": { + "defaultMessage": "Signed out" + }, + "xXbJso": { + "defaultMessage": "Sign out" } } diff --git a/lib/apolloClient.js b/lib/apolloClient.js index 542c5a8..472d7d4 100644 --- a/lib/apolloClient.js +++ b/lib/apolloClient.js @@ -15,6 +15,7 @@ const httpLink = new HttpLink({ }); function createApolloClient(token) { + console.log("token", token); return new ApolloClient({ connectToDevTools: true, ssrMode: typeof window === "undefined", @@ -83,6 +84,7 @@ export function addApolloState(client, pageProps) { export function useApollo(pageProps, firebaseAuth) { const state = pageProps[APOLLO_STATE_PROP_NAME]; const [token, setToken] = useState(undefined); + console.log(firebaseAuth); useEffect(() => { auth(); diff --git a/pages/_app.tsx b/pages/_app.tsx index c81a770..ce6c1f8 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -4,7 +4,7 @@ import type { AppProps } from "next/app"; import React, { useState, useEffect } from "react"; import Head from "next/head"; import { useRouter } from "next/router"; -import { Toaster } from "react-hot-toast"; +import toast, { Toaster } from "react-hot-toast"; import { IntlProvider } from "react-intl"; import { ApolloProvider, gql } from "@apollo/client"; import { useApollo } from "lib/apolloClient"; @@ -39,11 +39,27 @@ function CustomApp({ Component, pageProps }: AppProps) { // TODO: Clean this up onAuthStateChanged(auth, (user: any) => { + if (user) { + setUser(user); + } else { + setUser(null); + } + setLoading(false); + + // Redirect if not loged in + if (!user && pathname !== "/signin") { + replace("/signin"); + } + }); + }, []); + + useEffect(() => { + if (!loading) { if (user) { apolloClient .query({ query: GET_USER, - variables: { filter: { firebaseID: { eq: user?.uid } } }, + variables: { filter: { firebaseId: { eq: user?.uid } } }, }) .then((firebaseUser: any) => { // Make sure we have a user @@ -61,11 +77,11 @@ function CustomApp({ Component, pageProps }: AppProps) { .mutate({ mutation: ADD_USER, variables: { - input: [{ firebaseID: user.uid }], + input: [{ firebaseId: user.uid }], }, }) .then((addUser: any) => { - console.log("linked firebase user to zef user"); + console.log("linked firebase user to zef user", addUser); setUser({ ...user, id: addUser.data.addUser.user[0].id, @@ -73,18 +89,16 @@ function CustomApp({ Component, pageProps }: AppProps) { setLoading(false); }); } + }) + .catch((err: any) => { + console.error(err); + toast.error(err.message); }); - } else { - setUser(null); - setLoading(false); } + } + }, [loading, user]); - // Redirect if not loged in - if (!user && pathname !== "/signin") { - replace("/signin"); - } - }); - }, []); + console.log("loading", loading); return ( { icon: values.icon, created: new Date(), user: { - firebaseID: user?.id, + id: user?.id, }, }, ], diff --git a/server/Dockerfile b/server/Dockerfile index b44ca6d..8a9cb58 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -40,9 +40,13 @@ RUN git config --global --add credential.helper 'store --file=/run/secrets/gitcr && git config --global url."https://github.com/".insteadOf git@github.com: COPY get_zefdb.sh . -ADD backend . +ADD ikura.graphql . -RUN --mount=type=secret,id=gitcredentials bash get_zefdb.sh zef v0.15.2-rc6 'zef-.*cp310' +RUN --mount=type=secret,id=gitcredentials bash get_zefdb.sh zef v0.15.3-dev2 'zef-.*cp310' + +# pip install stuff +ADD requirements.txt . +RUN pip3 install --no-cache-dir -r requirements.txt EXPOSE 5001 diff --git a/server/get_zefdb.sh b/server/get_zefdb.sh new file mode 100644 index 0000000..96be9d6 --- /dev/null +++ b/server/get_zefdb.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Black magic to extract access token and then get asset id from github +# Steps: +# 1. Get GH_ACCESS_TOKEN from the secret passed in as the gitcredentials (this is not stored past this RUN command) +# 2. Scrap the github release to find the asset with "zefdb-" and "cp38" in its name (i.e. with julia and python 3.8). +# 3. Grab the file itself + +if [ "$#" -ne 3 ] ; then + echo "Need three arguments, the repo, the tag and the asset filter, zefDB v0.12.26 e.g. zefdb-.*cp38" + exit 1 +fi + +REPO="$1" +ZEFDB_TAG="$2" +ASSET_FILTER="$3" + +set -o pipefail +GH_ACCESS_TOKEN=$(cat /run/secrets/gitcredentials | sed -e 's_^https://.*:\(.*\)@.*$_\1_') || exit 1 + +DETAILS="$(curl "https://${GH_ACCESS_TOKEN}:@api.github.com/repos/zefhub/$REPO/releases/tags/$ZEFDB_TAG" | jq ".assets | map(select(.name | test(\"$ASSET_FILTER\")))[0]")" || exit 1 +ASSET_ID=$(echo $DETAILS | jq ".id") || exit 1 +FILENAME=$(echo $DETAILS | jq ".name" | tr -d \") || exit 1 + +curl -L -o $FILENAME -H 'Accept: application/octet-stream' "https://${GH_ACCESS_TOKEN}:@api.github.com/repos/zefhub/$REPO/releases/assets/${ASSET_ID}" || exit 1 + +if [[ "$FILENAME" == "null" ]] ; then + exit 1 +fi +pip3 install --no-cache-dir $FILENAME diff --git a/server/requirements.txt b/server/requirements.txt new file mode 100644 index 0000000..6c36329 --- /dev/null +++ b/server/requirements.txt @@ -0,0 +1 @@ +requests>=2.27.1