Skip to content

Commit

Permalink
onlySassy toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
artlu99 committed Nov 1, 2024
1 parent a7f4ce7 commit 593fb94
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/channelFeed.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface EnhancedCastObject extends CastObject {
amFollowing: boolean;
authorHasPowerBadge: boolean;
botOrNotResult: BotOrNotResult;
isSassy: boolean;
decryptedText?: string;
tags: IHashTag[];
}
export interface PagedCronFeed {
Expand Down Expand Up @@ -37,6 +39,7 @@ export const getEnhancedChannelFeed = async (channelFeedRequestPayload: ChannelF
casts: cronFeed.casts.map((castObject) => ({
...castObject,
amFollowing: following.find((fid) => fid === castObject.author.fid) !== undefined,
isSassy: /[a-fA-F0-9]{64}/.test(castObject.text),

authorHasPowerBadge: powerBadgeUsers.find((fid) => fid === castObject.author.fid) !== undefined,
botOrNotResult: botOrNotResponse.fids.find((fid) => fid.fid === castObject.author.fid)?.result ?? {
Expand Down
1 change: 1 addition & 0 deletions src/api/forYouFeed.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const getEnhancedForYouFeed = async (
casts: forYouFeed.casts.map((castObject) => ({
...castObject,
amFollowing: following.find((fid) => fid === castObject.author.fid) !== undefined,
isSassy: /[a-fA-F0-9]{64}/.test(castObject.text),

authorHasPowerBadge: powerBadgeUsers.find((fid) => fid === castObject.author.fid) !== undefined,
botOrNotResult: botOrNotResponse.fids.find((fid) => fid.fid === castObject.author.fid)?.result ?? {
Expand Down
2 changes: 2 additions & 0 deletions src/components/apps/channelFeed/ChannelFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const ChannelFeed: React.FC = () => {
const signalToNoiseState = useAppSelector((state) => state.signalToNoise);
const showMainFeed = signalToNoiseState.showMainFeed;
const showOnlyFollowing = signalToNoiseState.showOnlyFollowing;
const showOnlySassy = signalToNoiseState.showOnlySassy;
const showOnlyFarcaptcha = signalToNoiseState.showOnlyFarcaptcha;

const { user } = useNeynarContext();
Expand Down Expand Up @@ -116,6 +117,7 @@ export const ChannelFeed: React.FC = () => {
const filteredCasts = casts
.filter((c) => !showMainFeed || isAllowedInMainFeed(c, channelModerators))
.filter((c) => !showOnlyFollowing || c.amFollowing)
.filter((c) => !showOnlySassy || c.isSassy)
.filter((c) => !showOnlyFarcaptcha || c.botOrNotResult.farcaptcha)
.filter((c) =>
selectedLabels.length === 0 ? true : selectedLabels.includes(c.botOrNotResult.label ?? 'missing-label'),
Expand Down
3 changes: 3 additions & 0 deletions src/components/apps/forYouFeed/ForYouFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {

const signalToNoiseState = useAppSelector((state) => state.signalToNoise);
const showOnlyFollowing = signalToNoiseState.showOnlyFollowing;
const showOnlySassy = signalToNoiseState.showOnlySassy;
const showOnlyCuratedChannels = signalToNoiseState.showOnlyCuratedChannels;
const showOnlyFarcaptcha = signalToNoiseState.showOnlyFarcaptcha;

Expand Down Expand Up @@ -97,6 +98,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {
const filteredCastsList = useMemo(() => {
const filteredCasts = casts
.filter((c) => !showOnlyFollowing || c.amFollowing)
.filter((c) => !showOnlySassy || c.isSassy)
.filter((c) => !showOnlyCuratedChannels || c.tags.length > 1)
.filter((c) => !showOnlyFarcaptcha || c.botOrNotResult.farcaptcha)
.filter((c) =>
Expand Down Expand Up @@ -134,6 +136,7 @@ export const ForYouFeed: React.FC<ForYouFeedProps> = ({ fid }) => {
casts,
setNumCastsAfterFiltering,
showOnlyFollowing,
showOnlySassy,
showOnlyCuratedChannels,
showOnlyFarcaptcha,
selectedLabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
setShowOnlyCuratedChannels,
setShowOnlyFarcaptcha,
setShowOnlyFollowing,
setShowOnlySassy,
unsetShowMainFeed,
unsetShowOnlyCuratedChannels,
unsetShowOnlyFarcaptcha,
unsetShowOnlyFollowing,
unsetShowOnlySassy,
} from '@app/store/slices/signalToNoiseSlice';
import { useZustand } from '@app/store/zustand';
import { useTranslation } from 'react-i18next';
Expand All @@ -26,6 +28,7 @@ export const FeedSettings: React.FC = () => {
numCasts,
numMainFeedCasts,
numFollowingCasts,
numSassyCasts,
numCuratedChannelsCasts,
numFarcaptchas,
numCastsAfterFiltering,
Expand All @@ -35,6 +38,7 @@ export const FeedSettings: React.FC = () => {
const signalToNoiseState = useAppSelector((state) => state.signalToNoise);
const showMainFeed = signalToNoiseState.showMainFeed;
const showOnlyFollowing = signalToNoiseState.showOnlyFollowing;
const showOnlySassy = signalToNoiseState.showOnlySassy;
const showOnlyCuratedChannels = signalToNoiseState.showOnlyCuratedChannels;
const showOnlyFarcaptcha = signalToNoiseState.showOnlyFarcaptcha;

Expand All @@ -44,6 +48,9 @@ export const FeedSettings: React.FC = () => {
const handleChangeOnlyFollowing = (showOnlyFollowing: boolean) => {
dispatch(showOnlyFollowing ? setShowOnlyFollowing() : unsetShowOnlyFollowing());
};
const handleChangeOnlySassy = (showOnlySassy: boolean) => {
dispatch(showOnlySassy ? setShowOnlySassy() : unsetShowOnlySassy());
};
const handleChangeOnlyCuratedChannels = (showOnlyCuratedChannels: boolean) => {
dispatch(showOnlyCuratedChannels ? setShowOnlyCuratedChannels() : unsetShowOnlyCuratedChannels());
};
Expand Down Expand Up @@ -115,6 +122,16 @@ export const FeedSettings: React.FC = () => {
/>
</SwitchContainer>
<BaseDivider />
<SwitchContainer>
<span>{t('Only Sassy')}</span> {numSassyCasts}
<BaseSwitch
checkedChildren={t('On')}
unCheckedChildren={t('Off')}
checked={showOnlySassy}
onChange={handleChangeOnlySassy}
/>
</SwitchContainer>
<BaseDivider />
</>
)}
<SwitchContainer>
Expand Down
5 changes: 5 additions & 0 deletions src/constants/altClients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ export const herocastLink = (props: LinkProps) => {
const { hash } = props;
return `https://app.herocast.xyz/conversation/${hash}`;
};

export const fireflyLink = (props: LinkProps) => {
const { hash } = props;
return `https://firefly.mask.social/${hash}`;
};
19 changes: 19 additions & 0 deletions src/store/slices/signalToNoiseSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ import { createAction, createSlice } from '@reduxjs/toolkit';
interface SignalToNoiseState {
showMainFeed: boolean;
showOnlyFollowing: boolean;
showOnlySassy: boolean;
showOnlyCuratedChannels: boolean;
showOnlyFarcaptcha: boolean;
}

const showMainFeed = localStorage.getItem('showMainFeed') === 'true';
const showOnlyFollowing = localStorage.getItem('showOnlyFollowing') === 'true';
const showOnlySassy = localStorage.getItem('showOnlySassy') === 'false';
const showOnlyCuratedChannels = localStorage.getItem('showOnlyCuratedChannels') === 'true';
const showOnlyFarcaptcha = localStorage.getItem('showOnlyFarcaptcha') === 'true';

localStorage.setItem('showMainFeed', JSON.stringify(showMainFeed));
localStorage.setItem('showOnlyFollowing', JSON.stringify(showOnlyFollowing));
localStorage.setItem('showOnlySassy', JSON.stringify(showOnlySassy));
localStorage.setItem('showOnlyCuratedChannels', JSON.stringify(showOnlyCuratedChannels));
localStorage.setItem('showOnlyFarcaptcha', JSON.stringify(showOnlyFarcaptcha));

const initialState: SignalToNoiseState = {
showMainFeed,
showOnlyFollowing,
showOnlySassy,
showOnlyCuratedChannels,
showOnlyFarcaptcha,
};
Expand All @@ -42,6 +46,15 @@ export const unsetShowOnlyFollowing = createAction('signalToNoise/unsetShowOnlyF
return { payload: false };
});

export const setShowOnlySassy = createAction('signalToNoise/setShowOnlySassy', () => {
localStorage.setItem('showOnlySassy', JSON.stringify(true));
return { payload: true };
});
export const unsetShowOnlySassy = createAction('signalToNoise/unsetShowOnlySassy', () => {
localStorage.setItem('showOnlySassy', JSON.stringify(false));
return { payload: false };
});

export const setShowOnlyCuratedChannels = createAction('signalToNoise/setShowOnlyCuratedChannels', () => {
localStorage.setItem('showOnlyCuratedChannels', JSON.stringify(true));
return { payload: true };
Expand Down Expand Up @@ -78,6 +91,12 @@ export const signalToNoiseSlice = createSlice({
builder.addCase(unsetShowOnlyFollowing, (state, action) => {
state.showOnlyFollowing = action.payload;
});
builder.addCase(setShowOnlySassy, (state, action) => {
state.showOnlySassy = action.payload;
});
builder.addCase(unsetShowOnlySassy, (state, action) => {
state.showOnlySassy = action.payload;
});
builder.addCase(setShowOnlyCuratedChannels, (state, action) => {
state.showOnlyCuratedChannels = action.payload;
});
Expand Down
4 changes: 4 additions & 0 deletions src/store/zustand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface ZustandState {
setNumMainFeedCasts: (count: number) => void;
numFollowingCasts: number;
setNumFollowingCasts: (count: number) => void;
numSassyCasts: number;
setNumSassyCasts: (count: number) => void;
numCuratedChannelsCasts: number;
setNumCuratedChannelsCasts: (count: number) => void;
numFarcaptchas: number;
Expand All @@ -30,6 +32,8 @@ export const useZustand = create<ZustandState>()((set) => ({
setNumMainFeedCasts: (count) => set(() => ({ numMainFeedCasts: count })),
numFollowingCasts: 0,
setNumFollowingCasts: (count) => set(() => ({ numFollowingCasts: count })),
numSassyCasts: 0,
setNumSassyCasts: (count) => set(() => ({ numSassyCasts: count })),
numCuratedChannelsCasts: 0,
setNumCuratedChannelsCasts: (count) => set(() => ({ numCuratedChannelsCasts: count })),
numFarcaptchas: 0,
Expand Down

0 comments on commit 593fb94

Please sign in to comment.