Skip to content

Commit

Permalink
feat(yew-notifications): update doc and readme;
Browse files Browse the repository at this point in the history
feat(ci): update config;
  • Loading branch information
TheBestTvarynka committed Apr 1, 2023
1 parent bcb3c45 commit 3604f7b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
credentials_json: '${{ secrets.GCP_SERVICE_KEY }}'

- name: 'Build documentation'
run: 'mkdir doc && cargo doc --release --target-dir doc --all-features -p yew-notifications --no-deps'
run: 'mkdir doc && cargo doc --release --target-dir doc --all-features -p yew-notifications --no-deps --color always'

- name: 'Set up Cloud SDK'
uses: google-github-actions/setup-gcloud@v0
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ Notifications components library for [Yew](https://yew.rs/). It's like [react-to

![deploy](https://github.com/TheBestTvarynka/yew-notifications/actions/workflows/github-actions.yml/badge.svg)

Documentation: https://yn-docs.qkation.com/
Documentation: https://yn-docs.qkation.com/yew_notifications/index.htmlhttps://yn-docs.qkation.com/

#[](/static/screenshots/basic_example.gif)

<sub>[demo](https://yn-docs.qkation.com/examples/basic/index.html)</sub>

Where it already used?

* [crypto-helper](https://crypto.qkation.com/)

### Motivation

Expand Down
28 changes: 14 additions & 14 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ use crate::Notifiable;

/// Returned object from the `use_notification` hook. Can spawn new notifications.
#[derive(Clone, PartialEq)]
pub struct NotificationsManager<T: Notifiable + PartialEq + Clone> {
pub(crate) sender: Option<UseReducerDispatcher<NotificationsList<T>>>,
pub struct NotificationsManager<N: Notifiable + PartialEq + Clone> {
pub(crate) sender: Option<UseReducerDispatcher<NotificationsList<N>>>,
}

impl<T: Notifiable + PartialEq + Clone> NotificationsManager<T> {
/// Spawns new notification of the type T.
pub fn spawn(&self, notification: T) {
impl<N: Notifiable + PartialEq + Clone> NotificationsManager<N> {
/// Spawns new notification of the type N.
pub fn spawn(&self, notification: N) {
if let Some(sender) = &self.sender {
sender.dispatch(Action::New(notification));
}
}
}

impl<T: Notifiable + PartialEq + Clone> Default for NotificationsManager<T> {
impl<N: Notifiable + PartialEq + Clone> Default for NotificationsManager<N> {
fn default() -> Self {
Self {
sender: Default::default(),
Expand All @@ -31,28 +31,28 @@ impl<T: Notifiable + PartialEq + Clone> Default for NotificationsManager<T> {
}

#[derive(Debug)]
pub enum Action<T: Notifiable + PartialEq + Clone> {
New(T),
pub enum Action<N: Notifiable + PartialEq + Clone> {
New(N),
Close(Uuid),
Tick,
Pause(Uuid),
Continue(Uuid),
}

#[derive(Debug, Clone, PartialEq)]
pub struct NotificationsList<T: Notifiable + PartialEq + Clone> {
pub notifications: Vec<T>,
pub struct NotificationsList<N> {
pub notifications: Vec<N>,
}

impl<T: Notifiable + PartialEq + Clone> Default for NotificationsList<T> {
impl<N> Default for NotificationsList<N> {
fn default() -> Self {
Self {
notifications: Default::default(),
}
}
}

impl<T: Notifiable + PartialEq + Clone> NotificationsList<T> {
impl<N> NotificationsList<N> {
pub const TIME_TICK_MILLIS: usize = 1000; // every second
pub const TIME_TICK_DURATION: Duration = Duration::seconds(1);

Expand All @@ -61,8 +61,8 @@ impl<T: Notifiable + PartialEq + Clone> NotificationsList<T> {
}
}

impl<T: Notifiable + PartialEq + Clone> Reducible for NotificationsList<T> {
type Action = Action<T>;
impl<N: Notifiable + PartialEq + Clone> Reducible for NotificationsList<N> {
type Action = Action<N>;

fn reduce(self: Rc<Self>, action: Self::Action) -> Rc<Self> {
match action {
Expand Down
20 changes: 10 additions & 10 deletions src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<&str> for NotificationsPosition {

/// Props for [`NotificationsProvider`]
#[derive(Properties, PartialEq, Clone)]
pub struct NotificationsProviderProps<T: Notifiable + PartialEq, F: NotifiableComponentFactory<T> + PartialEq + Clone> {
pub struct NotificationsProviderProps<N: Notifiable + PartialEq, F: NotifiableComponentFactory<N> + PartialEq + Clone> {
/// Inner provider components
pub children: Children,
/// Instance of the component factory
Expand All @@ -60,13 +60,13 @@ pub struct NotificationsProviderProps<T: Notifiable + PartialEq, F: NotifiableCo
#[prop_or(NotificationsPosition::BottomRight)]
pub position: NotificationsPosition,
#[prop_or_default]
pub _notification: PhantomData<T>,
pub _notification: PhantomData<N>,
}

/// The notification provider component.
///
/// Every child (direct or indirect) of this component can use `use_notification` hook to spawn new notifications.
/// `T` - type of the notification.
/// `N` - type of the notification.
/// `F` - notification factory type.
///
/// # Example
Expand All @@ -82,12 +82,12 @@ pub struct NotificationsProviderProps<T: Notifiable + PartialEq, F: NotifiableCo
/// ```
#[function_component(NotificationsProvider)]
pub fn notifications_provider<
T: Notifiable + PartialEq + Clone,
F: NotifiableComponentFactory<T> + PartialEq + Clone,
N: Notifiable + PartialEq + Clone,
F: NotifiableComponentFactory<N> + PartialEq + Clone,
>(
props: &NotificationsProviderProps<T, F>,
props: &NotificationsProviderProps<N, F>,
) -> Html {
let notifications = use_reducer_eq(NotificationsList::<T>::default);
let notifications = use_reducer_eq(NotificationsList::<N>::default);

let manager = NotificationsManager {
sender: Some(notifications.dispatcher()),
Expand All @@ -100,7 +100,7 @@ pub fn notifications_provider<
let sender = sender.clone();
let is_active = *is_active;

let interval = Interval::new(NotificationsList::<T>::TIME_TICK_MILLIS as u32, move || {
let interval = Interval::new(NotificationsList::<N>::TIME_TICK_MILLIS as u32, move || {
if is_active {
sender.dispatch(Action::Tick);
}
Expand All @@ -120,7 +120,7 @@ pub fn notifications_provider<
let classes = vec![classes!("notifications"), (&props.position).into()];

html! {
<ContextProvider<NotificationsManager<T>> context={manager}>
<ContextProvider<NotificationsManager<N>> context={manager}>
{children}
<div class={classes}>
{for ns.iter().map(|n| {
Expand Down Expand Up @@ -151,6 +151,6 @@ pub fn notifications_provider<
notification_creator.component(notification, onclick, onenter, onleave)
})}
</div>
</ContextProvider<NotificationsManager<T>>>
</ContextProvider<NotificationsManager<N>>>
}
}
Binary file added static/screenshots/basic_example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3604f7b

Please sign in to comment.