tag of the day basically done

just going to get rid of the copy
This commit is contained in:
mehbark 2023-07-22 16:19:42 -04:00
parent 7f24b1b481
commit 5f79532829
3 changed files with 112 additions and 3 deletions

View file

@ -102,3 +102,38 @@ export const DisappearOnClick = ({
{children}
</details>
);
export function shuffle<T>(array: T[]): T[] {
let currentIndex = array.length,
randomIndex;
// While there remain elements to shuffle.
while (currentIndex != 0) {
// Pick a remaining element.
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex],
array[currentIndex],
];
}
return array;
}
// type NOf<N extends number, T, R extends any[] = []> = R["length"] extends N
// ? R
// : NOf<N, T, [T, ...R]>;
// export function n_of<N extends number, T, R extends any[]>(
// n: N,
// x: T
// ): NOf<N, T, R> {
// return [];
// }
export function n_of<T>(n: number, x: T): T[] {
return new Array(n).fill(x);
}

View file

@ -30,7 +30,7 @@ const get_delays = (...lengths: number[]): number[] => {
return out;
};
const Wheel = ({
export const Wheel = ({
items,
width,
calc_width,
@ -74,12 +74,12 @@ function slices<T>(arr: T[]): T[][] {
return arr.map((_, i) => arr.slice(0, i));
}
function weird_slices<T>(arr: T[]): T[][] {
export function weird_slices<T>(arr: T[]): T[][] {
console.log(arr.map(item => [...arr.filter(t => t != item), item]));
return arr.map(item => [...arr.filter(t => t != item), item]);
}
const MultiWheel = ({
export const MultiWheel = ({
items,
calc_width,
shl,

View file

@ -0,0 +1,74 @@
import { ComponentChildren, toChildArray } from "preact";
import { Main, render_and_copy, shuffle, n_of } from "./common.tsx";
const Tag = ({ tag }: { tag: string }) => (
<a href={`https://cohost.org/rc/tagged/${tag}`}>{`#${tag}`}</a>
);
const tags = `\
CSS Crimes
borgesposting
NEISVoid
circling the square
retrocomputing
cats of cohost
coho film club
cohost crafts
the cohost plural feed
cohost summer mixtape
trans trucks
The Cohost Local Feed (Minnesota)
cohost draws
tv head
make up a mech pilot
frasierposting
cohost utilities`.split("\n");
// repeating makes it seem more random
export const PseudoRandom = ({
children,
repeat = 5,
}: {
children: ComponentChildren;
repeat?: number;
}) => (
<div
class="pseudo-random"
style={{
display: "grid",
gridTemplateColumns: `repeat(${
toChildArray(children).length * repeat
}, 1fr)`,
}}
>
{...n_of(repeat, toChildArray(children))
.map(shuffle)
.flat()
.map(child => <Choice>{child}</Choice>)}
</div>
);
/// width is 0-1
export const Choice = ({ children }: { children: ComponentChildren }) => (
<details
style={{
width: "100%",
height: "100%",
display: "inline-block",
cursor: "pointer",
}}
class="choice"
>
<summary
style={{ listStyle: "none", width: "100%", height: "100%" }}
></summary>
<div class="result">{children}</div>
</details>
);
render_and_copy(
<Main>
Click for a random @TagOfTheDay tag
<PseudoRandom>{...tags.map(tag => <Tag tag={tag} />)}</PseudoRandom>
</Main>
);