Skip to content

Commit

Permalink
feat: add threads page
Browse files Browse the repository at this point in the history
  • Loading branch information
d0kur0 committed Sep 23, 2023
1 parent 3969aff commit 4d7c4ae
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"useTabs": true,
"printWidth": 110,
"printWidth": 90,
"tabWidth": 2,
"semi": true,
"singleQuote": false,
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"solid-icons": "^1.0.12",
"solid-js": "^1.7.6",
"solid-transition-group": "^0.0.10",
"webm-grabber": "^1.0.4"
"webm-grabber": "^1.1.0"
},
"devDependencies": {
"@electron-forge/cli": "^6.4.2",
Expand Down
24 changes: 14 additions & 10 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Route, Routes } from "@solidjs/router";
import { Box, globalCss, HopeProvider } from "@hope-ui/solid";
import { NotificationsProvider, globalCss, HopeProvider } from "@hope-ui/solid";
import { useStore } from "@nanostores/solid";
import { $media } from "./stores/media";
import { Match, Switch } from "solid-js";
import { GlobalLoading } from "./components/GlobalLoading";
import { Main } from "./pages/Main";
import { WindowBar } from "./components/WindowBar";
import { Threads } from "./pages/Threads";

const globalStyles = globalCss({
"*": {
Expand All @@ -18,6 +19,7 @@ function Routing() {
return (
<Routes>
<Route path="/" component={Main} />
<Route path="/threads" component={Threads} />
</Routes>
);
}
Expand All @@ -29,17 +31,19 @@ export function App() {

return (
<HopeProvider config={{ initialColorMode: "system" }}>
<WindowBar />
<NotificationsProvider>
<WindowBar />

<Switch>
<Match when={media().loading}>
<GlobalLoading />
</Match>
<Switch>
<Match when={media().loading}>
<GlobalLoading />
</Match>

<Match when={!media().loading}>
<Routing />
</Match>
</Switch>
<Match when={!media().loading}>
<Routing />
</Match>
</Switch>
</NotificationsProvider>
</HopeProvider>
);
}
6 changes: 5 additions & 1 deletion src/components/GlobalLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function GlobalLoading() {
return (
<Box
css={{
height: "100vh",
height: "calc(100vh - 52px)",
display: "flex",
alignItems: "center",
flexDirection: "column",
Expand All @@ -20,6 +20,10 @@ export function GlobalLoading() {

<Box mt={12}>Обновление списка тредов и файлов</Box>

<Box my={12} fontSize="0.9em" color="$neutral9">
Получение тредов с 4chan - долгий процесс
</Box>

<Box mt={12} css={{ fontSize: "0.7em" }}>
state: {status()}
</Box>
Expand Down
32 changes: 26 additions & 6 deletions src/pages/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
ListItem,
ListIcon,
Heading,
Switch,
notificationService,
Input,
SwitchPrimitive,
css,
Text,
Expand All @@ -21,7 +22,7 @@ import { TbHash } from "solid-icons/tb";
import { $fileTypes, $fileTypesActions } from "../stores/fileTypes";
import { $media, fetchMedia } from "../stores/media";
import { FaSolidHashtag } from "solid-icons/fa";
import { $filter } from "../stores/filter";
import { $filter, $filterActions } from "../stores/filter";
import { IoClose } from "solid-icons/io";

const switchRootClass = css({
Expand Down Expand Up @@ -87,6 +88,17 @@ export function Main() {
$schemaChanged.set(false);
};

const handleAddFilterWord = (event: SubmitEvent) => {
event.preventDefault();
const target = event.currentTarget as HTMLFormElement;
const formData = new FormData(target);
const word = formData.get("word");
if (!word) return;

$filterActions.add(word.toString());
target.reset();
};

return (
<Box p={16} css={{ display: "flex", gap: "32px" }}>
<Box css={{ flex: "1 1 0" }}>
Expand Down Expand Up @@ -174,9 +186,16 @@ export function Main() {
<Box css={{ flex: "1 1 0" }}>
<Heading mb={18} display="flex" justifyContent="space-between">
<Box>Бан ворды</Box>
<Button size="xs" onClick={() => prompt("pizda?")}>
Добавить
</Button>
<Box>
<form
onSubmit={handleAddFilterWord}
style={{ display: "flex", "align-items": "center", gap: "8px" }}>
<Input required name="word" placeholder="Write here..." size="xs" />
<Button type="submit" colorScheme="accent" size="xs">
Добавить
</Button>
</form>
</Box>
</Heading>

<Text my={16} fontSize=".9em" color="$neutral9">
Expand All @@ -190,7 +209,7 @@ export function Main() {
Список пуст
</Text>
}>
{word => (
{(word, index) => (
<Box
my={12}
px={16}
Expand All @@ -205,6 +224,7 @@ export function Main() {
<IconButton
size="xs"
icon={<IoClose />}
onClick={() => $filterActions.remove(index())}
variant="dashed"
aria-label="remove"
colorScheme="danger"
Expand Down
86 changes: 86 additions & 0 deletions src/pages/Threads.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
Box,
Input,
Button,
Heading,
List,
ListIcon,
ListItem,
Text,
Badge,
} from "@hope-ui/solid";
import { createMemo, createSignal, For } from "solid-js";
import { useStore } from "@nanostores/solid";
import { $media } from "../stores/media";
import { Link } from "@solidjs/router";

export function Threads() {
const [searchQuery, setSearchQuery] = createSignal("");

const media = useStore($media);

const threads = createMemo(() =>
media().threads.filter(thread => thread.subject?.includes(searchQuery())),
);

return (
<Box p={16}>
<Heading mb={24}>Список тредов</Heading>

<form style={{ display: "flex", gap: "12px" }}>
<Input
size="sm"
value={searchQuery()}
width={300}
onInput={({ currentTarget }) => setSearchQuery(currentTarget.value)}
placeholder="Поиск тредов"
/>
<Button type="reset" size="sm" colorScheme="warning" variant="dashed">
Сбросить
</Button>
</form>

<Box mt={24}>
{!!threads().length && (
<Text color="$neutral9" fontSize="0.8em" mb={8}>
Тредов: {threads().length}
</Text>
)}

<List spacing="$3">
<For
each={threads()}
fallback={
<Box
p={12}
border="2px dashed $neutral7"
display="flex"
borderRadius="8px"
color="$neutral9"
alignItems="center"
justifyContent="center">
Список тредов пуст
</Box>
}>
{thread => (
<ListItem>
<Link href={`/thread/${thread.id}`}>
<Badge
colorScheme={thread.vendorName === "2ch" ? "warning" : "success"}
mr={8}>
{thread.vendorName}
</Badge>
{thread.subject?.substring(0, 120) || (
<Text as="span" color="$neutral9">
Тред без названия
</Text>
)}
</Link>
</ListItem>
)}
</For>
</List>
</Box>
</Box>
);
}
3 changes: 3 additions & 0 deletions src/stores/fileTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { map, onSet } from "nanostores";
import { $schemaChanged } from "./schema";

const STORAGE_KEY = "file-types-cache";

Expand Down Expand Up @@ -53,5 +54,7 @@ export const $fileTypesActions = {
return { ...type, enabled: !type.enabled };
}),
);

$schemaChanged.set(true);
},
};
17 changes: 15 additions & 2 deletions src/stores/filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { map } from "nanostores";
import { map, onSet } from "nanostores";

export const $filter = map<string[]>(["nigger", "gay"]);
const STORAGE_KEY = "filter-cache";

const basedFilters = ["gay", "trap", "трап"];

function readFromCache() {
const cachedValue = localStorage.getItem(STORAGE_KEY);
return cachedValue ? JSON.parse(cachedValue) : basedFilters;
}

export const $filter = map<string[]>(readFromCache());

export const $filterActions = {
add(text: string) {
Expand All @@ -10,3 +19,7 @@ export const $filterActions = {
$filter.set($filter.get().filter((_, k) => k !== key));
},
};

onSet($filter, ({ newValue }) => {
localStorage.setItem(STORAGE_KEY, JSON.stringify(newValue));
});
Loading

0 comments on commit 4d7c4ae

Please sign in to comment.