Skip to content

Commit

Permalink
Merge branch 'persist-share-as-image-choices' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sharunkumar committed Aug 11, 2024
2 parents beddb70 + db6a9e0 commit 62940bd
Show file tree
Hide file tree
Showing 33 changed files with 606 additions and 69 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"editor.formatOnSave": true,
"prettier.enable": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.removeUnusedImports": "always"
}
}
4 changes: 2 additions & 2 deletions src/features/auth/login/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Totp from "./Totp";
import { DynamicDismissableModalContext } from "../../../shared/DynamicDismissableModal";
import InAppExternalLink from "../../../shared/InAppExternalLink";
import { HelperText } from "../../../settings/shared/formatting";
import { getImageSrc } from "../../../../services/lemmy";
import { buildBaseLemmyUrl, getImageSrc } from "../../../../services/lemmy";
import { loginSuccess } from "../../../../helpers/toastMessages";
import lemmyLogo from "../lemmyLogo.svg";
import { styled } from "@linaria/react";
Expand Down Expand Up @@ -162,7 +162,7 @@ export default function Login({ url, siteIcon }: LoginProps) {
<div className="ion-padding">
You are logging in to{" "}
<InAppExternalLink
href={`https://${url}`}
href={buildBaseLemmyUrl(url)}
target="_blank"
rel="noopener noreferrer"
>
Expand Down
6 changes: 4 additions & 2 deletions src/features/comment/CommentLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Text } from "mdast";
import { uniqBy } from "lodash";
import { isValidUrl } from "../../helpers/url";
import spoiler from "@aeharding/remark-lemmy-spoiler";
import { buildBaseLemmyUrl } from "../../services/lemmy";

const Container = styled.div`
display: flex;
Expand All @@ -34,6 +35,7 @@ export default function CommentLinks({ markdown }: CommentLinksProps) {
const connectedInstance = useAppSelector(
(state) => state.auth.connectedInstance,
);
const connectedInstanceUrl = buildBaseLemmyUrl(connectedInstance);

const links = useMemo(() => {
// Initialize a unified processor with the remark-parse parser
Expand All @@ -56,7 +58,7 @@ export default function CommentLinks({ markdown }: CommentLinksProps) {
links.push({
type: node.type,
// normalize relative links
url: new URL(node.url, `https://${connectedInstance}`).href,
url: new URL(node.url, connectedInstanceUrl).href,
text:
"children" in node ? (node.children[0] as Text)?.value : undefined,
});
Expand All @@ -72,7 +74,7 @@ export default function CommentLinks({ markdown }: CommentLinksProps) {
links = links.slice(0, 4);

return links;
}, [markdown, showCommentImages, connectedInstance]);
}, [connectedInstance, markdown, showCommentImages, connectedInstanceUrl]);

if (!links.length) return;

Expand Down
26 changes: 14 additions & 12 deletions src/features/feed/PostCommentFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
isComment,
isPost,
postHasFilteredKeywords,
postHasFilteredWebsite,
} from "../../helpers/lemmy";
import { useAutohidePostIfNeeded } from "./PageTypeContext";

Expand All @@ -36,15 +37,15 @@ interface PostCommentFeed
extends Omit<FeedProps<PostCommentItem>, "renderItemContent"> {
communityName?: string;
filterHiddenPosts?: boolean;
filterKeywords?: boolean;
filterKeywordsAndWebsites?: boolean;

header?: ReactElement;
}

