Skip to content

Commit

Permalink
feat: add copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
nbouliol committed Nov 8, 2023
1 parent ec0a3b6 commit 0bbbe67
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
16 changes: 16 additions & 0 deletions src/plugins/backgrounds/apod/Apod.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.Apod
.picture
background-position: 50% 50%
background-size: cover
transition: opacity 0.25s ease-out

.title
display: flex
flex-direction: column
position: absolute
bottom: 1rem
left: 1rem
right: 1rem

p
margin: 4px 0 0
18 changes: 13 additions & 5 deletions src/plugins/backgrounds/apod/Apod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Backdrop from "../../../views/shared/Backdrop";
import { defaultData, Props } from "./types";
import { getPicture } from "./api";
import ApodTitle from "./ApodTitle";
import "./Apod.sass";

const Unsplash: React.FC<Props> = ({
cache,
Expand All @@ -14,27 +15,34 @@ const Unsplash: React.FC<Props> = ({
}) => {
const [picture, setPicture] = React.useState(cache);
const mounted = React.useRef(false);

React.useEffect(() => {
getPicture(data, loader).then(setCache);
if (mounted.current || !picture) getPicture(data, loader).then(setPicture);
mounted.current = true;
}, [data.customDate, data.date]);

return (
<div className="Unsplash fullscreen">
<div className="Apod fullscreen">
<Backdrop
className="image fullscreen"
ready={true}
className="picture fullscreen"
ready={
!!(picture?.media_type === "image"
? picture?.hdurl || picture?.url
: picture?.thumbnail_url)
}
style={{
backgroundImage: `url(${
picture?.media_type === "image"
? picture?.hdurl
? picture?.hdurl || picture?.url
: picture?.thumbnail_url
})`,
}}
/>

{picture && data.showTitle && <ApodTitle title={picture.title} />}
{picture && data.showTitle && (
<ApodTitle title={picture.title} copyright={picture.copyright} />
)}
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/backgrounds/apod/ApodSettings.sass
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.ApodSettings
.date
margin-left: 4px;
margin-left: 4px
13 changes: 6 additions & 7 deletions src/plugins/backgrounds/apod/ApodTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from "react";
import giphyLogo from "./giphy-logo.png";
import { Image } from "./types";

type Props = {
title?: string;
};
type Props = Pick<Image, "title" | "copyright">;

const Credit: React.FC<Props> = ({ title }) => (
<div className="credit">
<span>{title}</span>
const Credit: React.FC<Props> = ({ title, copyright }) => (
<div className="title">
<p>{title}</p>
{copyright && <p>&copy; {copyright}</p>}
</div>
);

Expand Down
2 changes: 0 additions & 2 deletions src/plugins/backgrounds/apod/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export async function getPicture(
data: Config,
loader: API["loader"],
): Promise<Image> {
console.log("in getPicture");

const url = "https://api.nasa.gov/planetary/apod";
const params = new URLSearchParams();

Expand Down
1 change: 1 addition & 0 deletions src/plugins/backgrounds/apod/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface Image {
media_type: string;
explanation: string;
thumbnail_url: string;
copyright: string;
}

type Cache = Image;
Expand Down

0 comments on commit 0bbbe67

Please sign in to comment.