This commit is contained in:
Georgi Gardev
2023-11-19 10:30:22 +02:00
parent e503facbfc
commit cb686e29ad
4 changed files with 14 additions and 20 deletions

View File

@@ -29,13 +29,13 @@ export function Search(props: SearchProps) {
return provider || defaultProvider();
});
const searchTerm = createMemo(() => {
const searchTerm = () => {
if (!props.term().startsWith('!')) {
return props.term();
}
return props.term().split(`!${activeProvider()?.prefix} `)[1];
});
};
return (
<div>

View File

@@ -9,8 +9,8 @@ import style from './Weather.module.css';
export function Weather() {
const weather = createWeather();
const sunrise = createMemo(() => getTime((weather()?.sunrise ?? 0) * 1000));
const sunset = createMemo(() => getTime((weather()?.sunset ?? 0) * 1000));
const sunrise = () => getTime((weather()?.sunrise ?? 0) * 1000);
const sunset = () => getTime((weather()?.sunset ?? 0) * 1000);
return (
<div class={style.Weather}>

View File

@@ -17,8 +17,9 @@ export default function Home() {
const { activeCategory, selectCategory, resetCategory } = createActiveCategory();
const shouldSearchLocally = () => searchTerm() && !searchTerm().startsWith('!');
const searchResults = createMemo(() => {
if (!searchTerm() || searchTerm().startsWith('!')) {
if (!shouldSearchLocally()) {
return [];
}
@@ -60,18 +61,12 @@ export default function Home() {
}
}
const activeCategoryApps = createMemo(
() => categories()?.find((c) => c.name === activeCategory())?.apps ?? []
);
const activeCategoryName = createMemo(
() => categories()?.find((c) => c.name === activeCategory())?.name ?? ''
);
const activeCategoryDef = () => categories()?.find((c) => c.name === activeCategory());
return (
<main class={style.SidebarPage}>
<Sidebar
categories={createMemo(() => categories()?.flatMap((c) => c.name))}
categories={() => categories()?.flatMap((c) => c.name)}
selectCategory={selectCategory}
activeCategory={activeCategory()}
/>
@@ -79,8 +74,8 @@ export default function Home() {
<div class={style.Widgets}>
{activeCategory() ? (
<AppList
category={activeCategoryName}
apps={activeCategoryApps}
category={() => activeCategoryDef()?.name ?? ''}
apps={() => activeCategoryDef()?.apps ?? []}
resetCategory={resetCategory}
/>
) : (
@@ -93,7 +88,7 @@ export default function Home() {
canOpenApp={searchResults().length > 0}
onOpenApp={() => window.open(searchResults()[0].url)}
/>
{searchTerm() ? (
{shouldSearchLocally() ? (
<AppList
category={() => 'search results'}
apps={searchResults}

View File

@@ -42,11 +42,10 @@ export function SettingsProvider(props: { children: JSX.Element }) {
onUnfavoriteBackground,
} = createBackgrounds();
const currentBackground = createMemo(() =>
appSettings.useSavedBackgrounds ? sample(favoriteBackgrounds) : currentRandomBackground()
);
const currentBackground = () =>
appSettings.useSavedBackgrounds ? sample(favoriteBackgrounds) : currentRandomBackground();
const isCurrentBackgroundSaved = createMemo(() => isBackgroundSaved(currentBackground()?.id));
const isCurrentBackgroundSaved = () => isBackgroundSaved(currentBackground()?.id);
const onUnfavoriteCurrentBackground = () =>
currentBackground() && onUnfavoriteBackground(currentBackground()!.id);