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: custom prompts #4037

Merged
merged 37 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d38297a
feat: add `EditPrompt` icon
omBratteng Jan 2, 2025
26e23b5
feat: add `CustomPrompt` icon
omBratteng Jan 2, 2025
a511e2c
feat: add `TLDR` icon
omBratteng Jan 2, 2025
934d02a
Merge branch 'main' into feat-custom-prompts
rebelchris Jan 3, 2025
0a3f255
feat: setting addition (#4035)
rebelchris Jan 3, 2025
1667a4a
feat: smart prompt modal (#4038)
rebelchris Jan 3, 2025
42d0758
feat: add custom prompt buttons to post content (#4039)
omBratteng Jan 6, 2025
8821e7c
Merge branch 'main' into feat-custom-prompts
omBratteng Jan 6, 2025
fa8bc7f
fix: add custom prompt box (#4047)
rebelchris Jan 7, 2025
c0cb6da
feat: stream smart queries (#4044)
omBratteng Jan 7, 2025
04a2d00
fix: render modal on mobile (#4048)
rebelchris Jan 7, 2025
a1a60f3
fix: sort language order on custom prompts
rebelchris Jan 10, 2025
3fb5e32
fix: render only chosen options
rebelchris Jan 10, 2025
77f63f8
fix: only render chosen and right size
rebelchris Jan 10, 2025
5e0843f
fix: add copy/edit buttons
rebelchris Jan 10, 2025
ff053d4
Merge branch 'main' into feat-custom-prompts
rebelchris Jan 10, 2025
cf20521
fix: update prompt
rebelchris Jan 10, 2025
fb63fa1
Merge remote-tracking branch 'origin/feat-custom-prompts' into feat-c…
rebelchris Jan 10, 2025
394b617
Merge branch 'main' of github.com:dailydotdev/apps into feat-custom-p…
rebelchris Feb 3, 2025
bc0aa5a
fix: right endpoint
rebelchris Feb 3, 2025
4ca5c61
fix: lb happy :)
rebelchris Feb 3, 2025
c1533fb
fix: try different format
rebelchris Feb 3, 2025
2c30c67
Merge branch 'main' into feat-custom-prompts
rebelchris Feb 3, 2025
28d34fb
Merge branch 'main' into feat-custom-prompts
rebelchris Feb 3, 2025
09a6066
Update packages/shared/src/lib/query.ts
rebelchris Feb 4, 2025
96a4590
Merge branch 'main' into feat-custom-prompts
rebelchris Feb 4, 2025
1e68a92
fix: try once, PR feedback
rebelchris Feb 4, 2025
bf8a580
fix: pr feedback
rebelchris Feb 4, 2025
6369c9f
fix: pr feedback
rebelchris Feb 4, 2025
c0ed7f9
fix: pr feedback
rebelchris Feb 4, 2025
c9c313d
fix: pr feedback
rebelchris Feb 4, 2025
b4f97a4
Merge branch 'main' of github.com:dailydotdev/apps into feat-custom-p…
rebelchris Feb 5, 2025
f65e4c7
fix: review feedback
rebelchris Feb 5, 2025
cf0b2b2
fix: pr feedback and tests
rebelchris Feb 5, 2025
0d93332
fix: modify tracking needs
rebelchris Feb 5, 2025
04336aa
fix: last item feedback
rebelchris Feb 5, 2025
16783a9
fix: linter
rebelchris Feb 5, 2025
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
15 changes: 12 additions & 3 deletions packages/shared/src/components/buttons/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,18 @@ export const useGetIconWithSize = (
size: icon.props?.size ?? buttonSizeToIconSize[size],
className: classNames(
icon.props.className,
!iconOnly && '!h-6 !w-6 text-base',
!iconOnly && iconPosition === ButtonIconPosition.Left && '-ml-2 mr-1',
!iconOnly && iconPosition === ButtonIconPosition.Right && '-mr-2 ml-1',
!iconOnly && 'text-base',
!iconOnly && !icon.props?.size && '!h-6 !w-6',
!iconOnly && iconPosition === ButtonIconPosition.Left && 'mr-1',
!iconOnly &&
!icon.props?.size &&
iconPosition === ButtonIconPosition.Left &&
'-ml-2',
!iconOnly && iconPosition === ButtonIconPosition.Right && 'ml-1',
!iconOnly &&
!icon.props?.size &&
iconPosition === ButtonIconPosition.Right &&
'-mr-2',
),
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React from 'react';
import type { ReactElement } from 'react';
import {
Typography,
TypographyColor,
TypographyTag,
TypographyType,
} from '../../../typography/Typography';
import { PlusUser } from '../../../PlusUser';
import ConditionalWrapper from '../../../ConditionalWrapper';
import { SimpleTooltip } from '../../../tooltips';
import { LogEvent, Origin, TargetId } from '../../../../lib/log';
import { Button, ButtonSize, ButtonVariant } from '../../../buttons/Button';
import { plusUrl } from '../../../../lib/constants';
import { DevPlusIcon } from '../../../icons';
import { usePlusSubscription, useToastNotification } from '../../../../hooks';
import { usePromptsQuery } from '../../../../hooks/prompt/usePromptsQuery';
import { FilterCheckbox } from '../../../fields/FilterCheckbox';
import { useSettingsContext } from '../../../../contexts/SettingsContext';
import { labels } from '../../../../lib';
import { useLogContext } from '../../../../contexts/LogContext';

export const SmartPrompts = (): ReactElement => {
const { isPlus, logSubscriptionEvent } = usePlusSubscription();
const { displayToast } = useToastNotification();
const { logEvent } = useLogContext();
const { flags, updatePromptFlag } = useSettingsContext();
const { prompt: promptFlags } = flags;
const { data: prompts, isLoading } = usePromptsQuery();

return (
<section className="flex flex-col gap-4" aria-busy={isLoading}>
<div className="flex flex-col">
<div className="mb-1 flex items-center gap-2">
<Typography
tag={TypographyTag.H3}
color={TypographyColor.Primary}
type={TypographyType.Body}
bold
>
Smart Prompts
</Typography>
<PlusUser />
</div>
<Typography
className="pr-24"
color={TypographyColor.Tertiary}
type={TypographyType.Callout}
>
Level up how you interact with posts using AI-powered prompts. Extract
insights, refine content, or run custom instructions to get more out
of every post in one click.
</Typography>
</div>
<ConditionalWrapper
condition={!isPlus}
wrapper={(child) => {
return (
<SimpleTooltip
container={{
className: 'max-w-70 text-center typo-subhead',
}}
content="Upgrade to Plus to unlock Smart Prompts."
>
<div className="w-fit">{child as ReactElement}</div>
</SimpleTooltip>
);
}}
>
<div className="flex flex-col gap-2">
{prompts?.map(({ id, label, description }) => (
<FilterCheckbox
key={id}
name={`prompt-${id}`}
checked={promptFlags?.[id] ?? true}
description={description}
disabled={!isPlus}
onToggleCallback={() => {
const newState = !(promptFlags?.[id] || true);
updatePromptFlag(id, newState);
rebelchris marked this conversation as resolved.
Show resolved Hide resolved
displayToast(
labels.feed.settings.globalPreferenceNotice.smartPrompt,
);

logEvent({
event_name: LogEvent.ToggleSmartPrompts,
target_id: newState ? TargetId.On : TargetId.Off,
extra: JSON.stringify({
origin: Origin.Settings,
}),
});
}}
descriptionClassName="text-text-tertiary"
>
<Typography bold>{label}</Typography>
</FilterCheckbox>
))}
</div>
</ConditionalWrapper>
{!isPlus && (
<Button
className="w-fit"
tag="a"
type="button"
variant={ButtonVariant.Primary}
size={ButtonSize.Medium}
href={plusUrl}
icon={<DevPlusIcon className="text-action-plus-default" />}
onClick={() => {
logSubscriptionEvent({
event_name: LogEvent.UpgradeSubscription,
target_id: TargetId.ClickbaitShield,
});
}}
>
Upgrade to Plus
</Button>
)}
</section>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { Divider } from '../../../utilities';
import { Switch } from '../../../fields/Switch';
import { labels } from '../../../../lib';
import { SmartPrompts } from '../components/SmartPrompts';

export const FeedSettingsAISection = (): ReactElement => {
const { isPlus, logSubscriptionEvent } = usePlusSubscription();
Expand Down Expand Up @@ -159,6 +160,8 @@ export const FeedSettingsAISection = (): ReactElement => {
icon={null}
/>
</section>
<Divider className="bg-border-subtlest-tertiary" />
<SmartPrompts />
</>
);
};
10 changes: 10 additions & 0 deletions packages/shared/src/components/icons/CustomPrompt/filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/shared/src/components/icons/CustomPrompt/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ReactElement } from 'react';
import React from 'react';
import type { IconProps } from '../../Icon';
import Icon from '../../Icon';
import OutlinedIcon from './outlined.svg';
import FilledIcon from './filled.svg';

export const CustomPromptIcon = (props: IconProps): ReactElement => (
<Icon {...props} IconPrimary={OutlinedIcon} IconSecondary={FilledIcon} />
);
10 changes: 10 additions & 0 deletions packages/shared/src/components/icons/CustomPrompt/outlined.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/shared/src/components/icons/EditPrompt/filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/shared/src/components/icons/EditPrompt/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ReactElement } from 'react';
import React from 'react';
import type { IconProps } from '../../Icon';
import Icon from '../../Icon';
import OutlinedIcon from './outlined.svg';
import FilledIcon from './filled.svg';

export const EditPromptIcon = (props: IconProps): ReactElement => (
<Icon {...props} IconPrimary={OutlinedIcon} IconSecondary={FilledIcon} />
);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions packages/shared/src/components/icons/TLDR/filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/shared/src/components/icons/TLDR/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ReactElement } from 'react';
import React from 'react';
import type { IconProps } from '../../Icon';
import Icon from '../../Icon';
import OutlinedIcon from './outlined.svg';
import FilledIcon from './filled.svg';

export const TLDRIcon = (props: IconProps): ReactElement => (
<Icon {...props} IconPrimary={OutlinedIcon} IconSecondary={FilledIcon} />
);
6 changes: 6 additions & 0 deletions packages/shared/src/components/icons/TLDR/outlined.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/shared/src/components/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ export * from './ShieldWarning';
export * from './ShieldPlus';
export * from './Sidebar';
export * from './Folder';
export * from './EditPrompt';
export * from './CustomPrompt';
export * from './TLDR';
export * from './Privacy';
7 changes: 7 additions & 0 deletions packages/shared/src/components/modals/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ const AddToCustomFeedModal = dynamic(
),
);

const SmartPromptModal = dynamic(() =>
import(
/* webpackChunkName: "smartPromptModal" */ './plus/SmartPromptModal'
).then((mod) => mod.SmartPromptModal),
);

const CookieConsentModal = dynamic(
() =>
import(
Expand Down Expand Up @@ -264,6 +270,7 @@ export const modals = {
[LazyModal.ClickbaitShield]: ClickbaitShieldModal,
[LazyModal.MoveBookmark]: MoveBookmarkModal,
[LazyModal.AddToCustomFeed]: AddToCustomFeedModal,
[LazyModal.SmartPrompt]: SmartPromptModal,
[LazyModal.CookieConsent]: CookieConsentModal,
[LazyModal.ReportUser]: ReportUserModal,
};
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/components/modals/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export enum LazyModal {
AddToCustomFeed = 'addToCustomFeed',
CookieConsent = 'cookieConsent',
ReportUser = 'reportUser',
SmartPrompt = 'smartPrompt',
}

export type ModalTabItem = {
Expand Down
Loading