Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: Favourite UI

alihamuh74eefc868ed4
diff --git a/apps/web/src/components/favorite/index.js b/apps/web/src/components/favorite/index.js
new file mode 100644
index 000000000..168e8984c
--- /dev/null
+++ b/apps/web/src/components/favorite/index.js
@@ -0,0 +1,41 @@
+import React from "react";
+import { Flex, Text } from "rebass";
+import TimeAgo from "timeago-react";
+import ListItem from "../list-item";
+
+const dropdownRefs = [];
+const menuItems = [
+ { title: "Unfavorite" },
+ {
+ title: "Delete",
+ color: "red"
+ }
+];
+
+const Favourite = ({ item, index }) => {
+ const trashItem = item;
+ return (
+ <ListItem
+ title={trashItem.title}
+ body={trashItem.headline}
+ index={index}
+ onClick={() => {}} //TODO
+ info={
+ <Flex justifyContent="center" alignItems="center">
+ <TimeAgo datetime={trashItem.dateDeleted} />
+ <Text as="span" mx={1}>
+ •
+ </Text>
+ <Text color="primary">
+ {trashItem.type[0].toUpperCase() + trashItem.type.substring(1)}
+ </Text>
+ </Flex>
+ }
+ menuData={trashItem}
+ menuItems={menuItems}
+ dropdownRefs={dropdownRefs}
+ />
+ );
+};
+
+export default Favourite;
\ No newline at end of file
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index 118870cd0..5a9bad69b 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -8,6 +8,7 @@ import { ThemeProvider } from "emotion-theming";
import { Box, Flex, Heading } from "rebass";
import * as Icon from "react-feather";
import theme from "../theme";
+import Favorite from "../views/Favorite";
export const routes = {
home: {
@@ -25,7 +26,7 @@ export const routes = {
favorites: {
key: "favorites",
title: "Favorites",
- component: undefined,
+ component: Favorite,
icon: Icon.Star
},
trash: {
diff --git a/apps/web/src/views/Favorite.js b/apps/web/src/views/Favorite.js
new file mode 100644
index 000000000..be4443901
--- /dev/null
+++ b/apps/web/src/views/Favorite.js
@@ -0,0 +1,61 @@
+import React, { useState, useEffect } from "react";
+import { Box, Flex, Text } from "rebass";
+import Button from "../components/button";
+import { db, ev } from "../common";
+import FavoriteItem from "../components/favorite";
+import Search from "../components/search";
+import * as Icon from "react-feather";
+import { Virtuoso as List } from "react-virtuoso";
+
+function Favorite() {
+ const [favorites, setFavorites] = useState([]);
+
+ useEffect(() => {
+ function onRefreshFavorite() {
+ setFavorites(db.getFavorites());
+ }
+ onRefreshFavorite();
+ ev.addListener("refreshFavorite", onRefreshFavorite);
+ return () => {
+ ev.removeListener("refreshFavorite", onRefreshFavorite);
+ };
+ }, []);
+
+ return (
+ <Flex flexDirection="column" flex="1 1 auto">
+ {favorites.length > 0 ? (
+ <Flex flexDirection="column" flex="1 1 auto">
+ <Search placeholder="Search" />
+ <List
+ style={{
+ width: "100%",
+ flex: "1 1 auto",
+ height: "auto",
+ overflowX: "hidden"
+ }}
+ totalCount={favorites.length}
+ item={index => <FavoriteItem index={index} item={favorites[index]} />}
+ />
+ <Button
+ Icon={Icon.Star}
+ content={"Clear Favorite"}
+ //onClick={}
+ />
+ </Flex>
+ ) : (
+ <Flex
+ flex="1 1 auto"
+ alignItems="center"
+ justifyContent="center"
+ color="#9b9b9b"
+ flexDirection="column"
+ >
+ <Icon.Star size={72} strokeWidth={1.5} />
+ <Text variant="title">You have no Favorites.</Text>
+ </Flex>
+ )}
+ </Flex>
+ );
+}
+
+export default Favorite;
\ No newline at end of file