Skip to content

Commit

Permalink
Enhanced theme selection (#4401)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs authored Sep 19, 2023
1 parent e8b1ee3 commit 226d763
Show file tree
Hide file tree
Showing 37 changed files with 376 additions and 169 deletions.
6 changes: 3 additions & 3 deletions frontend/app/src/components/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import Upgrading from "./upgrading/Upgrading.svelte";
import UpgradeBanner from "./UpgradeBanner.svelte";
import { mobileOperatingSystem } from "../utils/devices";
import { themeStore } from "../theme/themes";
import { currentTheme } from "../theme/themes";
import "../stores/fontSize";
import Profiler from "./Profiler.svelte";
import { OpenChat, SessionExpiryError } from "openchat-client";
Expand Down Expand Up @@ -310,12 +310,12 @@
}
let isFirefox = navigator.userAgent.indexOf("Firefox") >= 0;
$: burstPath = $themeStore.name === "dark" ? "/assets/burst_dark" : "/assets/burst_light";
$: burstPath = $currentTheme.mode === "dark" ? "/assets/burst_dark" : "/assets/burst_light";
$: burstUrl = isFirefox ? `${burstPath}.png` : `${burstPath}.svg`;
$: burstFixed = isScrollingRoute($pathParams);
</script>

{#if $themeStore.burst || landingPage}
{#if $currentTheme.burst || landingPage}
<div
class:fixed={burstFixed}
class="burst-wrapper"
Expand Down
7 changes: 6 additions & 1 deletion frontend/app/src/components/ButtonGroup.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
export let align: "end" | "fill" | "center" | "start" = "end"; // we may need more options later but I think this covers it at the moment
export let nowrap = false;
const cls = `button-group ${align}`;
</script>

<div class={cls}>
<div class:nowrap class={cls}>
<slot />
</div>

Expand All @@ -17,6 +18,10 @@
gap: $sp3;
flex-wrap: wrap;
&.nowrap {
flex-wrap: nowrap;
}
&.start {
justify-content: flex-start;
}
Expand Down
7 changes: 3 additions & 4 deletions frontend/app/src/components/home/EmojiPicker.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script lang="ts">
import { createEventDispatcher, onMount } from "svelte";
import "emoji-picker-element";
import { getCurrentThemeName } from "../../theme/themes";
import { currentTheme } from "../../theme/themes";
export let mode: "message" | "reaction" | "thread" = "message";
const dispatch = createEventDispatcher();
let theme: string = getCurrentThemeName();
onMount(() => {
document.querySelector("emoji-picker")?.addEventListener("emoji-click", (event) => {
Expand All @@ -19,8 +18,8 @@
class:message={mode === "message"}
class:reaction={mode === "reaction"}
class:thread={mode === "thread"}
class:dark={theme === "dark"}
class:light={theme === "light" || theme === "original"} />
class:dark={$currentTheme.mode === "dark"}
class:light={$currentTheme.mode === "light"} />

<style lang="scss">
emoji-picker {
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import { dimensions } from "../../stores/screenDimensions";
import { messageToForwardStore } from "../../stores/messageToForward";
import type { Share } from "../../utils/share";
import { themeStore } from "../../theme/themes";
import { currentTheme } from "../../theme/themes";
import SuspendedModal from "../SuspendedModal.svelte";
import NoAccess from "./NoAccess.svelte";
import NewGroup from "./addgroup/NewGroup.svelte";
Expand Down Expand Up @@ -1026,7 +1026,7 @@
</Overlay>
{/if}

{#if $themeStore.name !== "white"}
{#if $currentTheme.name !== "white"}
<BackgroundLogo
width={`${bgHeight}px`}
bottom={"unset"}
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/components/home/MemeBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
MessageContext,
OpenChat,
} from "openchat-client";
import { themeStore } from "../../theme/themes";
import { currentTheme } from "../../theme/themes";
const client = getContext<OpenChat>("client");
Expand Down Expand Up @@ -43,8 +43,8 @@
const styleVariables = {
"--background-color": "#1b1c21",
"--foreground-color": $themeStore.txt,
"--button-color": $themeStore.button.bg,
"--foreground-color": $currentTheme.txt,
"--button-color": $currentTheme.button.bg,
};
function send() {
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/TimeAndTicks.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { _ } from "svelte-i18n";
import type { ChatType, OpenChat } from "openchat-client";
import { getContext } from "svelte";
import { themeStore } from "../../theme/themes";
import { currentTheme } from "../../theme/themes";
const client = getContext<OpenChat>("client");
Expand All @@ -27,7 +27,7 @@
export let deleted: boolean;
export let undeleting: boolean;
let iconColor = $themeStore.time.icon;
let iconColor = $currentTheme.time.icon;
let pinnedColor = crypto || me || fill ? "#ffffff" : "var(--txt)";
</script>

Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/Tweet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<script lang="ts">
import { _ } from "svelte-i18n";
import { themeStore } from "../../theme/themes";
import { currentTheme } from "../../theme/themes";
import { createEventDispatcher, onMount } from "svelte";
import { eventListScrolling } from "../../stores/scrollPos";
Expand Down Expand Up @@ -32,7 +32,7 @@
rendering = (<any>window).twttr?.widgets.createTweet(tweetId, tweetWrapper, {
conversation: "none",
theme: $themeStore.name,
theme: $currentTheme.mode,
}) as Promise<any>;
rendering
Expand Down
32 changes: 0 additions & 32 deletions frontend/app/src/components/home/profile/CommunityThemes.svelte

This file was deleted.

181 changes: 181 additions & 0 deletions frontend/app/src/components/home/profile/ThemeSelector.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<script lang="ts">
import { _ } from "svelte-i18n";
import {
preferredDarkThemeName,
preferredLightThemeName,
preferredDarkTheme,
preferredLightTheme,
themes,
themeType,
} from "../../../theme/themes";
import ChevronDown from "svelte-material-icons/ChevronDown.svelte";
import Legend from "../../Legend.svelte";
import { getContext, onMount } from "svelte";
import type { Theme } from "../../../theme/types";
import MenuIcon from "../../MenuIcon.svelte";
import Menu from "../../Menu.svelte";
import MenuItem from "../../MenuItem.svelte";
import { iconSize } from "../../../stores/iconSize";
import ButtonGroup from "../../ButtonGroup.svelte";
import Button from "../../Button.svelte";
import { AvatarSize, type OpenChat } from "openchat-client";
import Avatar from "../../Avatar.svelte";
const client = getContext<OpenChat>("client");
$: userStore = client.userStore;
type PartitionedThemes = {
light: Theme[];
dark: Theme[];
};
let lightMenu: MenuIcon;
let darkMenu: MenuIcon;
let partitionedThemes: PartitionedThemes = {
light: [],
dark: [],
};
onMount(() => {
partitionedThemes = Object.values(themes).reduce((p, theme) => {
if (theme.mode === "light") {
p.light.push(theme);
}
if (theme.mode === "dark") {
p.dark.push(theme);
}
return p;
}, partitionedThemes);
});
</script>

<div class="theme-buttons">
<ButtonGroup nowrap align="fill">
<Button on:click={() => themeType.set("system")} secondary={$themeType !== "system"}
>{$_("theme.system")}</Button>
<Button on:click={() => themeType.set("light")} secondary={$themeType !== "light"}
>{$_("theme.light")}</Button>
<Button on:click={() => themeType.set("dark")} secondary={$themeType !== "dark"}
>{$_("theme.dark")}</Button>
</ButtonGroup>
</div>

<div class="theme-selection">
<div class="theme-wrapper">
<Legend label={$_("theme.preferredLightTheme")} />
<div
tabindex="0"
role="button"
class="theme"
on:click={() => lightMenu.showMenu()}
style={`background: ${$preferredLightTheme.bg}; border-color: ${$preferredLightTheme.accent}`}>
<span style={`color: ${$preferredLightTheme.txt}`} class="theme-txt">
{$preferredLightTheme.label}
</span>

<MenuIcon bind:this={lightMenu} position="bottom" align="end">
<span class="icon" slot="icon">
<ChevronDown
viewBox={"0 -3 24 24"}
size={$iconSize}
color={`${$preferredLightTheme.accent}`} />
</span>
<span slot="menu">
<Menu>
{#each partitionedThemes.light as theme}
<MenuItem on:click={() => preferredLightThemeName.set(theme.name)}>
<div slot="text">
{theme.label}
</div>
</MenuItem>
{/each}
</Menu>
</span>
</MenuIcon>
</div>
</div>
<div class="theme-wrapper">
<Legend label={$_("theme.preferredDarkTheme")} />
<div
tabindex="0"
role="button"
class="theme"
on:click={() => darkMenu.showMenu()}
style={`background: ${$preferredDarkTheme.bg}; border-color: ${$preferredDarkTheme.accent}`}>
<span style={`color: ${$preferredDarkTheme.txt}`} class="theme-txt">
{$preferredDarkTheme.label}
</span>

<MenuIcon bind:this={darkMenu} position="bottom" align="end">
<span class="icon" slot="icon">
<ChevronDown
viewBox={"0 -3 24 24"}
size={$iconSize}
color={`${$preferredDarkTheme.accent}`} />
</span>
<span slot="menu">
<Menu>
{#each partitionedThemes.dark as theme}
<MenuItem on:click={() => preferredDarkThemeName.set(theme.name)}>
<div class="theme-item" slot="text">
<div class="label">{theme.label}</div>
{#if theme.author !== undefined && $userStore[theme.author] !== undefined}
<div class="avatar">
<Avatar
url={client.userAvatarUrl($userStore[theme.author])}
userId={theme.author}
size={AvatarSize.Tiny} />
</div>
{/if}
</div>
</MenuItem>
{/each}
</Menu>
</span>
</MenuIcon>
</div>
</div>
</div>

<style lang="scss">
:global(.theme-buttons button) {
min-width: 0 !important;
}
.theme-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: $sp3;
width: 100%;
}
.theme-buttons {
margin-bottom: $sp4;
}
.theme-selection {
display: flex;
align-items: center;
gap: $sp3;
margin-bottom: $sp4;
.theme-wrapper {
flex: 1;
}
.theme {
text-align: center;
padding: 22px;
height: 65px;
color: #fff;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
gap: $sp2;
border-bottom: $sp2 solid var(--accent);
}
}
</style>
Loading

0 comments on commit 226d763

Please sign in to comment.