Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications page #288

Merged
merged 6 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/builddao/widget/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ const config = {
},
hide: true,
},
notifications: {
path: "${config_account}/widget/page.notifications",
blockHeight: "final",
init: {
name: "Notifications",
},
hide: true,
},
},
},
};
Expand Down
1 change: 1 addition & 0 deletions apps/builddao/widget/app/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const Container = styled.div`
const Content = styled.div`
width: 100%;
height: 100%;
background: var(--bg-1, #000);
`;

// const Template = config.Template ?? (({children}) => <>{children}</>);
Expand Down
4 changes: 4 additions & 0 deletions apps/builddao/widget/components/CSS.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ const CSS = styled.div`
background: #007bff;
color: #fff;
}

.placeholder-glow {
background: var(--bg-1, black);
}
`;

return { CSS };
102 changes: 90 additions & 12 deletions apps/builddao/widget/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ const { Button } = VM.require("${config_account}/widget/components") || {
Button: () => <></>,
};

if (!Button) {
return "";
}

const { href } = VM.require("${config_account}/widget/lib.url") || {
href: () => {},
};
Expand Down Expand Up @@ -208,6 +204,25 @@ const MobileContent = styled.div`
justify-content: space-between;
`;

const getNotificationCount = () => {
const notificationFeedSrc = "${alias_mob}/widget/NotificationFeed";

const lastBlockHeight = Storage.get("lastBlockHeight", notificationFeedSrc);
if (lastBlockHeight === null) {
return "";
}

const notifications = Social.index("notify", context.accountId, {
order: "asc",
from: (lastBlockHeight ?? 0) + 1,
subscribe: true,
});

return notifications.length;
};

const unreadNotifications = getNotificationCount();

function Navbar(props) {
const { page, routes } = props;
const [dropdown, setDropdown] = useState(false);
Expand Down Expand Up @@ -263,6 +278,37 @@ function Navbar(props) {
</NavLinks>
</Left>
<Right>
{context.accountId && (
<Button
className="rounded-3 position-relative"
type="icon"
href={href({
widgetSrc: "${config_account}/widget/app",
params: {
page: "notifications",
},
})}
>
<i className="bi bi-bell"></i>
{unreadNotifications > 0 && (
<div
className="position-absolute d-flex align-items-center justify-content-center text-white fw-bold"
style={{
top: 0,
background: "red",
borderRadius: "100%",
right: 0,
width: 18,
height: 18,
fontSize: 10,
margin: -4,
}}
>
{unreadNotifications}
</div>
)}
</Button>
)}
<div
style={{
flex: 1,
Expand Down Expand Up @@ -351,14 +397,46 @@ function Navbar(props) {
alt="BuildDAO"
/>
</Link>
<Button
type="icon"
variant="outline"
className="rounded-2 border-0"
onClick={toggleDropdown}
>
<i style={{ fontSize: 24 }} className="bi bi-list"></i>
</Button>
<div className="d-flex align-items-center gap-2">
{context.accountId && (
<Button
className="rounded-3 position-relative"
type="icon"
href={href({
widgetSrc: "${config_account}/widget/app",
params: {
page: "notifications",
},
})}
>
<i className="bi bi-bell"></i>
{unreadNotifications > 0 && (
<div
className="position-absolute d-flex align-items-center justify-content-center text-white fw-bold"
style={{
top: 0,
background: "red",
borderRadius: "100%",
right: 0,
width: 18,
height: 18,
fontSize: 10,
margin: -4,
}}
>
{unreadNotifications}
</div>
)}
</Button>
)}
<Button
type="icon"
className="rounded-2 border-0"
onClick={toggleDropdown}
>
<i style={{ fontSize: 24 }} className="bi bi-list"></i>
</Button>
</div>
</MobileNavigation>
</MainContent>

Expand Down
63 changes: 63 additions & 0 deletions apps/builddao/widget/page/notifications.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const accountId = context.accountId;

if (!accountId) {
return "Sign in with NEAR Wallet";
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we show a login button to navigate them to join page?
Like we do for feed I guess

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this sounds like a nice addition


const index = {
action: "notify",
key: accountId,
options: {
limit: 50,
order: "desc",
subscribe: true,
},
cacheOptions: {
ignoreCache: true,
},
};

const StyledNotification = styled.div`
.me-2.text-truncate,
.text-muted {
color: white !important;
}

.btn.rounded-5 {
border-radius: 8px !important;
border: 1px solid rgba(255, 255, 255, 0.2) !important;
font-family: "Poppins", sans-serif !important;
font-weight: 500 !important;
color: white !important;
background: black !important;
}
`;

const renderItem = (item, i) => {
if (i === 0) {
Storage.set("lastBlockHeight", item.blockHeight);
}
return (
<StyledNotification>
<Widget
loading={
<div className="mb-3">
<div className="placeholder" style={{ height: "48px" }} />
</div>
}
src="${alias_mob}/widget/Notification.Item"
key={i}
props={item}
/>
</StyledNotification>
);
};

return (
<div className="placeholder-glow container-xl mt-3">
<Widget
src="${alias_mob}/widget/FilteredIndexFeed"
props={{ index, renderItem }}
/>
</div>
);
Loading