export default function PostCommentFeed({
fetchFn: _fetchFn,
filterHiddenPosts = true,
filterKeywords = true,
filterKeywordsAndWebsites = true,
filterOnRxFn: _filterOnRxFn,
filterFn: _filterFn,
...rest
Expand All @@ -58,6 +59,9 @@ export default function PostCommentFeed({
const filteredKeywords = useAppSelector(
(state) => state.settings.blocks.keywords,
);
const filteredWebsites = useAppSelector(
(state) => state.settings.blocks.websites,
);

const disableMarkingRead = useAppSelector(
(state) => state.settings.general.posts.disableMarkingRead,
Expand Down Expand Up @@ -152,26 +156,24 @@ export default function PostCommentFeed({
postHidden.hidden
)
return false;
if (
filterKeywords &&
postHasFilteredKeywords(
item.post,
filterKeywords ? filteredKeywords : [],
)
)
return false;

if (filterKeywordsAndWebsites) {
if (postHasFilteredKeywords(item.post, filteredKeywords)) return false;
if (postHasFilteredWebsite(item.post, filteredWebsites)) return false;
}

if (_filterFn) return _filterFn(item);

return true;
},
[
postHiddenById,
filteredKeywords,
filterKeywords,
filterHiddenPosts,
filterKeywordsAndWebsites,
_filterFn,
postDeletedById,
filteredKeywords,
filteredWebsites,
],
);

Expand Down
5 changes: 3 additions & 2 deletions src/features/feed/SpecialFeedMoreActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useSetPostAppearance,
} from "../post/appearance/PostAppearanceProvider";
import { getShareIcon } from "../../helpers/device";
import { buildBaseLemmyUrl } from "../../services/lemmy";

interface SpecialFeedMoreActionsProps {
type: ListingType;
Expand Down Expand Up @@ -40,10 +41,10 @@ export default function SpecialFeedMoreActions({
text: "Share",
icon: getShareIcon(),
handler: () => {
const url = urlSelector(store.getState());
const url = buildBaseLemmyUrl(urlSelector(store.getState()));

Share.share({
url: `https://${url}?dataType=Post&listingType=${type}`,
url: `${url}?dataType=Post&listingType=${type}`,
});
},
},
Expand Down
52 changes: 48 additions & 4 deletions src/features/labels/links/CommunityLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import { Community, SubscribedType } from "lemmy-js-client";
import { renderHandle } from "../Handle";
import { LinkContainer, StyledLink, hideCss } from "./shared";
import ItemIcon from "../img/ItemIcon";
import { useIonActionSheet } from "@ionic/react";
import { IonIcon, useIonActionSheet } from "@ionic/react";
import { LongPressOptions, useLongPress } from "use-long-press";
import {
heart,
heartDislikeOutline,
heartOutline,
removeCircleOutline,
tabletPortraitOutline,
} from "ionicons/icons";
import useCommunityActions from "../../community/useCommunityActions";
import { useCallback, useContext } from "react";
import { createContext, useCallback, useContext } from "react";
import { ShareImageContext } from "../../share/asImage/ShareAsImage";
import {
preventOnClickNavigationBug,
Expand All @@ -22,12 +23,28 @@ import {
import { styled } from "@linaria/react";
import { cx } from "@linaria/core";
import { useAppSelector } from "../../../store";
import { OShowSubscribedIcon } from "../../../services/db";

const StyledItemIcon = styled(ItemIcon)`
margin-right: 0.4rem;
vertical-align: middle;
`;

const SubscribedIcon = styled(IonIcon)`
color: var(--ion-color-danger);
vertical-align: middle;
font-size: 0.85em;
margin-bottom: 1px;
margin-left: 2px;
opacity: 0.4;
.ion-palette-dark & {
opacity: 0.5;
}
`;

interface CommunityLinkProps {
community: Community;
showInstanceWhenRemote?: boolean;
Expand Down Expand Up @@ -55,6 +72,7 @@ export default function CommunityLink({
const showCommunityIcons = useAppSelector(
(state) => state.settings.appearance.posts.showCommunityIcons,
);
const showSubscribed = useShowSubscribedIcon();

const { isSubscribed, isBlocked, subscribe, block, sidebar } =
useCommunityActions(community, subscribed);
Expand Down Expand Up @@ -106,6 +124,13 @@ export default function CommunityLink({
showInstanceWhenRemote,
});

const end = (
<>
{instance}
{showSubscribed && isSubscribed && <SubscribedIcon icon={heart} />}
</>
);

return (
<LinkContainer
{...bind()}
Expand All @@ -117,19 +142,38 @@ export default function CommunityLink({
e.stopPropagation();
preventOnClickNavigationBug(e);
}}
draggable={false}
>
{showCommunityIcons && !hideCommunity && !hideIcon && (
<StyledItemIcon item={community} size={tinyIcon ? 16 : 24} />
)}

{name}
{!disableInstanceClick && instance}
{!disableInstanceClick && end}
</StyledLink>
{disableInstanceClick && instance}
{disableInstanceClick && end}
</LinkContainer>
);
}

const onStart: LongPressOptions["onStart"] = (e) => {
e.stopPropagation();
};

function useShowSubscribedIcon() {
const feedEnabled = useContext(ShowSubscribedIconContext);
const subscribedIcon = useAppSelector(
(state) => state.settings.general.subscribedIcon,
);

switch (subscribedIcon) {
case OShowSubscribedIcon.OnlyAllLocal:
return feedEnabled;
case OShowSubscribedIcon.Never:
return false;
case OShowSubscribedIcon.Everywhere:
return true;
}
}

export const ShowSubscribedIconContext = createContext(false);
1 change: 1 addition & 0 deletions src/features/labels/links/PersonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export default function PersonLink({
e.stopPropagation();
preventOnClickNavigationBug(e);
}}
draggable={false}
>
{prefix ? (
<>
Expand Down
104 changes: 104 additions & 0 deletions src/features/settings/blocks/FilteredWebsites.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
IonItem,
IonItemOption,
IonItemOptions,
IonItemSliding,
IonLabel,
IonList,
useIonAlert,
} from "@ionic/react";
import { useAppDispatch, useAppSelector } from "../../../store";
import { ListHeader } from "../shared/formatting";
import { updateFilteredWebsites } from "../settingsSlice";
import { uniq, without } from "lodash";
import { RemoveItemButton } from "../../shared/ListEditor";
import { parseUrl } from "../../../helpers/url";
import useAppToast from "../../../helpers/useAppToast";
import { close } from "ionicons/icons";

export default function FilteredWebsites() {
const [presentAlert] = useIonAlert();
const presentToast = useAppToast();
const dispatch = useAppDispatch();
const filteredWebsites = useAppSelector(
(state) => state.settings.blocks.websites,
);

async function remove(website: string) {
dispatch(updateFilteredWebsites(without(filteredWebsites, website)));
}

async function add() {
presentAlert({
message: "Add Filtered Website",
buttons: [
{
text: "OK",
handler: ({ website }) => {
const cleanedWebsite = website.trim().toLowerCase();

if (!cleanedWebsite) return;

const hasProtocol = /^https?:\/\//.test(cleanedWebsite);
const host = parseUrl(
`${hasProtocol ? "" : "https://"}${cleanedWebsite}`,
)?.host;

if (!host || !host.includes(".")) {
presentToast({
message: "Invalid website",
color: "danger",
centerText: true,
icon: close,
});
return false;
}

dispatch(updateFilteredWebsites(uniq([...filteredWebsites, host])));
},
},
"Cancel",
],
inputs: [
{
placeholder: "example.org",
name: "website",
type: "url",
},
],
});
}

return (
<>
<ListHeader>
<IonLabel>Filtered Websites</IonLabel>
</ListHeader>
<IonList inset>
{filteredWebsites.map((website) => (
<IonItemSliding key={website}>
<IonItemOptions side="end" onIonSwipe={() => remove(website)}>
<IonItemOption
color="danger"
expandable
onClick={() => remove(website)}
>
Unfilter
</IonItemOption>
</IonItemOptions>
<IonItem>
<RemoveItemButton />
<IonLabel>{website}</IonLabel>
</IonItem>
</IonItemSliding>
))}

<IonItemSliding>
<IonItem onClick={add} button detail={false}>
<IonLabel color="primary">Add Website</IonLabel>
</IonItem>
</IonItemSliding>
</IonList>
</>
);
}
2 changes: 2 additions & 0 deletions src/features/settings/general/other/Other.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import OpenNativeApps from "./OpenNativeApps";
import ClearCache from "./ClearCache";
import BackupSettings from "./backup/BackupSettings";
import Thumbnailinator from "./Thumbnailinator";
import SubscribedIcon from "./SubscribedIcon";

export default function Other() {
return (
Expand All @@ -24,6 +25,7 @@ export default function Other() {
<Haptics />
<NoSubscribedInFeed />
<Thumbnailinator />
<SubscribedIcon />
<ClearCache />
<BackupSettings />
</IonList>
Expand Down
Loading

0 comments on commit 62940bd

Please sign in to comment.