Skip to content

Commit

Permalink
Merge pull request #716 from the-clothing-loop/merge-1
Browse files Browse the repository at this point in the history
Merge vps2 setup to chat
  • Loading branch information
lil5 authored Apr 29, 2024
2 parents 898b0db + 0ae53dd commit 50b62c8
Show file tree
Hide file tree
Showing 68 changed files with 591 additions and 106 deletions.
21 changes: 9 additions & 12 deletions .github/workflows/deploy-acceptance-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,18 @@ jobs:
- name: Build binary
run: make build-server
working-directory: ./server
- name: Rename binary
run: mv server cl-api-acceptance
working-directory: ./server
- name: Install SSH key
uses: benoitchantre/setup-ssh-authentication-action@1.0.1
with:
private-key: ${{ secrets.VPS1_PRIVKEY }}
known-hosts: ${{ secrets.VPS1_KNOWNHOSTS }}
private-key: ${{ secrets.VPS2_PRIVKEY }}
private-key-name: id_ed25519
known-hosts: ${{ secrets.VPS2_KNOWNHOSTS }}
- name: Send binary to vps and restart service
run: |
rsync -az --delete ./server/cl-api-acceptance admin@vpsnode1.vps.webdock.cloud:/home/admin/
ssh admin@vpsnode1.vps.webdock.cloud "\
sudo rm /home/clothingloop/opt/api-acceptance; \
sudo cp /home/admin/cl-api-acceptance /home/clothingloop/opt/api-acceptance; \
sudo chown root:root /home/clothingloop/opt/api-acceptance; \
sudo chmod 0775 /home/clothingloop/opt/api-acceptance; \
sudo systemctl restart cl-api-acceptance"
rsync -az --delete ./server/server admin@vps2.vps.webdock.cloud:/home/admin/acc.api.clothingloop.org/server.next
ssh admin@vps2.vps.webdock.cloud "\
task-services stop my_api_acc; \
sudo mv /home/admin/acc.api.clothingloop.org/server.next /home/admin/acc.api.clothingloop.org/server; \
sudo chmod +x /home/admin/acc.api.clothingloop.org/server; \
task-services start my_api_acc;"
echo "done"
12 changes: 6 additions & 6 deletions .github/workflows/deploy-acceptance-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ jobs:
- name: Install SSH key
uses: benoitchantre/setup-ssh-authentication-action@1.0.1
with:
private-key: ${{ secrets.VPS1_PRIVKEY }}
known-hosts: ${{ secrets.VPS1_KNOWNHOSTS }}
private-key: ${{ secrets.VPS2_PRIVKEY }}
private-key-name: id_ed25519
known-hosts: ${{ secrets.VPS2_KNOWNHOSTS }}
- name: Send public files to vps
run: |
ssh admin@vpsnode1.vps.webdock.cloud "mkdir -p /home/admin/cl-app-acceptance"
rsync -az --delete ./app/build/ admin@vpsnode1.vps.webdock.cloud:/home/admin/cl-app-acceptance/
ssh admin@vpsnode1.vps.webdock.cloud "\
sudo rsync -z -rlt --chown=caddy:caddy --chmod=0775 --delete /home/admin/cl-app-acceptance/ /var/caddy/acc.app.clothingloop.org/; \
rsync -az --delete ./app/build/ admin@vps2.vps.webdock.cloud:/home/admin/acc.app.clothingloop.org/
ssh admin@vps2.vps.webdock.cloud "\
sudo chmod -R 0775 /home/admin/acc.app.clothingloop.org/; \
sudo systemctl reload caddy"
echo "done"
12 changes: 6 additions & 6 deletions .github/workflows/deploy-acceptance-fe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ jobs:
- name: Install SSH key
uses: benoitchantre/setup-ssh-authentication-action@1.0.1
with:
private-key: ${{ secrets.VPS1_PRIVKEY }}
known-hosts: ${{ secrets.VPS1_KNOWNHOSTS }}
private-key: ${{ secrets.VPS2_PRIVKEY }}
private-key-name: id_ed25519
known-hosts: ${{ secrets.VPS2_KNOWNHOSTS }}
- name: Send public files to vps
run: |
ssh admin@vpsnode1.vps.webdock.cloud "mkdir -p /home/admin/cl-fe-acceptance"
rsync -az --delete ./frontend/build/ admin@vpsnode1.vps.webdock.cloud:/home/admin/cl-fe-acceptance/
ssh admin@vpsnode1.vps.webdock.cloud "\
sudo rsync -z -rlt --chown=caddy:caddy --chmod=0775 --delete /home/admin/cl-fe-acceptance/ /var/caddy/acc.clothingloop.org/; \
rsync -az --delete ./frontend/build/ admin@vps2.vps.webdock.cloud:/home/admin/acc.clothingloop.org/
ssh admin@vps2.vps.webdock.cloud "\
sudo chmod -R 0775 /home/admin/acc.clothingloop.org/; \
sudo systemctl reload caddy"
echo "done"
6 changes: 5 additions & 1 deletion app/src/components/AddressList/AddressListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface AddressListItemProps {
number: number;
routerLink: string | undefined;
isUserPaused: boolean;
isChainAdmin: boolean;
}
export default function AddressListItem({
user,
Expand All @@ -23,6 +24,7 @@ export default function AddressListItem({
number,
routerLink,
isUserPaused,
isChainAdmin,
}: AddressListItemProps) {
return (
<IonItem
Expand All @@ -48,7 +50,9 @@ export default function AddressListItem({
</h5>
<span className="tw-opacity-60">
{isUserPaused ? (
<small>{t("paused")}</small>
isChainAdmin ? (
<small>{user.address}</small>
) : null
) : isAddressPrivate ? (
<small>&nbsp;</small>
) : (
Expand Down
25 changes: 20 additions & 5 deletions app/src/components/Bags/SelectUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import {
IonSearchbar,
IonRadioGroup,
IonRadio,
IonIcon,
} from "@ionic/react";
import { RefObject, useContext, useState, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { bagPut } from "../../api/bag";
import { UID } from "../../api/types";
import { StoreContext } from "../../stores/Store";
import IsPaused from "../../utils/is_paused";
import { pauseCircleSharp } from "ionicons/icons";

const MIN_USERS_FOR_SEARCH = 15;

Expand All @@ -40,7 +43,7 @@ export default function SelectUserModal({
modal: RefObject<HTMLIonModalElement>;
didDismiss?: (e: IonModalCustomEvent<OverlayEventDetail<any>>) => void;
}) {
const { chain, chainUsers, route, authUser, setChain } =
const { chain, chainUsers, route, authUser, setChain, isChainAdmin } =
useContext(StoreContext);
const { t, i18n } = useTranslation();

Expand Down Expand Up @@ -166,11 +169,23 @@ export default function SelectUserModal({

const isSelected = selected === user.uid;
const isMe = user.uid === authUser?.uid;
const isPaused = IsPaused(user, chain?.uid);
return (
<IonItem lines="full" key={user.uid}>
<span slot="start" className="!tw-font-bold">{`#${
i + 1
}`}</span>
<IonItem
disabled={isPaused && !isChainAdmin}
lines="full"
key={user.uid}
>
<div slot="start" className="tw-flex tw-items-center">
{isPaused ? (
<IonIcon
icon={pauseCircleSharp}
className="tw-w-6 tw-h-6"
/>
) : (
<span className="!tw-font-bold">{`#${i + 1}`}</span>
)}
</div>
<IonLabel>
<h2
className={`tw-text-lg ${isMe ? "tw-text-primary" : ""} ${
Expand Down
7 changes: 4 additions & 3 deletions app/src/components/Bags/UserLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { User } from "../../api/types";
interface Props {
user: User;
routeIndex: number;
isPaused: boolean;
}

export default function UserLink({ user, routeIndex }: Props) {
export default function UserLink({ user, routeIndex, isPaused }: Props) {
return (
<div className="!tw-font-bold tw-text-medium tw-flex tw-flex-row tw-items-baseline tw-text-xs tw-w-full">
{user.paused_until ? (
{isPaused ? (
<IonIcon
className="tw-translate-y-px tw-w-4 tw-h-4 tw-min-w-[16px] tw-me-[3px]"
icon={pauseCircle}
Expand All @@ -20,7 +21,7 @@ export default function UserLink({ user, routeIndex }: Props) {
)}
<span
className={`ion-text-ellipsis tw-text-sm tw-flex-grow tw-block ${
user.paused_until ? "tw-text-medium" : "tw-text-dark"
isPaused ? "tw-text-medium" : "tw-text-dark"
}`}
>
{user.name}
Expand Down
1 change: 1 addition & 0 deletions app/src/components/Settings/RoutePrivacyExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default function RoutePrivacyExample(props: {
isUserPaused={user.paused_until !== null}
number={i + 5}
routerLink={undefined}
isChainAdmin={true}
/>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions app/src/pages/AddressItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useContext, useMemo } from "react";
import { RouteComponentProps } from "react-router";
import UserCard from "../components/UserCard";
import { StoreContext } from "../stores/Store";
import isPaused from "../utils/is_paused";
import IsPaused from "../utils/is_paused";
import { t } from "i18next";
import Badges from "../components/SizeBadge";
import AddressBagCard from "../components/Bags/AddressBagCard";
Expand All @@ -29,7 +29,7 @@ export default function AddressItem({
let userUID = match.params.uid;
return chainUsers.find((u) => u.uid === userUID) || null;
}, [match.params.uid, chainUsers]);
const isUserPaused = isPaused(user, chain?.uid);
const isUserPaused = IsPaused(user, chain?.uid);

const userBags = useMemo(() => {
return bags.filter((b) => b.user_uid === user?.uid);
Expand Down
5 changes: 3 additions & 2 deletions app/src/pages/AddressList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import AddressListItem, {
} from "../components/AddressList/AddressListItem";
import wrapIndex from "../utils/wrap_index";
import { useDebounce } from "@uidotdev/usehooks";
import isPaused from "../utils/is_paused";
import IsPaused from "../utils/is_paused";

export default function AddressList() {
const {
Expand Down Expand Up @@ -102,7 +102,7 @@ export default function AddressList() {

const isPrivate = IsPrivate(user.email);
const isAddressPrivate = IsPrivate(user.address);
const isUserPaused = isPaused(user, chain.uid);
const isUserPaused = IsPaused(user, chain.uid);

arr.push({
user,
Expand All @@ -113,6 +113,7 @@ export default function AddressList() {
number: i + 1,
isUserPaused,
routerLink: isPrivate ? undefined : "/address/" + user.uid,
isChainAdmin,
});
}

Expand Down
15 changes: 13 additions & 2 deletions app/src/pages/BagsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import UserLink from "../components/Bags/UserLink";
import SelectUserModal from "../components/Bags/SelectUserModal";
import { useDebounce } from "@uidotdev/usehooks";
import dayjs from "../dayjs";
import IsPaused from "../utils/is_paused";

type State = { bag_id?: number } | undefined;

Expand Down Expand Up @@ -408,6 +409,7 @@ export default function BagsList() {
{bagsCard.map((bag) => {
const user = chainUsers.find((u) => u.uid === bag.user_uid);
if (!user) return null;
const isPaused = IsPaused(user, chain?.uid);
let routeIndex = route.indexOf(user.uid);
if (routeIndex === -1) return null;
const { bagUpdatedAt, isBagTooOldMe, isBagTooOldHost } =
Expand Down Expand Up @@ -458,7 +460,11 @@ export default function BagsList() {
routerLink={"/address/" + user.uid}
className="tw-py-3 tw-px-2 tw-block tw-bg-light"
>
<UserLink user={user} routeIndex={routeIndex} />
<UserLink
user={user}
routeIndex={routeIndex}
isPaused={isPaused}
/>
</IonRouterLink>
</Card>
</IonCol>
Expand All @@ -472,6 +478,7 @@ export default function BagsList() {
const { bagUpdatedAt, isBagTooOldMe, isBagTooOldHost } =
useBagTooOld(authUser, isChainAdmin, bag);
let isOpen = openCard == bag.id;
const isPaused = IsPaused(user, chain?.uid);
return (
<IonCol
size="12"
Expand Down Expand Up @@ -536,7 +543,11 @@ export default function BagsList() {
routerLink={"/address/" + user.uid}
className="tw-w-[115px] tw-h-[35px]"
>
<UserLink user={user} routeIndex={routeIndex} />
<UserLink
user={user}
routeIndex={routeIndex}
isPaused={isPaused}
/>
</IonButton>
)}
{isChainAdmin ? (
Expand Down
13 changes: 9 additions & 4 deletions app/src/pages/HelpItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
IonButtons,
IonIcon,
} from "@ionic/react";
import { useContext, useMemo } from "react";
import { Fragment, useContext, useMemo } from "react";
import { useTranslation } from "react-i18next";
import type { TOptionsBase } from "i18next";
import { RouteComponentProps } from "react-router";
Expand Down Expand Up @@ -84,9 +84,14 @@ export default function HelpItem({
>
{item.title}
</h1>
{item.content.split("\n").map((s, i) => (
<p key={i}>{s}</p>
))}
<p>
{item.content.split("\n").map((s, i) => (
<Fragment key={i}>
{s === "" ? null : <span>{s}</span>}
<br />
</Fragment>
))}
</p>
</IonText>
<IonIcon
aria-hidden="true"
Expand Down
12 changes: 10 additions & 2 deletions app/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
import {
arrowBack,
arrowForwardOutline,
mailOutline,
mailUnreadOutline,
sendOutline,
} from "ionicons/icons";
import { Fragment, useContext, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
Expand All @@ -29,6 +29,8 @@ import { loginEmail } from "../api/login";
import { StoreContext } from "../stores/Store";
import { AppLauncher } from "@capacitor/app-launcher";

const VERSION = import.meta.env.VITE_APP_VERSION;

enum State {
idle,
error,
Expand Down Expand Up @@ -211,7 +213,7 @@ export default function Login(props: { isLoggedIn: boolean }) {
{sentState === State.success ? (
<IonIcon slot="end" icon={mailUnreadOutline} />
) : sentState === State.loading ? null : (
<IonIcon slot="end" icon={sendOutline} />
<IonIcon slot="end" icon={mailOutline} />
)}
</IonButton>
</IonItem>
Expand Down Expand Up @@ -260,6 +262,12 @@ export default function Login(props: { isLoggedIn: boolean }) {
</IonItem>
</Fragment>
) : null}
<div
className="tw-text-center tw-mt-2 -tw-mb-4 tw-text-medium"
key="version"
>
{VERSION}
</div>
</div>
<div className="tw-relative tw-flex-grow -tw-m-4 tw-mt-8 tw-inset-0 -tw-z-10 tw-bg-green tw-overflow-hidden">
<div className="tw-absolute tw-overflow-hidden tw-inset-0 -tw-z-10">
Expand Down
4 changes: 2 additions & 2 deletions app/src/pages/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
warningOutline,
} from "ionicons/icons";
import dayjs from "../dayjs";
import isPaused from "../utils/is_paused";
import IsPaused from "../utils/is_paused";
import Badges from "../components/SizeBadge";
import { Share } from "@capacitor/share";
import { Clipboard } from "@capacitor/clipboard";
Expand Down Expand Up @@ -201,7 +201,7 @@ export default function Settings() {
Share.share({ url });
}

let isUserPaused = isPaused(authUser, chain?.uid);
let isUserPaused = IsPaused(authUser, chain?.uid);
let pausedDayjs = isUserPaused ? dayjs(authUser!.paused_until) : null;
let showExpandButton = (chain?.description.length || 0) > 200;
let emptyDescription = (chain?.description.length || 0) == 0;
Expand Down
6 changes: 3 additions & 3 deletions app/src/utils/is_paused.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, test } from "vitest";
import isPaused from "./is_paused";
import IsPaused from "./is_paused";
import dayjs from "../dayjs";

function TestIsPausedByDate(date: string | null) {
return isPaused({ chains: [], paused_until: date } as any, "");
return IsPaused({ chains: [], paused_until: date } as any, "");
}

test("should is pause be a date in the past then return true", () => {
Expand All @@ -24,7 +24,7 @@ test("should is pause be null then return false", () => {

test("should be paused when the current user chain is paused", () => {
expect(
isPaused(
IsPaused(
{ chains: [{ chain_uid: "test", is_paused: true }] } as any,
"test",
),
Expand Down
2 changes: 1 addition & 1 deletion app/src/utils/is_paused.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UID, User } from "../api/types";
import dayjs from "../dayjs";

export default function isPaused(
export default function IsPaused(
user: User | null,
currentChainUID: UID | undefined,
): boolean {
Expand Down
Loading

0 comments on commit 50b62c8

Please sign in to comment.