mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-18 21:19:44 +00:00
feat: add visibility filter
This commit is contained in:
parent
0cceed51f8
commit
00c7abc38d
@ -85,7 +85,7 @@ const AnalyticsDialog: React.FC<Props> = (props: Props) => {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" className="py-2 px-2 text-left text-sm font-semibold text-gray-500">
|
<th scope="col" className="py-2 px-2 text-left text-sm font-semibold text-gray-500">
|
||||||
Devices
|
Operating system
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="py-2 pr-2 text-right text-sm font-semibold text-gray-500">
|
<th scope="col" className="py-2 pr-2 text-right text-sm font-semibold text-gray-500">
|
||||||
Visitors
|
Visitors
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import useViewStore from "../stores/v1/filter";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import useViewStore from "../stores/v1/view";
|
||||||
import Icon from "./Icon";
|
import Icon from "./Icon";
|
||||||
|
import VisibilityIcon from "./VisibilityIcon";
|
||||||
|
|
||||||
const FilterView = () => {
|
const FilterView = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
const viewStore = useViewStore();
|
const viewStore = useViewStore();
|
||||||
const filter = viewStore.filter;
|
const filter = viewStore.filter;
|
||||||
const shouldShowFilters = filter.tag !== undefined;
|
const shouldShowFilters = filter.tag !== undefined || filter.visibility !== undefined;
|
||||||
|
|
||||||
if (!shouldShowFilters) {
|
if (!shouldShowFilters) {
|
||||||
return <></>;
|
return <></>;
|
||||||
@ -15,10 +18,21 @@ const FilterView = () => {
|
|||||||
<span className="text-gray-400">Filters:</span>
|
<span className="text-gray-400">Filters:</span>
|
||||||
{filter.tag && (
|
{filter.tag && (
|
||||||
<button
|
<button
|
||||||
className="ml-2 px-2 py-1 flex flex-row justify-center items-center bg-gray-200 rounded-full text-gray-500 text-sm hover:line-through"
|
className="ml-2 px-2 py-1 flex flex-row justify-center items-center bg-gray-100 rounded-full text-gray-500 text-sm hover:line-through"
|
||||||
onClick={() => viewStore.setFilter({ tag: undefined })}
|
onClick={() => viewStore.setFilter({ tag: undefined })}
|
||||||
>
|
>
|
||||||
<Icon.Tag className="w-4 h-auto mr-1" />#{filter.tag}
|
<Icon.Tag className="w-4 h-auto mr-1" />#{filter.tag}
|
||||||
|
<Icon.X className="w-4 h-auto ml-1" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{filter.visibility && (
|
||||||
|
<button
|
||||||
|
className="ml-2 px-2 py-1 flex flex-row justify-center items-center bg-gray-100 rounded-full text-gray-500 text-sm hover:line-through"
|
||||||
|
onClick={() => viewStore.setFilter({ visibility: undefined })}
|
||||||
|
>
|
||||||
|
<VisibilityIcon className="w-4 h-auto mr-1" visibility={filter.visibility} />
|
||||||
|
{t(`shortcut.visibility.${filter.visibility.toLowerCase()}.self`)}
|
||||||
|
<Icon.X className="w-4 h-auto ml-1" />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { shortcutService } from "../services";
|
import { shortcutService } from "../services";
|
||||||
import useFaviconStore from "../stores/v1/favicon";
|
import useFaviconStore from "../stores/v1/favicon";
|
||||||
import useViewStore from "../stores/v1/filter";
|
import useViewStore from "../stores/v1/view";
|
||||||
import useUserStore from "../stores/v1/user";
|
import useUserStore from "../stores/v1/user";
|
||||||
import { absolutifyLink } from "../helpers/utils";
|
import { absolutifyLink } from "../helpers/utils";
|
||||||
import { showCommonDialog } from "./Alert";
|
import { showCommonDialog } from "./Alert";
|
||||||
@ -143,14 +143,17 @@ const ShortcutView = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title={t(`shortcut.visibility.${shortcut.visibility.toLowerCase()}.description`)} variant="solid" placement="top" arrow>
|
<Tooltip title={t(`shortcut.visibility.${shortcut.visibility.toLowerCase()}.description`)} variant="solid" placement="top" arrow>
|
||||||
<div className="w-auto px-2 leading-6 flex flex-row justify-start items-center border rounded-full text-gray-500 text-sm">
|
<div
|
||||||
|
className="w-auto px-2 leading-6 flex flex-row justify-start items-center border rounded-full cursor-pointer text-gray-500 text-sm"
|
||||||
|
onClick={() => viewStore.setFilter({ visibility: shortcut.visibility })}
|
||||||
|
>
|
||||||
<VisibilityIcon className="w-4 h-auto mr-1" visibility={shortcut.visibility} />
|
<VisibilityIcon className="w-4 h-auto mr-1" visibility={shortcut.visibility} />
|
||||||
{t(`shortcut.visibility.${shortcut.visibility.toLowerCase()}.self`)}
|
{t(`shortcut.visibility.${shortcut.visibility.toLowerCase()}.self`)}
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title="View count" variant="solid" placement="top" arrow>
|
<Tooltip title="View count" variant="solid" placement="top" arrow>
|
||||||
<div
|
<div
|
||||||
className="w-auto px-2 leading-6 flex flex-row justify-start items-center border rounded-full text-gray-500 text-sm"
|
className="w-auto px-2 leading-6 flex flex-row justify-start items-center border rounded-full cursor-pointer text-gray-500 text-sm"
|
||||||
onClick={() => setShowAnalyticsDialog(true)}
|
onClick={() => setShowAnalyticsDialog(true)}
|
||||||
>
|
>
|
||||||
<Icon.BarChart2 className="w-4 h-auto mr-1" />
|
<Icon.BarChart2 className="w-4 h-auto mr-1" />
|
||||||
|
@ -2,7 +2,7 @@ import { Button, Tab, TabList, Tabs } from "@mui/joy";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { shortcutService } from "../services";
|
import { shortcutService } from "../services";
|
||||||
import { useAppSelector } from "../stores";
|
import { useAppSelector } from "../stores";
|
||||||
import useViewStore, { Filter } from "../stores/v1/filter";
|
import useViewStore, { Filter } from "../stores/v1/view";
|
||||||
import useUserStore from "../stores/v1/user";
|
import useUserStore from "../stores/v1/user";
|
||||||
import useLoading from "../hooks/useLoading";
|
import useLoading from "../hooks/useLoading";
|
||||||
import Icon from "../components/Icon";
|
import Icon from "../components/Icon";
|
||||||
@ -15,7 +15,7 @@ interface State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getFilteredShortcutList = (shortcutList: Shortcut[], filter: Filter, currentUser: User) => {
|
const getFilteredShortcutList = (shortcutList: Shortcut[], filter: Filter, currentUser: User) => {
|
||||||
const { tag, mineOnly } = filter;
|
const { tag, mineOnly, visibility } = filter;
|
||||||
const filteredShortcutList = shortcutList.filter((shortcut) => {
|
const filteredShortcutList = shortcutList.filter((shortcut) => {
|
||||||
if (tag) {
|
if (tag) {
|
||||||
if (!shortcut.tags.includes(tag)) {
|
if (!shortcut.tags.includes(tag)) {
|
||||||
@ -27,6 +27,11 @@ const getFilteredShortcutList = (shortcutList: Shortcut[], filter: Filter, curre
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (visibility) {
|
||||||
|
if (shortcut.visibility !== visibility) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
return filteredShortcutList;
|
return filteredShortcutList;
|
||||||
|
@ -4,6 +4,7 @@ import { persist } from "zustand/middleware";
|
|||||||
export interface Filter {
|
export interface Filter {
|
||||||
tag?: string;
|
tag?: string;
|
||||||
mineOnly?: boolean;
|
mineOnly?: boolean;
|
||||||
|
visibility?: Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ViewState {
|
interface ViewState {
|
Loading…
x
Reference in New Issue
Block a user