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

feat/season-plugin-option #11

Merged
merged 14 commits into from
Dec 3, 2021

Conversation

PaulieScanlon
Copy link
Contributor

@PaulieScanlon PaulieScanlon commented Nov 15, 2021

  • add season start and end

The only slight snag with this is:

When a user sets the dates via the plugin options it must be a valid date object which includes the year. Naturally, next year this wouldn't start the snow unless the user changes the year in the options

    {
      resolve: "@raae/gatsby-plugin-let-it-snow",
      options: {
        season: {
          start: new Date("December 1, 2021"), // date including year
          end: new Date("January 1, 2022"), // date including year
        },
      },
    },

@@ -40,5 +41,14 @@ export const onInitialClientRender = (_, options) => {
}
};

frame();
if (season) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could do if(season && new Date() ...) not sure if you're a fan of nested if statements or not?

Copy link
Member

Choose a reason for hiding this comment

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

No real preference.

@raae
Copy link
Member

raae commented Nov 15, 2021

I think you can do custom validation, ie. letting folks write:

{
  resolve: "@raae/gatsby-plugin-let-it-snow",
  options: {
    season: {
      start: 12-01
      end: 01-01
    },
  },
},

And then custom verify that the string prefixed with the year is date...

I also think these dates should be the defaults if no season is set (making it a breaking change 🤯).

@PaulieScanlon
Copy link
Contributor Author

Dates are hard but to me 12-01 is the 12th of January so maybe the long hand way will work better so folks have to write it out saving confusion.

Also agree it should have a default.

Breaking change is ok. It can be the first stable version 1.0.0

... but we should probably add a CHANGELOG.md so it's clear, as well as of course, updating the README.md

@raae
Copy link
Member

raae commented Nov 15, 2021

What about your proposal + a flag for repeat every year? That is true by default?

@raae
Copy link
Member

raae commented Nov 15, 2021

See #12 for changelog

@PaulieScanlon
Copy link
Contributor Author

PaulieScanlon commented Nov 15, 2021

I'll have to look into it but you need the year in the date sting for it to be valid, and then to be able to run getTime on the date object which was the easiest way I could think of to handle the condition.

I'd be inclined to leave it and if folks want it next year they can update the date string.

@PaulieScanlon
Copy link
Contributor Author

PaulieScanlon commented Nov 15, 2021

I think as well using the date string folks could include a time

E.g

end: new Date("December 31, 2021 11:59:00")

And the getTime condition would still work

frame();
if (season) {
if (
new Date(now).getTime() >= new Date(season.start).getTime() &&
Copy link
Member

Choose a reason for hiding this comment

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

question: Aren't season.start already a date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are but they get passed as string so you can't run getTime() on the unless the new Date constructor is used

Copy link
Member

Choose a reason for hiding this comment

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

I see!

@raae
Copy link
Member

raae commented Nov 16, 2021

I really want it to start again next year, might look into it a little.

@PaulieScanlon
Copy link
Contributor Author

There's other ways to do this by changing the config to use a start and end month / day

Maybe something like this?

  plugins: [
    {
      resolve: "@raae/gatsby-plugin-let-it-snow",
      options: {
        season: {
          start: {
            day: 1,
            month: 12,
          },
          end: {
            day: 31,
            month: 12,
          },
        },
      },
    },
  ],

Then i guess those values could be used to construct a new Date and the year bit gets added by the plugin. This would then repeat each year and because a date is still constructed, the getTime() method to evaluate if it's within range would still work.

If you like the above API i can make the change, it's no trouble at all Queen!

@raae
Copy link
Member

raae commented Nov 17, 2021

Let's ask Twitter 🎉

@raae
Copy link
Member

raae commented Nov 21, 2021

Let's do it as you proposed and I will try to sneak in a repeat flag at some point.

Copy link
Member

@raae raae left a comment

Choose a reason for hiding this comment

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

I can add the defaults, if you add me to your fork.

@@ -4,5 +4,11 @@ exports.pluginOptionsSchema = ({ Joi }) => {
colors: Joi.array()
.items(Joi.string().default("#ffffff"))
.description("Array of hex color values"),
season: Joi.object()
.keys({
start: Joi.date(),
Copy link
Member

@raae raae Nov 21, 2021

Choose a reason for hiding this comment

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

nitpick: Add default dates.

Copy link
Contributor Author

@PaulieScanlon PaulieScanlon left a comment

Choose a reason for hiding this comment

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

Lovely stuff!

@raae raae closed this Dec 3, 2021
@raae raae reopened this Dec 3, 2021
@raae raae merged commit 9319fa0 into queen-raae:main Dec 3, 2021
raae-bot pushed a commit that referenced this pull request Dec 3, 2021
# [0.4.0](v0.3.0...v0.4.0) (2021-12-03)

### Features

* season-plugin-option, solves [#2](#2) ([#11](#11)) ([9319fa0](9319fa0))
@raae-bot
Copy link

raae-bot commented Dec 3, 2021

🎉 This PR is included in version 0.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@raae raae linked an issue Dec 3, 2021 that may be closed by this pull request
raae added a commit that referenced this pull request Dec 3, 2021
raae-bot pushed a commit that referenced this pull request Dec 3, 2021
## [0.4.1](v0.4.0...v0.4.1) (2021-12-03)

### Bug Fixes

* duration broken by [#11](#11) ([616a01f](616a01f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add season plugin option
3 participants