diff --git a/web/src/components/ShortcutView.tsx b/web/src/components/ShortcutView.tsx index 76b6de3..0ff99e1 100644 --- a/web/src/components/ShortcutView.tsx +++ b/web/src/components/ShortcutView.tsx @@ -31,6 +31,7 @@ const ShortcutView = (props: Props) => { const [showAnalyticsDialog, setShowAnalyticsDialog] = useState(false); const havePermission = currentUser.role === "ADMIN" || shortcut.creatorId === currentUser.id; const shortcutLink = absolutifyLink(`/s/${shortcut.name}`); + const compactStyle = viewStore.layout === "grid"; useEffect(() => { faviconStore.getOrFetchUrlFavicon(shortcut.link).then((url) => { @@ -58,7 +59,7 @@ const ShortcutView = (props: Props) => { return ( <> -
+
@@ -128,22 +129,21 @@ const ShortcutView = (props: Props) => { )}
- {shortcut.description &&

{shortcut.description}

} - {shortcut.tags.length > 0 && ( -
- {shortcut.tags.map((tag) => { - return ( - viewStore.setFilter({ tag: tag })} - > - #{tag} - - ); - })} -
- )} + {shortcut.description && !compactStyle &&

{shortcut.description}

} +
+ {shortcut.tags.map((tag) => { + return ( + viewStore.setFilter({ tag: tag })} + > + #{tag} + + ); + })} + {shortcut.tags.length === 0 && No tags} +
diff --git a/web/src/components/ShortcutListView.tsx b/web/src/components/ShortcutsContainer.tsx similarity index 66% rename from web/src/components/ShortcutListView.tsx rename to web/src/components/ShortcutsContainer.tsx index 50e923a..dffb534 100644 --- a/web/src/components/ShortcutListView.tsx +++ b/web/src/components/ShortcutsContainer.tsx @@ -1,18 +1,27 @@ import { useState } from "react"; import CreateShortcutDialog from "./CreateShortcutDialog"; import ShortcutView from "./ShortcutView"; +import useViewStore from "../stores/v1/view"; +import classNames from "classnames"; interface Props { shortcutList: Shortcut[]; } -const ShortcutListView: React.FC = (props: Props) => { +const ShortcutsContainer: React.FC = (props: Props) => { const { shortcutList } = props; + const viewStore = useViewStore(); + const layout = viewStore.layout || "list"; const [editingShortcutId, setEditingShortcutId] = useState(); return ( <> -
+
{shortcutList.map((shortcut) => { return setEditingShortcutId(shortcut.id)} />; })} @@ -31,4 +40,4 @@ const ShortcutListView: React.FC = (props: Props) => { ); }; -export default ShortcutListView; +export default ShortcutsContainer; diff --git a/web/src/components/OrderSetting.tsx b/web/src/components/ViewSetting.tsx similarity index 81% rename from web/src/components/OrderSetting.tsx rename to web/src/components/ViewSetting.tsx index 19839be..5f7a384 100644 --- a/web/src/components/OrderSetting.tsx +++ b/web/src/components/ViewSetting.tsx @@ -4,10 +4,11 @@ import useViewStore from "../stores/v1/view"; import Dropdown from "./common/Dropdown"; import Icon from "./Icon"; -const OrderSetting = () => { +const ViewSetting = () => { const viewStore = useViewStore(); const order = viewStore.getOrder(); const { field, direction } = order; + const layout = viewStore.layout || "list"; const handleReset = () => { viewStore.setOrder({ field: "name", direction: "asc" }); @@ -46,10 +47,17 @@ const OrderSetting = () => {
+
+ Layout + +
} > ); }; -export default OrderSetting; +export default ViewSetting; diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index 5659981..e12b570 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -6,10 +6,10 @@ import useViewStore, { getFilteredShortcutList, getOrderedShortcutList } from ". import useUserStore from "../stores/v1/user"; import useLoading from "../hooks/useLoading"; import Icon from "../components/Icon"; -import ShortcutListView from "../components/ShortcutListView"; +import ShortcutsContainer from "../components/ShortcutsContainer"; import CreateShortcutDialog from "../components/CreateShortcutDialog"; import FilterView from "../components/FilterView"; -import OrderSetting from "../components/OrderSetting"; +import ViewSetting from "../components/ViewSetting"; import Navigator from "../components/Navigator"; interface State { @@ -59,7 +59,7 @@ const Home: React.FC = () => { value={filter.search} onChange={(e) => viewStore.setFilter({ search: e.target.value })} /> - +
) : ( - + )}
diff --git a/web/src/stores/v1/view.ts b/web/src/stores/v1/view.ts index e2ccbca..c110ba3 100644 --- a/web/src/stores/v1/view.ts +++ b/web/src/stores/v1/view.ts @@ -13,12 +13,16 @@ export interface Order { direction: "asc" | "desc"; } +export type Layout = "grid" | "list"; + interface ViewState { filter: Filter; order: Order; + layout: Layout; setFilter: (filter: Partial) => void; getOrder: () => Order; setOrder: (order: Partial) => void; + setLayout: (layout: Layout) => void; } const useViewStore = create()( @@ -29,6 +33,7 @@ const useViewStore = create()( field: "name", direction: "asc", }, + layout: "list", setFilter: (filter: Partial) => { set({ filter: { ...get().filter, ...filter } }); }, @@ -41,6 +46,9 @@ const useViewStore = create()( setOrder: (order: Partial) => { set({ order: { ...get().order, ...order } }); }, + setLayout: (layout: Layout) => { + set({ layout }); + }, }), { name: "view",