fix data loading

This commit is contained in:
Georgi Gardev
2023-11-18 16:26:08 +02:00
parent b0063a90e7
commit e177abef1b
8 changed files with 62 additions and 21 deletions
+17 -4
View File
@@ -1,8 +1,21 @@
FROM node:18-alpine FROM node:18-alpine
ARG VITE_OPEN_WEATHER_KEY
ARG VITE_OPEN_WEATHER_LAT
ARG VITE_OPEN_WEATHER_LON
ENV VITE_OPEN_WEATHER_KEY=$VITE_OPEN_WEATHER_KEY
ENV VITE_OPEN_WEATHER_LAT=$VITE_OPEN_WEATHER_LAT
ENV VITE_OPEN_WEATHER_LON=$VITE_OPEN_WEATHER_LON
WORKDIR /app WORKDIR /app
COPY package.json . COPY package*.json .
RUN npm install RUN npm install
COPY . .
RUN npm run build COPY public ./public
COPY src ./src
COPY tsconfig.json .
COPY vite.config.ts .
CMD ["npm", "run", "dev"]
EXPOSE 3000 EXPOSE 3000
CMD ["npm", "start"]
+2
View File
@@ -8,3 +8,5 @@ services:
- "3000:3000" - "3000:3000"
volumes: volumes:
- ./data:/app/data/ - ./data:/app/data/
env_file:
- .env
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "gardev-startpage", "name": "gardev-startpage",
"scripts": { "scripts": {
"dev": "solid-start dev", "dev": "solid-start dev --host 0.0.0.0",
"build": "solid-start build", "build": "solid-start build",
"start": "solid-start start" "start": "solid-start start"
}, },
+20
View File
@@ -0,0 +1,20 @@
import { createResource, lazy } from 'solid-js';
import { AppDefinition } from '~/types';
async function getApps(): Promise<AppDefinition[]> {
return await import('../../data/apps.json').then((m) => m.default);
}
export function createApps() {
const [apps] = createResource<AppDefinition[]>(getApps);
return apps;
}
export async function getTagOrder(): Promise<string[]> {
return await import('../../data/tag-order.json').then((m) => m.default);
}
export function createTagOrder() {
const [tagOrder] = createResource<string[]>(getTagOrder);
return tagOrder;
}
+4 -3
View File
@@ -1,9 +1,9 @@
import { groupBy } from 'ramda'; import { groupBy } from 'ramda';
import { Accessor } from 'solid-js';
import { createTagOrder } from '~/api/get-apps';
import { AppDefinition } from '~/types'; import { AppDefinition } from '~/types';
import tagOrder from '../../../data/tag-order.json';
import { Pill } from './Pill'; import { Pill } from './Pill';
import { Accessor } from 'solid-js';
import style from './AppList.module.css'; import style from './AppList.module.css';
export function AppList({ export function AppList({
@@ -15,6 +15,7 @@ export function AppList({
tag?: Accessor<string | null>; tag?: Accessor<string | null>;
resetTag?(): void; resetTag?(): void;
}) { }) {
const tagOrder = createTagOrder();
const grouped = groupBy((app) => app.tags, apps); const grouped = groupBy((app) => app.tags, apps);
return ( return (
@@ -34,7 +35,7 @@ export function AppList({
</div> </div>
</div> </div>
) : ( ) : (
tagOrder.map((tag) => ( tagOrder()?.map((tag) => (
<div> <div>
<h2 class={style.Header}>{tag}</h2> <h2 class={style.Header}>{tag}</h2>
<div class={style.AppList}> <div class={style.AppList}>
+8 -4
View File
@@ -1,13 +1,14 @@
import { Anchor, Tag, TagProps } from '@hope-ui/solid'; import { Tag, TagProps } from '@hope-ui/solid';
import { getAppIcon } from '~/api/get-app-icon';
import { createTagOrder } from '~/api/get-apps';
import { useSettings } from '~/state/SettingsProvider'; import { useSettings } from '~/state/SettingsProvider';
import { AppDefinition } from '~/types'; import { AppDefinition } from '~/types';
import tagOrder from '../../../data/tag-order.json';
import { getAppIcon } from '~/api/get-app-icon';
import style from './AppTable.module.css'; import style from './AppTable.module.css';
export function AppTable({ apps }: { apps: AppDefinition[] }) { export function AppTable({ apps }: { apps: AppDefinition[] }) {
const { appSettings } = useSettings(); const { appSettings } = useSettings();
const tagOrder = createTagOrder();
const TAG_TO_COLOR: Record<string, TagProps['colorScheme']> = { const TAG_TO_COLOR: Record<string, TagProps['colorScheme']> = {
media: 'primary', media: 'primary',
@@ -31,7 +32,10 @@ export function AppTable({ apps }: { apps: AppDefinition[] }) {
</thead> </thead>
<tbody> <tbody>
{apps {apps
.sort((tagA, tagB) => tagOrder.indexOf(tagA.tags) - tagOrder.indexOf(tagB.tags)) .sort(
(tagA, tagB) =>
(tagOrder()?.indexOf(tagA.tags) ?? 0) - (tagOrder()?.indexOf(tagB.tags) ?? 0)
)
.map((app) => ( .map((app) => (
<tr> <tr>
<td> <td>
+4 -3
View File
@@ -1,5 +1,4 @@
import tagOrder from '../../../data/tag-order.json'; import { createTagOrder } from '~/api/get-apps';
import style from './Sidebar.module.css'; import style from './Sidebar.module.css';
type SidebarProps = { type SidebarProps = {
@@ -7,10 +6,12 @@ type SidebarProps = {
}; };
export function Sidebar(props: SidebarProps) { export function Sidebar(props: SidebarProps) {
const tagOrder = createTagOrder();
return ( return (
<div class={style.Sidebar}> <div class={style.Sidebar}>
<ul class={style.Menu}> <ul class={style.Menu}>
{tagOrder.map((tag) => ( {tagOrder()?.map((tag) => (
<li <li
onClick={() => props.onSelectTag?.(tag)} onClick={() => props.onSelectTag?.(tag)}
onMouseEnter={() => props.onSelectTag?.(tag)} onMouseEnter={() => props.onSelectTag?.(tag)}
+6 -6
View File
@@ -1,13 +1,11 @@
import { createSignal, onCleanup, onMount } from 'solid-js'; import { createSignal, onCleanup, onMount } from 'solid-js';
import { createApps } from '~/api/get-apps';
import { AppList } from '~/components/apps/AppList';
import { DateView } from '~/components/widgets/Date'; import { DateView } from '~/components/widgets/Date';
import { Search } from '~/components/widgets/Search'; import { Search } from '~/components/widgets/Search';
import { Weather } from '~/components/widgets/Weather'; import { Weather } from '~/components/widgets/Weather';
import data from '../../data/apps.json';
import { Sidebar } from '../components/ui/Sidebar'; import { Sidebar } from '../components/ui/Sidebar';
import { AppList } from '~/components/apps/AppList';
import style from './index.module.css'; import style from './index.module.css';
import { HiOutlineXCircle, HiSolidXCircle } from 'solid-icons/hi';
export default function Home() { export default function Home() {
onMount(() => { onMount(() => {
@@ -18,6 +16,8 @@ export default function Home() {
parent.removeEventListener('keydown', handleKeypress); parent.removeEventListener('keydown', handleKeypress);
}); });
const apps = createApps();
const [activeTag, setActiveTag] = createSignal<string | null>(null); const [activeTag, setActiveTag] = createSignal<string | null>(null);
const [timeout, storeTimeout] = createSignal<NodeJS.Timeout | null>(null); const [timeout, storeTimeout] = createSignal<NodeJS.Timeout | null>(null);
@@ -47,7 +47,7 @@ export default function Home() {
} }
default: { default: {
if (document.activeElement?.id !== 'search') { if (document.activeElement?.id !== 'search') {
const app = data.find((app) => app.shortcut === e.key); const app = apps()?.find((app) => app.shortcut === e.key);
if (app) { if (app) {
window.open(app.url); window.open(app.url);
@@ -63,7 +63,7 @@ export default function Home() {
<div class={style.ContentWrapper}> <div class={style.ContentWrapper}>
<div class={style.Widgets}> <div class={style.Widgets}>
{activeTag() ? ( {activeTag() ? (
<AppList apps={data} tag={activeTag} resetTag={resetTag} /> <AppList apps={apps() ?? []} tag={activeTag} resetTag={resetTag} />
) : ( ) : (
<> <>
<Search /> <Search />