Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kind based nostr permissions #3054

Merged
merged 45 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b4f3a58
feat: initia nostr permission suffix
pavanjoshi914 Feb 20, 2024
594778c
feat: implement multiple permission options
pavanjoshi914 Feb 21, 2024
796d5fe
Merge remote-tracking branch 'upstream/master' into nostr-permissions…
pavanjoshi914 Mar 1, 2024
86912ac
feat: permission popup model
pavanjoshi914 Mar 1, 2024
3063c51
Merge remote-tracking branch 'upstream/master' into nostr-permissions…
pavanjoshi914 Mar 6, 2024
3c0372c
refactor: permissiom modal
pavanjoshi914 Mar 6, 2024
f731a70
fix: logic + modal designs
pavanjoshi914 Mar 7, 2024
b980e0e
fix: permissionOption Types
pavanjoshi914 Mar 12, 2024
0525865
feat: deletable badge permissions
pavanjoshi914 Mar 13, 2024
8ad7122
Merge remote-tracking branch 'upstream/master' into nostr-permissions…
pavanjoshi914 Mar 13, 2024
d1d6431
feat: prevent default form submission
pavanjoshi914 Mar 14, 2024
0072452
fix: radio button styles
pavanjoshi914 Mar 14, 2024
67ccfc8
feat: update permission representation
pavanjoshi914 Mar 14, 2024
1db82c6
Merge remote-tracking branch 'upstream/master' into nostr-permissions…
pavanjoshi914 Mar 15, 2024
7859d86
fix: tests, badge icon, translation keys
pavanjoshi914 Mar 15, 2024
6821bc2
feat: designs for site preferences
pavanjoshi914 Mar 15, 2024
98dc5aa
fix: translations
pavanjoshi914 Mar 15, 2024
82844ed
feat: add margin
pavanjoshi914 Mar 15, 2024
700c12c
feat: update nostr permissions title
pavanjoshi914 Mar 15, 2024
5de696c
feat: correct default values of unknown kinds
pavanjoshi914 Mar 18, 2024
bb64bcf
chore: lowercase props
pavanjoshi914 Mar 19, 2024
59f5a77
feat: make badge component generic
pavanjoshi914 Mar 19, 2024
a25feeb
fix: make labels clickable
pavanjoshi914 Mar 19, 2024
cf86e60
fix: badges, publisher cards
pavanjoshi914 Mar 19, 2024
d83879a
chore: lowercase the translations
pavanjoshi914 Mar 19, 2024
0b0b7cb
feat: extract permissions strings into constants
pavanjoshi914 Mar 19, 2024
595d6ce
Merge branch 'master' into nostr-permissions-suffix
reneaaron Mar 19, 2024
ea5780c
Merge branch 'master' into nostr-permissions-suffix
reneaaron Mar 19, 2024
3204ddc
fix: radio buttons in dark mode
pavanjoshi914 Mar 20, 2024
e868667
feat: simplify permissions references
pavanjoshi914 Mar 20, 2024
3f35d89
fix: layout & translations
reneaaron Mar 20, 2024
2353b9c
Merge branch 'master' into nostr-permissions-suffix
reneaaron Mar 20, 2024
f67d6e1
feat: typsafe code
pavanjoshi914 Mar 20, 2024
06424ae
fix: remove badge hiding
reneaaron Mar 20, 2024
d04f63e
fix: simplify lang key construction
reneaaron Mar 20, 2024
c5e1cf0
fix: encrypt decrypt translations
pavanjoshi914 Mar 21, 2024
187d997
fix: simplify translation keys
reneaaron Mar 21, 2024
acb7fdc
fix: translations
reneaaron Mar 21, 2024
c611501
fix: remove debugging
reneaaron Mar 21, 2024
87f8418
fix: translations
reneaaron Mar 21, 2024
bc66f48
fix: revert splitting
reneaaron Mar 21, 2024
fedf461
fix: add margin
reneaaron Mar 21, 2024
edd2a67
fix: add check for existing permissions
reneaaron Mar 21, 2024
71bfe31
fix: strict equal
reneaaron Mar 21, 2024
7a5106b
fix: translations
reneaaron Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions src/app/components/Badge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
import { useTranslation } from "react-i18next";
import { PopiconsXLine } from "@popicons/react";
import { classNames } from "~/app/utils";

type Props = {
label: "budget" | "auth" | "imported";
label: string;
className: string;
onDelete?: () => void;
description?: string;
};

