Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Commit eab6063

Browse files
committed
feat: Implement NSFW toggle
1 parent 7c93d46 commit eab6063

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

components/home.tsx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ interface IEntry {
9393
text: string;
9494
topics: string[];
9595
detail: number;
96+
nsfw: boolean;
9697
}
9798

9899
const ENTRIES: IEntry[] = [
@@ -103,6 +104,7 @@ const ENTRIES: IEntry[] = [
103104
text: "Lorem ipsum dolor sit amet consectetur adipisicing elit …",
104105
topics: ["substance-use"],
105106
detail: 10,
107+
nsfw: false,
106108
},
107109
{
108110
day: 17,
@@ -111,6 +113,7 @@ const ENTRIES: IEntry[] = [
111113
text: "Lorem ipsum dolor sit amet consectetur adipisicing elit …",
112114
topics: ["coming-out"],
113115
detail: 1,
116+
nsfw: false,
114117
},
115118
{
116119
day: 20,
@@ -119,6 +122,7 @@ const ENTRIES: IEntry[] = [
119122
text: "Lorem ipsum dolor sit amet consectetur adipisicing elit …",
120123
topics: ["hrt"],
121124
detail: 65,
125+
nsfw: false,
122126
},
123127
{
124128
day: 20,
@@ -127,6 +131,7 @@ const ENTRIES: IEntry[] = [
127131
text: "Dolor sit amet consectetur adipisicing elit lorem ipsum …",
128132
topics: ["ffs", "hrt"],
129133
detail: 20,
134+
nsfw: true,
130135
},
131136
{
132137
day: 21,
@@ -135,6 +140,7 @@ const ENTRIES: IEntry[] = [
135140
text: "Dolor sit amet consectetur adipisicing elit lorem ipsum …",
136141
topics: ["ffs", "domperidone"],
137142
detail: 30,
143+
nsfw: false,
138144
},
139145
{
140146
day: 22,
@@ -143,6 +149,7 @@ const ENTRIES: IEntry[] = [
143149
text: "Dolor sit amet consectetur adipisicing elit lorem ipsum …",
144150
topics: ["coming-out"],
145151
detail: 40,
152+
nsfw: false,
146153
},
147154
{
148155
day: 23,
@@ -151,6 +158,7 @@ const ENTRIES: IEntry[] = [
151158
text: "Dolor sit amet consectetur adipisicing elit lorem ipsum …",
152159
topics: ["substance-use", "ibutamoren"],
153160
detail: 100,
161+
nsfw: true,
154162
},
155163
{
156164
day: 30,
@@ -159,6 +167,7 @@ const ENTRIES: IEntry[] = [
159167
text: "Dolor sit amet consectetur adipisicing elit lorem ipsum …",
160168
topics: ["substance-use", "ibutamoren"],
161169
detail: 50,
170+
nsfw: true,
162171
},
163172
];
164173

@@ -315,6 +324,13 @@ export default function Home() {
315324
let pageStartDate = new Date();
316325
let pageEndDate = new Date();
317326

327+
const filter = (e: IEntry) =>
328+
activeTopics.filter((v) => e.topics.includes(v)).length > 0 &&
329+
e.detail <= detail &&
330+
nsfw
331+
? true
332+
: !e.nsfw;
333+
318334
switch (scale) {
319335
case "week": {
320336
maxPages = Math.round(
@@ -382,11 +398,7 @@ export default function Home() {
382398
break;
383399
}
384400
case "page": {
385-
const filteredEntries = ENTRIES.filter(
386-
(e) =>
387-
activeTopics.filter((v) => e.topics.includes(v)).length > 0 &&
388-
e.detail <= detail
389-
);
401+
const filteredEntries = ENTRIES.filter(filter);
390402

391403
maxPages = Math.ceil(filteredEntries.length / 4);
392404

@@ -405,19 +417,11 @@ export default function Home() {
405417
const entriesToShow =
406418
scale === "page"
407419
? ENTRIES.map((v, id) => ({ id, ...v }))
408-
.filter(
409-
(e) =>
410-
activeTopics.filter((v) => e.topics.includes(v)).length > 0 &&
411-
e.detail <= detail
412-
)
420+
.filter(filter)
413421
.slice(pageStartIndex, pageEndIndex)
414422
: ENTRIES.map((v, id) => ({ id, ...v }))
415423
.slice(pageStartIndex, pageEndIndex)
416-
.filter(
417-
(e) =>
418-
activeTopics.filter((v) => e.topics.includes(v)).length > 0 &&
419-
e.detail <= detail
420-
);
424+
.filter(filter);
421425

422426
let wentBackwards = useRef(false);
423427
useEffect(() => {
@@ -450,7 +454,7 @@ export default function Home() {
450454

451455
return 1;
452456
});
453-
}, [selectedEntryID, currentPagination, detail, activeTopics]);
457+
}, [selectedEntryID, currentPagination, detail, activeTopics, nsfw]);
454458

455459
return (
456460
<Page
@@ -620,12 +624,12 @@ export default function Home() {
620624
<ToolbarItem className="pf-u-display-none pf-u-display-inline-flex-on-md">
621625
<ToggleGroup aria-label="Filter controls">
622626
<Tooltip
623-
content="Toggle the available filters"
627+
content="Toggle the available filters (coming soon)"
624628
position="bottom"
625629
>
626630
<ToggleGroupItem
627631
icon={<FilterIcon />}
628-
aria-label="Toggle the available filters"
632+
aria-label="Toggle the available filters (coming soon)"
629633
isSelected={filters}
630634
onChange={() => setFilters((v) => !v)}
631635
isDisabled
@@ -657,14 +661,15 @@ export default function Home() {
657661
>
658662
<ToggleGroup aria-label="Filter controls">
659663
<Tooltip
660-
content="Toggle the available filters"
664+
content="Toggle the available filters (coming soon)"
661665
position="bottom"
662666
>
663667
<ToggleGroupItem
664668
icon={<FilterIcon />}
665-
aria-label="Toggle the available filters"
669+
aria-label="Toggle the available filters (coming soon)"
666670
isSelected={filters}
667671
onChange={() => setFilters((v) => !v)}
672+
isDisabled
668673
/>
669674
</Tooltip>
670675
</ToggleGroup>

0 commit comments

Comments
 (0)