add ability to move cards
images / check (push) Successful in 30s
images / image (push) Successful in 21s

This commit is contained in:
2026-11-19 18:07:50 +01:00
parent dacd374946
commit 5001cae163
19 changed files with 1197 additions and 57 deletions
+12
View File
@@ -0,0 +1,12 @@
# Default ignored files
/shelf/
/workspace.xml
# Markdown personal settings
/markdown.xml
# Editor-based HTTP Client requests
/httpRequests/
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+60
View File
@@ -0,0 +1,60 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="LINE_SEPARATOR" value="&#10;" />
<HTMLCodeStyleSettings>
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
</HTMLCodeStyleSettings>
<JSCodeStyleSettings version="0">
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</JSCodeStyleSettings>
<TypeScriptCodeStyleSettings version="0">
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</TypeScriptCodeStyleSettings>
<VueCodeStyleSettings>
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
</VueCodeStyleSettings>
<codeStyleSettings language="HTML">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JavaScript">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="TypeScript">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="Vue">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>
+5
View File
@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+6
View File
@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/dahoam.iml" filepath="$PROJECT_DIR$/.idea/dahoam.iml" />
</modules>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PrettierConfiguration">
<option name="myConfigurationMode" value="AUTOMATIC" />
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
+3 -2
View File
@@ -99,13 +99,14 @@ scripts/sync-collabry.sh copies them from upstream at a pinned commit
`dashboard`, the `wallpaper` table is keyed by dashboard (migration `0007_dashboard_wallpaper` `dashboard`, the `wallpaper` table is keyed by dashboard (migration `0007_dashboard_wallpaper`
copies what each user had to all their dashboards). `/settings?d=<id>` is the dashboard whose copies what each user had to all their dashboards). `/settings?d=<id>` is the dashboard whose
wallpaper is shown, and where "Back to dashboard" goes. wallpaper is shown, and where "Back to dashboard" goes.
- [x] 16. Cards are dragged by their title bar: `card.position` (migration `0008_card_position`),
`saveLayout` (was `moveLinks`) stores the order of the cards and of their links.
## Not doing (not asked) ## Not doing (not asked)
- Unraid version/uptime chip and the Sonarr/Plex notification pills from the screenshot - Unraid version/uptime chip and the Sonarr/Plex notification pills from the screenshot
- Inline SearXNG result rendering (search opens the engine's result page) - Inline SearXNG result rendering (search opens the engine's result page)
- Reordering the cards themselves (they stay in the order they were made), free placement with - Free placement of cards with gaps in the grid, per-user SearXNG URL (SSRF risk — it is a server env)
gaps in the grid, per-user SearXNG URL (SSRF risk — it is a server env)
- Per dashboard clock or search engine (they stay per user), moving a card to another dashboard, - Per dashboard clock or search engine (they stay per user), moving a card to another dashboard,
reordering dashboards, remembering the last opened dashboard (the default opens) reordering dashboards, remembering the last opened dashboard (the default opens)
- A list of the icons a user uploaded, to use one again for another link - A list of the icons a user uploaded, to use one again for another link
+2
View File
@@ -64,6 +64,8 @@ Build it yourself: `docker build -t dahoam .`
edit or delete it. edit or delete it.
- **Move links** by dragging, inside a card or to another card. Touch: press and hold first. - **Move links** by dragging, inside a card or to another card. Touch: press and hold first.
Keyboard: focus a link, Space picks it up, arrow keys move it, Space puts it down. Keyboard: focus a link, Space picks it up, arrow keys move it, Space puts it down.
- **Move cards** by dragging their title bar, the links come along. Touch: press and hold
first. Keyboard: Space on the grip next to the plus, arrow keys, Space.
- **Icons**: leave the field empty and the icon is looked up by name in - **Icons**: leave the field empty and the icon is looked up by name in
[dashboard-icons](https://github.com/homarr-labs/dashboard-icons), then from the [dashboard-icons](https://github.com/homarr-labs/dashboard-icons), then from the
site's `/favicon.ico`. Or type in the field to search that library and click an icon, site's `/favicon.ico`. Or type in the field to search that library and click an icon,
+1
View File
@@ -0,0 +1 @@
ALTER TABLE "card" ADD COLUMN "position" integer DEFAULT 0 NOT NULL;
+909
View File
@@ -0,0 +1,909 @@
{
"id": "eddd02da-41ed-40a6-b0b0-e5976ea2c371",
"prevId": "c89fef31-f0cf-4f87-8683-df4f9eb49fa8",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.account": {
"name": "account",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"account_id": {
"name": "account_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"provider_id": {
"name": "provider_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"access_token": {
"name": "access_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"refresh_token": {
"name": "refresh_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"id_token": {
"name": "id_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"access_token_expires_at": {
"name": "access_token_expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"refresh_token_expires_at": {
"name": "refresh_token_expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"scope": {
"name": "scope",
"type": "text",
"primaryKey": false,
"notNull": false
},
"password": {
"name": "password",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"account_user_id_idx": {
"name": "account_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"account_user_id_user_id_fk": {
"name": "account_user_id_user_id_fk",
"tableFrom": "account",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.card": {
"name": "card",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"dashboard_id": {
"name": "dashboard_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"position": {
"name": "position",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"card_user_id_idx": {
"name": "card_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"card_dashboard_id_idx": {
"name": "card_dashboard_id_idx",
"columns": [
{
"expression": "dashboard_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"card_user_id_user_id_fk": {
"name": "card_user_id_user_id_fk",
"tableFrom": "card",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"card_dashboard_id_dashboard_id_fk": {
"name": "card_dashboard_id_dashboard_id_fk",
"tableFrom": "card",
"tableTo": "dashboard",
"columnsFrom": [
"dashboard_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.dashboard": {
"name": "dashboard",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"wallpaper_url": {
"name": "wallpaper_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"wallpaper_dim": {
"name": "wallpaper_dim",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 40
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"dashboard_user_id_idx": {
"name": "dashboard_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"dashboard_user_id_user_id_fk": {
"name": "dashboard_user_id_user_id_fk",
"tableFrom": "dashboard",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.icon": {
"name": "icon",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"mime": {
"name": "mime",
"type": "text",
"primaryKey": false,
"notNull": true
},
"data": {
"name": "data",
"type": "bytea",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"icon_user_id_idx": {
"name": "icon_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"icon_user_id_user_id_fk": {
"name": "icon_user_id_user_id_fk",
"tableFrom": "icon",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.link": {
"name": "link",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"card_id": {
"name": "card_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"position": {
"name": "position",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"link_user_id_idx": {
"name": "link_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"link_card_id_idx": {
"name": "link_card_id_idx",
"columns": [
{
"expression": "card_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"link_user_id_user_id_fk": {
"name": "link_user_id_user_id_fk",
"tableFrom": "link",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"link_card_id_card_id_fk": {
"name": "link_card_id_card_id_fk",
"tableFrom": "link",
"tableTo": "card",
"columnsFrom": [
"card_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.session": {
"name": "session",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"expires_at": {
"name": "expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"token": {
"name": "token",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"ip_address": {
"name": "ip_address",
"type": "text",
"primaryKey": false,
"notNull": false
},
"user_agent": {
"name": "user_agent",
"type": "text",
"primaryKey": false,
"notNull": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {
"session_user_id_idx": {
"name": "session_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"session_user_id_user_id_fk": {
"name": "session_user_id_user_id_fk",
"tableFrom": "session",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"session_token_unique": {
"name": "session_token_unique",
"nullsNotDistinct": false,
"columns": [
"token"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.settings": {
"name": "settings",
"schema": "",
"columns": {
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'Dahoam'"
},
"default_dashboard_id": {
"name": "default_dashboard_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"search_engine": {
"name": "search_engine",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'duckduckgo'"
},
"clock_font": {
"name": "clock_font",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'serif'"
},
"clock_style": {
"name": "clock_style",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'solid'"
}
},
"indexes": {},
"foreignKeys": {
"settings_user_id_user_id_fk": {
"name": "settings_user_id_user_id_fk",
"tableFrom": "settings",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"settings_default_dashboard_id_dashboard_id_fk": {
"name": "settings_default_dashboard_id_dashboard_id_fk",
"tableFrom": "settings",
"tableTo": "dashboard",
"columnsFrom": [
"default_dashboard_id"
],
"columnsTo": [
"id"
],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user": {
"name": "user",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email_verified": {
"name": "email_verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"image": {
"name": "image",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"user_email_unique": {
"name": "user_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.verification": {
"name": "verification",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"identifier": {
"name": "identifier",
"type": "text",
"primaryKey": false,
"notNull": true
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true
},
"expires_at": {
"name": "expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"verification_identifier_idx": {
"name": "verification_identifier_idx",
"columns": [
{
"expression": "identifier",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.wallpaper": {
"name": "wallpaper",
"schema": "",
"columns": {
"dashboard_id": {
"name": "dashboard_id",
"type": "uuid",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"mime": {
"name": "mime",
"type": "text",
"primaryKey": false,
"notNull": true
},
"data": {
"name": "data",
"type": "bytea",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"wallpaper_dashboard_id_dashboard_id_fk": {
"name": "wallpaper_dashboard_id_dashboard_id_fk",
"tableFrom": "wallpaper",
"tableTo": "dashboard",
"columnsFrom": [
"dashboard_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"wallpaper_user_id_user_id_fk": {
"name": "wallpaper_user_id_user_id_fk",
"tableFrom": "wallpaper",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
+7
View File
@@ -57,6 +57,13 @@
"when": 1795021173823, "when": 1795021173823,
"tag": "0007_dashboard_wallpaper", "tag": "0007_dashboard_wallpaper",
"breakpoints": true "breakpoints": true
},
{
"idx": 8,
"version": "7",
"when": 1795106775546,
"tag": "0008_card_position",
"breakpoints": true
} }
] ]
} }
+110 -44
View File
@@ -8,7 +8,6 @@ import {
TouchSensor, TouchSensor,
closestCenter, closestCenter,
pointerWithin, pointerWithin,
useDroppable,
useSensor, useSensor,
useSensors, useSensors,
} from "@dnd-kit/core" } from "@dnd-kit/core"
@@ -21,13 +20,14 @@ import {
SortableContext, SortableContext,
rectSortingStrategy, rectSortingStrategy,
sortableKeyboardCoordinates, sortableKeyboardCoordinates,
useSortable,
} from "@dnd-kit/sortable" } from "@dnd-kit/sortable"
import { Plus } from "lucide-react" import { GripVertical, Plus } from "lucide-react"
import { glass } from "@/components/glass" import { glass } from "@/components/glass"
import { LinkTile, TileFace } from "@/components/link-tile" import { LinkTile, TileFace } from "@/components/link-tile"
import type { HomeLink } from "@/components/link-tile" import type { HomeLink } from "@/components/link-tile"
import { moveLinks } from "@/lib/dashboard.functions" import { saveLayout } from "@/lib/dashboard.functions"
import { drop, moveOver, order } from "@/lib/layout" import { drop, moveCard, moveOver, order } from "@/lib/layout"
import { Button } from "@/vendor/collabry/components/Button/Button" import { Button } from "@/vendor/collabry/components/Button/Button"
import { cn } from "@/vendor/collabry/lib/cn" import { cn } from "@/vendor/collabry/lib/cn"
@@ -39,20 +39,25 @@ type Handlers = {
onEditCard: (card: DashCard) => void onEditCard: (card: DashCard) => void
} }
/** The cards with their links. Links can be dragged inside a card and between cards. */ /**
* The cards with their links. Links can be dragged inside a card and between cards,
* cards by their title bar.
*/
export function CardGrid({ export function CardGrid({
cards: saved, cards: saved,
onAddCard, onAddCard,
...handlers ...handlers
}: { cards: DashCard[]; onAddCard: () => void } & Handlers) { }: { cards: DashCard[]; onAddCard: () => void } & Handlers) {
const router = useRouter() const router = useRouter()
// the layout while a link is dragged, and until the server has stored it // the layout while a link or a card is dragged, and until the server has stored it
const [dragged, setDragged] = useState<DashCard[] | null>(null) const [dragged, setDragged] = useState<DashCard[] | null>(null)
const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null) const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null)
const drags = useRef(0) const drags = useRef(0)
const cards = dragged ?? saved const cards = dragged ?? saved
const links = cards.flatMap((c) => c.links) const links = cards.flatMap((c) => c.links)
const active = links.find((l) => l.id === activeId) const active = links.find((l) => l.id === activeId)
const activeCard = cards.find((c) => c.id === activeId)
const isCard = (id: UniqueIdentifier) => cards.some((c) => c.id === id)
const sensors = useSensors( const sensors = useSensors(
// a few pixels of slack, so a plain click still opens the link // a few pixels of slack, so a plain click still opens the link
@@ -82,10 +87,17 @@ export function CardGrid({
), ),
}) })
const cardArgs = only(cards.map((c) => c.id)) const cardArgs = only(cards.map((c) => c.id))
// the keyboard has no pointer: take the nearest card then const dragsCard = isCard(args.active.id)
const hit = pointerWithin(cardArgs).at(0) ?? closestCenter(cardArgs).at(0) // The keyboard has no pointer: take the nearest card then. A dragged card waits
// while the pointer is between cards: the nearest one could swap it back and forth.
const hit =
pointerWithin(cardArgs).at(0) ??
(dragsCard && args.pointerCoordinates
? undefined
: closestCenter(cardArgs).at(0))
const card = cards.find((c) => c.id === hit?.id) const card = cards.find((c) => c.id === hit?.id)
if (!hit || !card) return [] if (!hit || !card) return []
if (dragsCard) return [hit]
const nearest = closestCenter(only(card.links.map((l) => l.id))) const nearest = closestCenter(only(card.links.map((l) => l.id)))
return nearest.length ? nearest : [hit] return nearest.length ? nearest : [hit]
} }
@@ -97,7 +109,7 @@ export function CardGrid({
setDragged(next) setDragged(next)
const drag = drags.current const drag = drags.current
// on failure the reload below puts the links back where they were // on failure the reload below puts the links back where they were
await moveLinks({ data: { cards: order(next) } }).catch(() => {}) await saveLayout({ data: { cards: order(next) } }).catch(() => {})
await router.invalidate() await router.invalidate()
// a newer drag owns the layout by now // a newer drag owns the layout by now
if (drags.current === drag) setDragged(null) if (drags.current === drag) setDragged(null)
@@ -110,12 +122,18 @@ export function CardGrid({
cards.find((c) => c.id === id || c.links.some((l) => l.id === id))?.name cards.find((c) => c.id === id || c.links.some((l) => l.id === id))?.name
const announcements: Announcements = { const announcements: Announcements = {
onDragStart: ({ active: a }) => `Picked up ${name(a.id)}.`, onDragStart: ({ active: a }) => `Picked up ${name(a.id)}.`,
onDragOver: ({ active: a, over }) => onDragOver: ({ active: a, over }) => {
over ? `${name(a.id)} is in ${cardName(over.id)}.` : undefined, if (!over || over.id === a.id) return
return isCard(a.id)
? `${name(a.id)} took the place of ${name(over.id)}.`
: `${name(a.id)} is in ${cardName(over.id)}.`
},
onDragEnd: ({ active: a, over }) => onDragEnd: ({ active: a, over }) =>
over isCard(a.id)
? `${name(a.id)} was put down in ${cardName(over.id)}.` ? `${name(a.id)} was put down.`
: `${name(a.id)} was put back.`, : over
? `${name(a.id)} was put down in ${cardName(over.id)}.`
: `${name(a.id)} was put back.`,
onDragCancel: ({ active: a }) => `${name(a.id)} was put back.`, onDragCancel: ({ active: a }) => `${name(a.id)} was put back.`,
} }
@@ -132,7 +150,10 @@ export function CardGrid({
setDragged(cards) setDragged(cards)
}} }}
onDragOver={({ active: a, over }) => { onDragOver={({ active: a, over }) => {
if (over) setDragged(moveOver(cards, String(a.id), String(over.id))) if (!over) return
// each of the two leaves the other kind of drag alone
const [id, overId] = [String(a.id), String(over.id)]
setDragged(moveCard(moveOver(cards, id, overId), id, overId))
}} }}
onDragEnd={({ active: a, over }) => onDragEnd={({ active: a, over }) =>
finish(over ? drop(cards, String(a.id), String(over.id)) : cards) finish(over ? drop(cards, String(a.id), String(over.id)) : cards)
@@ -142,18 +163,22 @@ export function CardGrid({
setDragged(null) setDragged(null)
}} }}
> >
{/* cards in a row share a height, so their edges line up */} {/* A dragged card moves in the list itself (onDragOver), so no strategy shifts
<div className="flex w-full max-w-6xl flex-wrap justify-center gap-4"> the others: cards differ in size, and a shifted one would not fit its slot. */}
{cards.map((card) => ( <SortableContext items={cards.map((c) => c.id)} strategy={() => null}>
<CardPanel {/* cards in a row share a height, so their edges line up */}
key={card.id} <div className="flex w-full max-w-6xl flex-wrap justify-center gap-4">
card={card} {cards.map((card) => (
// the card the dragged link would land in <CardPanel
target={card.links.some((l) => l.id === activeId)} key={card.id}
{...handlers} card={card}
/> // the card the dragged link would land in
))} target={card.links.some((l) => l.id === activeId)}
</div> {...handlers}
/>
))}
</div>
</SortableContext>
<Button <Button
variant="ghost" variant="ghost"
className="mt-4 rounded-full text-white/60 hover:bg-white/10 hover:text-white" className="mt-4 rounded-full text-white/60 hover:bg-white/10 hover:text-white"
@@ -162,17 +187,46 @@ export function CardGrid({
<Plus className="size-4" /> New card <Plus className="size-4" /> New card
</Button> </Button>
<DragOverlay> <DragOverlay>
{active && ( {/* one expression: an array of two empty ones would still count as a child */}
{active ? (
<TileFace <TileFace
link={active} link={active}
className="cursor-grabbing rounded-2xl bg-white/15 shadow-2xl" className="cursor-grabbing rounded-2xl bg-white/15 shadow-2xl"
/> />
) : (
activeCard && <CardFace card={activeCard} />
)} )}
</DragOverlay> </DragOverlay>
</DndContext> </DndContext>
) )
} }
// 6rem is a tile's width. On a narrow screen fewer columns fit: they stay
// centered in the card, and a last row that is not full starts at the left.
const tiles =
"mx-auto grid max-w-full grid-cols-[repeat(auto-fill,6rem)] justify-center gap-y-2"
/** One column per link, at most 8. An empty card is as wide as two links. */
const tilesWidth = (card: DashCard) => ({
width: `${(Math.min(card.links.length, 8) || 2) * 6}rem`,
})
/** What follows the pointer while a card is dragged: the card without its buttons. */
function CardFace({ card }: { card: DashCard }) {
return (
// the overlay is as large as the card, h-full fills it for an empty card too
<div className={cn(glass, "h-full cursor-grabbing rounded-3xl p-2")}>
<div className="h-10 truncate pr-3.5 pl-5 text-sm leading-10 font-bold text-white/70">
{card.name}
</div>
<div style={tilesWidth(card)} className={tiles}>
{card.links.map((link) => (
<TileFace key={link.id} link={link} />
))}
</div>
</div>
)
}
function CardPanel({ function CardPanel({
card, card,
target, target,
@@ -181,11 +235,16 @@ function CardPanel({
onEditCard, onEditCard,
}: { card: DashCard; target: boolean } & Handlers) { }: { card: DashCard; target: boolean } & Handlers) {
const titleId = useId() const titleId = useId()
const { setNodeRef } = useDroppable({ id: card.id }) // `card` tells the link tiles that a card is dragged, see LinkTile
// one column per link, at most 8. An empty card is as wide as two links. const { setNodeRef, setActivatorNodeRef, attributes, listeners, isDragging } =
const columns = Math.min(card.links.length, 8) || 2 useSortable({ id: card.id, data: { card: true } })
const subtle = const subtle =
"rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-white/60" "rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-white/60"
// shown on hover, always on touch
const action = cn(
subtle,
"grid size-7 flex-none place-items-center text-white/70 opacity-0 transition-opacity group-hover/card:opacity-100 hover:bg-white/10 hover:text-white focus-visible:opacity-100 pointer-coarse:opacity-100"
)
return ( return (
<section <section
ref={setNodeRef} ref={setNodeRef}
@@ -193,11 +252,16 @@ function CardPanel({
className={cn( className={cn(
glass, glass,
"group/card max-w-full rounded-3xl p-2 transition-colors", "group/card max-w-full rounded-3xl p-2 transition-colors",
target && "border-white/30" target && "border-white/30",
isDragging && "opacity-40"
)} )}
> >
{/* the title starts where the first icon does, the plus ends where the last one does */} {/* The title starts where the first icon does, the plus ends where the last one does.
<header className="flex h-10 min-w-48 items-center gap-2 pr-3.5 pl-5"> The whole bar drags the card. The keyboard picks it up on the grip only. */}
<header
{...listeners}
className="flex h-10 min-w-48 cursor-grab touch-manipulation items-center gap-2 pr-3.5 pl-5 select-none [-webkit-touch-callout:none]"
>
<h2 id={titleId} className="m-0 min-w-0 text-sm"> <h2 id={titleId} className="m-0 min-w-0 text-sm">
<button <button
type="button" type="button"
@@ -211,14 +275,21 @@ function CardPanel({
{card.name} {card.name}
</button> </button>
</h2> </h2>
<button
type="button"
ref={setActivatorNodeRef}
{...attributes}
aria-label={`Move ${card.name}`}
title="Drag to move this card"
className={cn(action, "ml-auto cursor-grab")}
>
<GripVertical className="size-4" />
</button>
<button <button
type="button" type="button"
aria-label={`Add a link to ${card.name}`} aria-label={`Add a link to ${card.name}`}
onClick={() => onAddLink(card)} onClick={() => onAddLink(card)}
className={cn( className={action}
subtle,
"ml-auto grid size-7 flex-none place-items-center text-white/70 opacity-0 transition-opacity group-hover/card:opacity-100 hover:bg-white/10 hover:text-white focus-visible:opacity-100 pointer-coarse:opacity-100"
)}
> >
<Plus className="size-4" /> <Plus className="size-4" />
</button> </button>
@@ -227,12 +298,7 @@ function CardPanel({
items={card.links.map((l) => l.id)} items={card.links.map((l) => l.id)}
strategy={rectSortingStrategy} strategy={rectSortingStrategy}
> >
{/* 6rem is a tile's width. On a narrow screen fewer columns fit: they stay <div style={tilesWidth(card)} className={tiles}>
centered in the card, and a last row that is not full starts at the left. */}
<div
style={{ width: `${columns * 6}rem` }}
className="mx-auto grid max-w-full grid-cols-[repeat(auto-fill,6rem)] justify-center gap-y-2"
>
{card.links.map((link) => ( {card.links.map((link) => (
<LinkTile <LinkTile
key={link.id} key={link.id}
+4 -1
View File
@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from "react" import { useEffect, useRef, useState } from "react"
import { useDndContext } from "@dnd-kit/core"
import { useSortable } from "@dnd-kit/sortable" import { useSortable } from "@dnd-kit/sortable"
import { CSS } from "@dnd-kit/utilities" import { CSS } from "@dnd-kit/utilities"
import { Pencil } from "lucide-react" import { Pencil } from "lucide-react"
@@ -85,6 +86,8 @@ export function LinkTile({
link: HomeLink link: HomeLink
onEdit: () => void onEdit: () => void
}) { }) {
// while a card is dragged, the arrow keys go from card to card, not through the links
const cardDragged = !!useDndContext().active?.data.current?.card
const { const {
attributes, attributes,
listeners, listeners,
@@ -92,7 +95,7 @@ export function LinkTile({
transform, transform,
transition, transition,
isDragging, isDragging,
} = useSortable({ id: link.id }) } = useSortable({ id: link.id, disabled: { droppable: cardDragged } })
return ( return (
<div <div
ref={setNodeRef} ref={setNodeRef}
+2
View File
@@ -106,6 +106,8 @@ export const card = pgTable(
dashboardId: uuid("dashboard_id") dashboardId: uuid("dashboard_id")
.notNull() .notNull()
.references(() => dashboard.id, { onDelete: "cascade" }), .references(() => dashboard.id, { onDelete: "cascade" }),
// order on the dashboard
position: integer("position").notNull().default(0),
name: text("name").notNull(), name: text("name").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(), createdAt: timestamp("created_at").notNull().defaultNow(),
}, },
+19 -7
View File
@@ -85,7 +85,8 @@ export const getDashboard = createServerFn({ method: "GET" })
.select({ id: card.id, name: card.name }) .select({ id: card.id, name: card.name })
.from(card) .from(card)
.where(and(eq(card.userId, userId), eq(card.dashboardId, dashboardId))) .where(and(eq(card.userId, userId), eq(card.dashboardId, dashboardId)))
.orderBy(asc(card.createdAt)), // cards that were never moved all have position 0: oldest first
.orderBy(asc(card.position), asc(card.createdAt)),
db db
.select({ .select({
id: link.id, id: link.id,
@@ -173,7 +174,13 @@ export const saveCard = createServerFn({ method: "POST" })
.where(and(eq(card.id, id), eq(card.userId, user.id))) .where(and(eq(card.id, id), eq(card.userId, user.id)))
} else { } else {
await requireDashboard(user.id, dashboardId) await requireDashboard(user.id, dashboardId)
await db.insert(card).values({ name, dashboardId, userId: user.id }) await db.insert(card).values({
name,
dashboardId,
userId: user.id,
// after the last card of the dashboard
position: sql`(select coalesce(max(${card.position}) + 1, 0) from ${card} where ${card.dashboardId} = ${dashboardId})`,
})
} }
}) })
@@ -217,8 +224,8 @@ export const deleteCard = createServerFn({ method: "POST" })
.where(and(eq(card.id, data.id), eq(card.userId, user.id))) .where(and(eq(card.id, data.id), eq(card.userId, user.id)))
}) })
/** Stores the result of a drag: for each card, its links in order. */ /** Stores the result of a drag: the cards in order and, for each card, its links in order. */
export const moveLinks = createServerFn({ method: "POST" }) export const saveLayout = createServerFn({ method: "POST" })
.validator( .validator(
z.object({ z.object({
cards: z cards: z
@@ -234,15 +241,20 @@ export const moveLinks = createServerFn({ method: "POST" })
.from(card) .from(card)
.where(and(eq(card.userId, user.id), inArray(card.id, cardIds))) .where(and(eq(card.userId, user.id), inArray(card.id, cardIds)))
if (owned.length !== cardIds.length) throw new Error("Unknown card") if (owned.length !== cardIds.length) throw new Error("Unknown card")
// shortcut: one UPDATE per link, fine for a few hundred links; switch to a // shortcut: one UPDATE per card and link, fine for a few hundred links; switch
// single UPDATE ... FROM (VALUES ...) if a save gets slow // to a single UPDATE ... FROM (VALUES ...) if a save gets slow
await db.transaction(async (tx) => { await db.transaction(async (tx) => {
for (const c of data.cards) for (const [at, c] of data.cards.entries()) {
await tx
.update(card)
.set({ position: at })
.where(and(eq(card.id, c.id), eq(card.userId, user.id)))
for (const [position, id] of c.linkIds.entries()) for (const [position, id] of c.linkIds.entries())
await tx await tx
.update(link) .update(link)
.set({ cardId: c.id, position }) .set({ cardId: c.id, position })
.where(and(eq(link.id, id), eq(link.userId, user.id))) .where(and(eq(link.id, id), eq(link.userId, user.id)))
}
}) })
}) })
+13 -1
View File
@@ -1,6 +1,6 @@
import assert from "node:assert/strict" import assert from "node:assert/strict"
import { test } from "node:test" import { test } from "node:test"
import { drop, moveOver, order } from "./layout.ts" import { drop, moveCard, moveOver, order } from "./layout.ts"
const cards = () => [ const cards = () => [
{ id: "apps", links: [{ id: "a" }, { id: "b" }, { id: "c" }] }, { id: "apps", links: [{ id: "a" }, { id: "b" }, { id: "c" }] },
@@ -31,6 +31,18 @@ test("a link dropped on a card goes to its end", () => {
assert.deepEqual(ids(drop(cards(), "a", "empty")), ["bc", "x", "a"]) assert.deepEqual(ids(drop(cards(), "a", "empty")), ["bc", "x", "a"])
}) })
test("a card takes the place of the card it is over, with its links", () => {
assert.deepEqual(ids(moveCard(cards(), "apps", "empty")), ["x", "", "abc"])
assert.deepEqual(ids(moveCard(cards(), "empty", "apps")), ["", "abc", "x"])
})
test("a card over itself, or a link over a card, moves no card", () => {
const before = cards()
assert.equal(moveCard(before, "apps", "apps"), before)
assert.equal(moveCard(before, "a", "web"), before)
assert.equal(drop(before, "apps", "web"), before)
})
test("unknown ids change nothing", () => { test("unknown ids change nothing", () => {
const before = cards() const before = cards()
assert.equal(drop(before, "nope", "x"), before) assert.equal(drop(before, "nope", "x"), before)
+16 -2
View File
@@ -1,4 +1,4 @@
// Where links sit in their cards. Pure, so drag and drop can be tested without a browser. // Where the cards sit, and the links in them. Pure, so drag and drop can be tested without a browser.
type Card = { id: string; links: { id: string }[] } type Card = { id: string; links: { id: string }[] }
@@ -28,6 +28,20 @@ export function moveOver<TCard extends Card>(
) )
} }
/** While dragging a card: it takes the place of the card it hovers over. */
export function moveCard<TCard extends Card>(
cards: TCard[],
cardId: string,
overId: string
): TCard[] {
const from = cards.findIndex((c) => c.id === cardId)
const to = cards.findIndex((c) => c.id === overId)
if (from < 0 || to < 0 || from === to) return cards
const next = [...cards]
next.splice(to, 0, ...next.splice(from, 1))
return next
}
/** On drop: the link takes the place of the link it was dropped on. */ /** On drop: the link takes the place of the link it was dropped on. */
export function drop<TCard extends Card>( export function drop<TCard extends Card>(
cards: TCard[], cards: TCard[],
@@ -45,6 +59,6 @@ export function drop<TCard extends Card>(
return cards.map((c) => (c === card ? { ...c, links } : c)) return cards.map((c) => (c === card ? { ...c, links } : c))
} }
/** What the server stores: per card, its link ids in order. */ /** What the server stores: the cards in order and, per card, its link ids in order. */
export const order = (cards: Card[]) => export const order = (cards: Card[]) =>
cards.map((c) => ({ id: c.id, linkIds: c.links.map((l) => l.id) })) cards.map((c) => ({ id: c.id, linkIds: c.links.map((l) => l.id) }))