diff --git a/.github/workflows/review-style.yml b/.github/workflows/review-style.yml new file mode 100644 index 0000000..270ef82 --- /dev/null +++ b/.github/workflows/review-style.yml @@ -0,0 +1,22 @@ +name: Prettier + +on: [pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Clone source code + uses: actions/checkout@v1 + - name: Install Node + uses: actions/setup-node@v1 + with: + node-version: 10.x + - name: Install dependencies and run Prettier + run: | + npm install + npm run check-prettier + env: + CI: true \ No newline at end of file diff --git a/package.json b/package.json index 796074a..7513625 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "build-desktop-darwin-nosign": "npm run create-mac-icon; electron-builder -p 'never' -m dmg -c.mac.identity=null -c.afterSign=\"desktop/donothing.js\"", "build-desktop-linux": "electron-builder -p 'never' -l deb AppImage snap", "build-desktop-linux-select": "electron-builder -p 'never' -l ", + "check-prettier": "prettier --check src/**/**.tsx", "test": "react-scripts test", "eject": "react-scripts eject" }, diff --git a/src/types/Card.tsx b/src/types/Card.tsx index e3a3352..636de38 100644 --- a/src/types/Card.tsx +++ b/src/types/Card.tsx @@ -2,16 +2,16 @@ * Basic type for Cards, usually in Statuses */ export type Card = { - url: string; - title: string; - description: string; - image: string | null; - type: "link" | "photo" | "video" | "rich"; - author_name: string | null; - author_url: string | null; - provider_name: string | null; - provider_url: string | null; - html: string | null; - width: number | null; - height: number | null; + url: string; + title: string; + description: string; + image: string | null; + type: "link" | "photo" | "video" | "rich"; + author_name: string | null; + author_url: string | null; + provider_name: string | null; + provider_url: string | null; + html: string | null; + width: number | null; + height: number | null; }; diff --git a/src/utilities/appbar.tsx b/src/utilities/appbar.tsx index 4b4869c..bd4e8c0 100644 --- a/src/utilities/appbar.tsx +++ b/src/utilities/appbar.tsx @@ -7,5 +7,5 @@ import { isDarwinApp } from "./desktop"; * @returns Boolean dictating if the title bar is visible */ export function isAppbarExpanded(): boolean { - return isDarwinApp() || process.env.NODE_ENV === "development"; + return isDarwinApp() || process.env.NODE_ENV === "development"; } diff --git a/src/utilities/notifications.tsx b/src/utilities/notifications.tsx index accb54a..bbd3390 100644 --- a/src/utilities/notifications.tsx +++ b/src/utilities/notifications.tsx @@ -4,22 +4,22 @@ import { getUserDefaultBool, setUserDefaultBool } from "./settings"; * Get the person's permission to send notification requests. */ export function getNotificationRequestPermission() { - if ("Notification" in window) { - Notification.requestPermission(); - let request = Notification.permission; - if (request === "granted") { - setUserDefaultBool("enablePushNotifications", true); - setUserDefaultBool("userDeniedNotification", false); + if ("Notification" in window) { + Notification.requestPermission(); + let request = Notification.permission; + if (request === "granted") { + setUserDefaultBool("enablePushNotifications", true); + setUserDefaultBool("userDeniedNotification", false); + } else { + setUserDefaultBool("enablePushNotifications", false); + setUserDefaultBool("userDeniedNotification", true); + } } else { - setUserDefaultBool("enablePushNotifications", false); - setUserDefaultBool("userDeniedNotification", true); + console.warn( + "Notifications aren't supported in this browser. The setting will be disabled." + ); + setUserDefaultBool("enablePushNotifications", false); } - } else { - console.warn( - "Notifications aren't supported in this browser. The setting will be disabled." - ); - setUserDefaultBool("enablePushNotifications", false); - } } /** @@ -27,7 +27,7 @@ export function getNotificationRequestPermission() { * @returns Boolean value that determines whether the browser supports the Notification API */ export function browserSupportsNotificationRequests(): boolean { - return "Notification" in window; + return "Notification" in window; } /** @@ -35,7 +35,7 @@ export function browserSupportsNotificationRequests(): boolean { * @returns Boolean value of `enablePushNotifications` */ export function canSendNotifications() { - return getUserDefaultBool("enablePushNotifications"); + return getUserDefaultBool("enablePushNotifications"); } /** @@ -44,15 +44,15 @@ export function canSendNotifications() { * @param body The contents of the push notification */ export function sendNotificationRequest(title: string, body: string) { - if (canSendNotifications()) { - let notif = new Notification(title, { - body: body - }); + if (canSendNotifications()) { + let notif = new Notification(title, { + body: body + }); - notif.onclick = () => { - window.focus(); - }; - } else { - console.warn("The person has opted to not receive push notifications."); - } + notif.onclick = () => { + window.focus(); + }; + } else { + console.warn("The person has opted to not receive push notifications."); + } } diff --git a/src/utilities/settings.tsx b/src/utilities/settings.tsx index c5a0a45..95ad574 100644 --- a/src/utilities/settings.tsx +++ b/src/utilities/settings.tsx @@ -5,13 +5,13 @@ import { Config } from "../types/Config"; import { Visibility } from "../types/Visibility"; type SettingsTemplate = { - [key: string]: any; - darkModeEnabled: boolean; - systemDecidesDarkMode: boolean; - enablePushNotifications: boolean; - clearNotificationsOnRead: boolean; - displayAllOnNotificationBadge: boolean; - defaultVisibility: string; + [key: string]: any; + darkModeEnabled: boolean; + systemDecidesDarkMode: boolean; + enablePushNotifications: boolean; + clearNotificationsOnRead: boolean; + displayAllOnNotificationBadge: boolean; + defaultVisibility: string; }; /** @@ -20,14 +20,14 @@ type SettingsTemplate = { * @returns The boolean value associated with the key */ export function getUserDefaultBool(key: string): boolean { - if (localStorage.getItem(key) === null) { - console.warn( - "This key has not been set before, so the default value is FALSE for now." - ); - return false; - } else { - return localStorage.getItem(key) === "true"; - } + if (localStorage.getItem(key) === null) { + console.warn( + "This key has not been set before, so the default value is FALSE for now." + ); + return false; + } else { + return localStorage.getItem(key) === "true"; + } } /** @@ -36,10 +36,10 @@ export function getUserDefaultBool(key: string): boolean { * @param value The boolean value for the key */ export function setUserDefaultBool(key: string, value: boolean) { - if (localStorage.getItem(key) === null) { - console.warn("This key has not been set before."); - } - localStorage.setItem(key, value.toString()); + if (localStorage.getItem(key) === null) { + console.warn("This key has not been set before."); + } + localStorage.setItem(key, value.toString()); } /** @@ -47,14 +47,14 @@ export function setUserDefaultBool(key: string, value: boolean) { * @returns The Visibility value associated with the key */ export function getUserDefaultVisibility(): Visibility { - if (localStorage.getItem("defaultVisibility") === null) { - console.warn( - "This key has not been set before, so the default value is PUBLIC for now." - ); - return "public"; - } else { - return localStorage.getItem("defaultVisibility") as Visibility; - } + if (localStorage.getItem("defaultVisibility") === null) { + console.warn( + "This key has not been set before, so the default value is PUBLIC for now." + ); + return "public"; + } else { + return localStorage.getItem("defaultVisibility") as Visibility; + } } /** @@ -62,23 +62,23 @@ export function getUserDefaultVisibility(): Visibility { * @param key The settings key in localStorage to change */ export function setUserDefaultVisibility(key: string) { - if (localStorage.getItem("defaultVisibility") === null) { - console.warn("This key has not been set before."); - } - localStorage.setItem("defaultVisibility", key.toString()); + if (localStorage.getItem("defaultVisibility") === null) { + console.warn("This key has not been set before."); + } + localStorage.setItem("defaultVisibility", key.toString()); } /** * Gets the user's default theme or the default theme */ export function getUserDefaultTheme() { - let returnTheme = defaultTheme; - themes.forEach(theme => { - if (theme.key === localStorage.getItem("theme")) { - returnTheme = theme; - } - }); - return returnTheme; + let returnTheme = defaultTheme; + themes.forEach(theme => { + if (theme.key === localStorage.getItem("theme")) { + returnTheme = theme; + } + }); + return returnTheme; } /** @@ -86,42 +86,42 @@ export function getUserDefaultTheme() { * @param themeName The name of the theme */ export function setUserDefaultTheme(themeName: string) { - localStorage.setItem("theme", themeName); + localStorage.setItem("theme", themeName); } /** * Creates the user defaults if they do not exist already. */ export function createUserDefaults() { - let defaults: SettingsTemplate = { - darkModeEnabled: false, - systemDecidesDarkMode: true, - enablePushNotifications: true, - clearNotificationsOnRead: false, - displayAllOnNotificationBadge: false, - defaultVisibility: "public" - }; + let defaults: SettingsTemplate = { + darkModeEnabled: false, + systemDecidesDarkMode: true, + enablePushNotifications: true, + clearNotificationsOnRead: false, + displayAllOnNotificationBadge: false, + defaultVisibility: "public" + }; - let settings = [ - "darkModeEnabled", - "systemDecidesDarkMode", - "clearNotificationsOnRead", - "displayAllOnNotificationBadge", - "defaultVisibility" - ]; + let settings = [ + "darkModeEnabled", + "systemDecidesDarkMode", + "clearNotificationsOnRead", + "displayAllOnNotificationBadge", + "defaultVisibility" + ]; - migrateExistingSettings(); + migrateExistingSettings(); - settings.forEach((setting: string) => { - if (localStorage.getItem(setting) === null) { - if (typeof defaults[setting] === "boolean") { - setUserDefaultBool(setting, defaults[setting]); - } else { - localStorage.setItem(setting, defaults[setting].toString()); - } - } - }); - getNotificationRequestPermission(); + settings.forEach((setting: string) => { + if (localStorage.getItem(setting) === null) { + if (typeof defaults[setting] === "boolean") { + setUserDefaultBool(setting, defaults[setting]); + } else { + localStorage.setItem(setting, defaults[setting].toString()); + } + } + }); + getNotificationRequestPermission(); } /** @@ -129,22 +129,22 @@ export function createUserDefaults() { * @returns The Promise data from getting the config. */ export async function getConfig(): Promise { - try { - const resp = await axios.get("config.json"); - let config: Config = resp.data; - return config; - } catch (err) { - console.error( - "Couldn't configure Hyperspace with the config file. Reason: " + err.name - ); - } + try { + const resp = await axios.get("config.json"); + return resp.data as Config; + } catch (err) { + console.error( + "Couldn't configure Hyperspace with the config file. Reason: " + + err.name + ); + } } export function migrateExistingSettings() { - if (localStorage.getItem("prefers-dark-mode")) { - setUserDefaultBool( - "darkModeEnabled", - localStorage.getItem("prefers-dark-mode") === "true" - ); - } + if (localStorage.getItem("prefers-dark-mode")) { + setUserDefaultBool( + "darkModeEnabled", + localStorage.getItem("prefers-dark-mode") === "true" + ); + } }