export default function Badge({ label, className }: Props) {
const { t: tComponents } = useTranslation("components", {
keyPrefix: "badge",
});

export default function Badge({
label,
className,
onDelete,
description,
}: Props) {
return (
<span
<div
className={classNames(
"inline-block leading-none rounded-full font-medium mr-2 py-1 px-2 text-xs",
"inline-flex items-center leading-none rounded-full font-medium mr-2 py-1 pr-2 pl-3 mb-2 text-xs cursor-default",
className
)}
title={description}
>
{tComponents(`label.${label}`)}
</span>
{label.toUpperCase()}
{onDelete && (
<button
type="button"
onClick={() => {
onDelete();
}}
className="text-gray-400 dark:text-neutral-600 hover:text-gray-600 dark:hover:text-neutral-400"
>
<PopiconsXLine className="w-4 h-4" />
</button>
)}
</div>
);
}
12 changes: 11 additions & 1 deletion src/app/components/BadgesList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import Badge from "@components/Badge";
import { useTranslation } from "react-i18next";
import type { Allowance, Badge as BadgeType } from "~/types";

type Props = {
allowance: Allowance;
};

export default function BadgesList({ allowance }: Props) {
const { t: tComponents } = useTranslation("components", {
keyPrefix: "badge",
});
const badges: BadgeType[] = [];
if (allowance.remainingBudget > 0) {
badges.push({
Expand All @@ -23,7 +27,13 @@ export default function BadgesList({ allowance }: Props) {
return (
<>
{badges?.map((b) => {
return <Badge key={b.label} label={b.label} className={b.className} />;
return (
<Badge
key={b.label}
label={tComponents(`label.${b.label}`)}
className={b.className}
/>
);
})}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function Modal({
style={{ content: { maxHeight: "80vh" } }}
>
{title && (
<h2 className="text-2xl font-bold dark:text-white mb-6">{title}</h2>
<h2 className="text-2xl font-bold dark:text-white pb-5">{title}</h2>
)}
<button
onClick={closeModal}
Expand Down
114 changes: 114 additions & 0 deletions src/app/components/PermissionModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import Button from "~/app/components/Button";
import Modal from "~/app/components/Modal";
import PublisherCard from "~/app/components/PublisherCard";
import { useNavigationState } from "~/app/hooks/useNavigationState";
import { classNames } from "~/app/utils";

import { OriginData, PermissionOption } from "~/types";

type Props = {
onClose: () => void;
isOpen: boolean;
permissionCallback: (permission: PermissionOption) => void;
permission: PermissionOption;
};

export default function PermissionModal({
isOpen,
onClose,
permissionCallback,
permission,
}: Props) {
const { t: tCommon } = useTranslation("common");

const { t } = useTranslation("components", {
keyPrefix: "permissions_modal",
});

const navState = useNavigationState();
const [permissionOption, setPermissionOption] = useState(
PermissionOption.ASK_EVERYTIME
);
const origin = navState.origin as OriginData;

return (
<Modal
isOpen={isOpen}
close={() => {
onClose();
}}
contentLabel={t("content_label")}
position="top"
>
<div className="dark:text-white mt-6">
<PublisherCard
title={origin.name}
image={origin.icon}
url={origin.host}
isSmall={false}
isCard={false}
/>
<div className="flex flex-col gap-2 py-1">
<p className="text-md">{t("set_permissions")}</p>

<div className="flex flex-col gap-1">
<ListItem checkedValue={PermissionOption.ASK_EVERYTIME} />
<ListItem checkedValue={PermissionOption.DONT_ASK_CURRENT} />
<ListItem checkedValue={PermissionOption.DONT_ASK_ANY} />
</div>
<div className="flex mt-5">
<Button
label={tCommon("actions.save")}
primary
flex
onClick={() => permissionCallback(permissionOption)}
/>
</div>
</div>
</div>
</Modal>
);

type ListItemProps = {
checkedValue: PermissionOption;
};

function ListItem({ checkedValue }: ListItemProps) {
return (
<div className="flex flex-row gap-2 items-center py-1">
<input
type="radio"
id={checkedValue}
name="permission"
value="permission"
checked={permissionOption === checkedValue}
onChange={() => {
setPermissionOption(checkedValue);
}}
className={classNames(
"border border-gray-200 dark:border-neutral-700 cursor-pointer text-primary focus:ring-0 focus:ring-offset-0",
permissionOption !== checkedValue
? "bg-white dark:bg-surface-01dp"
: ""
)}
/>
<label
htmlFor={checkedValue}
className="text-sm text-gray-600 dark:text-neutral-400 cursor-pointer"
>
<Trans
i18nKey={checkedValue}
t={t}
values={{ permission }}
components={[
// eslint-disable-next-line react/jsx-key
<b></b>,
]}
/>
</label>
</div>
);
}
}
4 changes: 2 additions & 2 deletions src/app/components/PublisherCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default function PublisherCard({
<div
className={classNames(
isSmall ? "p-2" : "flex-col justify-center p-4",
isCard && "drop-shadow rounded-lg mt-4",
"flex items-center bg-white dark:bg-surface-02dp"
isCard && "drop-shadow rounded-lg mt-4 bg-white dark:bg-surface-02dp",
"flex items-center"
)}
>
{image && (
Expand Down
Loading
Loading