Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SvelteKit #756

Merged
merged 44 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ae2cef5
Standardize on 'en', not 'en-US' as a language code, but register both
eyeseast Nov 21, 2024
51ba1c2
check
eyeseast Nov 21, 2024
dd5672e
Get two-letter code everywhere
eyeseast Nov 21, 2024
fd77515
Merge pull request #868 from MuckRock/818-translation-strings
eyeseast Nov 21, 2024
48e8097
Refactor sidebar components
allanlasser Nov 22, 2024
afb1fb7
Make layouts more consistent
allanlasser Nov 22, 2024
664520a
- Move pinned data into top-level layout.ts
allanlasser Nov 22, 2024
857ee2f
Add a slot to show search tips
eyeseast Nov 22, 2024
f17598b
Draft a changelog
eyeseast Nov 24, 2024
afbf381
Pass query through viewer links between modes
eyeseast Nov 24, 2024
9fc2adf
Use getApiResponse on infinite scrolls, too
eyeseast Nov 25, 2024
65931ba
History and Scheduled, too
eyeseast Nov 25, 2024
1b0a420
Update src/lib/components/forms/Search.svelte
eyeseast Nov 25, 2024
8208179
Merge pull request #877 from MuckRock/843-search-help
eyeseast Nov 25, 2024
0d66a67
Merge pull request #879 from MuckRock/query-param-links
eyeseast Nov 25, 2024
f832f88
Merge pull request #878 from MuckRock/changelog
eyeseast Nov 25, 2024
31f55fb
Apply suggestions from code review
eyeseast Nov 25, 2024
112b4cd
Merge pull request #880 from MuckRock/829-infinite-scroll-errors
eyeseast Nov 25, 2024
4ebe5f2
Add project slugs to search queries for readability
eyeseast Nov 25, 2024
984e4ea
Merge pull request #882 from MuckRock/search-slugs
eyeseast Nov 25, 2024
246eaa5
Fix page data access
allanlasser Nov 25, 2024
be4b12e
Fix snapshots
allanlasser Nov 25, 2024
76e262b
Fix check
allanlasser Nov 25, 2024
a73f5c4
Hide empty collaborators on public projects
allanlasser Nov 25, 2024
2f3baee
Refactor document/Access to common component, use in Project header
allanlasser Nov 25, 2024
7fd68f7
Restore "Your Documents" nav item
allanlasser Nov 25, 2024
c6672a5
Adds Upload button to Project actions
allanlasser Nov 25, 2024
eee19cf
Smol icon
allanlasser Nov 25, 2024
8f29be3
Tweak langauge strings
allanlasser Nov 25, 2024
086358e
Merge branch 'sveltekit' of github.com:MuckRock/documentcloud-fronten…
eyeseast Nov 25, 2024
32cc3ff
Enable pinning based on logged-in status, not project.edit_access
eyeseast Nov 25, 2024
479a8d0
Merge pull request #889 from MuckRock/874-public-pinning
eyeseast Nov 25, 2024
9626b25
Merge pull request #876 from MuckRock/allanlasser/issue869
allanlasser Nov 25, 2024
e09703e
Hide page actions on embeds
eyeseast Nov 25, 2024
0bf5531
fix eager fetch
eyeseast Nov 25, 2024
baad22c
Set min-width on Share columns
allanlasser Nov 25, 2024
fcbc9ff
Adds sidebar toggles to project list header
allanlasser Nov 25, 2024
7190ed2
Merge pull request #891 from MuckRock/883-hide-actions-embeds
eyeseast Nov 25, 2024
8893c5d
Merge pull request #893 from MuckRock/allanlasser/issue875
allanlasser Nov 25, 2024
b86f6f4
Change how we measure clicks outside dropdowns
allanlasser Nov 25, 2024
cc03988
Take a yes-and approach to clicks outside
allanlasser Nov 25, 2024
6b3b827
Adds Nested Dropdown test case
allanlasser Nov 25, 2024
770311b
Merge pull request #892 from MuckRock/allanlasser/issue884
allanlasser Nov 25, 2024
f07c2eb
Merge pull request #894 from MuckRock/allanlasser/issue857
allanlasser Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

Significant changes to DocumentCloud's frontend will be noted in this file. We also announce new features in MuckRock's regular [Release Notes](https://www.muckrock.com/news/archives/?tags=115608) column.

DocumentCloud is a running application used by thousands of journalists around the world, so updates here are organized by date, not by version number. The goal of this file is to keep a record of features added, updated and removed.

## 2024-12-02 DocumentCloud on SvelteKit released

This is the latest iteration of DocumentCloud, bringing the frontend to SvelteKit and updating the UI.

Our goals:

- Clean up the user interface to provide a consistent experience that scales across devices.
- Server-render pages, making them faster to load and easier to share.
- Simplify the application’s logic to make it easier to reason about its structure, reactivity and state, and make it easier to support new features.
- Modernize our technologies and development practices to speed up development, ensuring high-quality, bug free code from the start.
9 changes: 6 additions & 3 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ export const handleError = Sentry.handleErrorWithSentry();
/** @type {import('@sveltejs/kit').Handle} */
async function language({ event, resolve }) {
const lang =
event.request.headers.get("accept-language")?.split(",")[0] ?? "en-US";
event.request.headers.get("accept-language")?.split(",")[0] ?? "en";

if (lang) {
locale.set(lang);
// use en.json for en-US and such
const [language, ...tags] = lang.split("-");

if (language) {
locale.set(language);
}

return resolve(event, {
Expand Down
42 changes: 25 additions & 17 deletions src/langs/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"title": "Title"
},
"search": {
"matchingResults": "{n, plural, one {# matching result} other {# matching results}}"
"matchingResults": "{n, plural, one {# matching result} other {# matching results}}",
"reset": "Clear Search",
"help": "Use filters like <code>user:</code>, <code>project:</code> or <code>organization:</code> to refine searches. Use <code>sort:</code> to order results.",
"more": "Learn more"
},
"homeTemplate": {
"signedIn": "Signed in as {name}",
Expand Down Expand Up @@ -203,7 +206,9 @@
"pageAbbrev": "p.",
"pageCount": "{n, plural, one {# page} other {# pages}}",
"select": "Select",
"noteCount": "{n, plural, one {# note} other {# notes}}"
"noteCount": "{n, plural, one {# note} other {# notes}}",
"more": "Load more",
"retry": "Please try again."
},
"error": {
"report": "Report a problem"
Expand Down Expand Up @@ -247,7 +252,7 @@
"view": "Viewer"
},
"delete": {
"action": "Delete project",
"action": "Delete Project",
"confirm": "Confirm delete",
"really": "Are you sure you want to delete this project ({project})?"
},
Expand All @@ -258,7 +263,7 @@
"collaborators": {
"title": "Collaborators",
"empty": "No collaborators",
"add": "Invite users to this project"
"add": "Invite"
},
"fields": {
"title": "Title",
Expand Down Expand Up @@ -345,15 +350,18 @@
"shareEmbed": "Share & Embed",
"sharedWith": "Shared with",
"revisions": "Revision History",
"edit": "Edit Metadata",
"edit": "Edit Document Metadata",
"upload": "Upload Documents",
"uploadToProject": "Upload to Project",
"download": "Download File",
"reprocess": "Reprocess",
"delete": "Delete",
"shareEmbedProject": "Share & Embed Project",
"editProject": "Edit Project Metadata",
"deleteProject": "Delete Project",
"created": "Created on",
"updated": "Last updated on",
"language": "Language",
"delete": "Delete",
"ocr_engine": "OCR Engine",
"addons": {
"title": "Add-Ons",
Expand Down Expand Up @@ -382,7 +390,7 @@
"cta": "Annotate this document"
},
"edit": {
"title": "Edit document metadata",
"title": "Edit Document Metadata",
"fields": {
"title": "Title",
"description": "Description",
Expand Down Expand Up @@ -417,10 +425,10 @@
}
},
"redact": {
"title": "Redact Document",
"confirm": "Save",
"confirmTitle": "Save Redactions",
"really": "Are you sure you wish to redact the current document? If you continue, the document viewer will be inaccessible temporarily while the document reprocesses with the redactions in place. This change is irreversible.",
"title": "Redact Document",
"instructions": "Click and drag to draw a black rectangle over each portion of the document you’d like to redact. Associated text will be removed when you save your redactions.",
"undo": "Undo",
"cancel": "Discard",
Expand All @@ -432,13 +440,13 @@
"page": "Page",
"title": "Title",
"delete": "Delete",
"new": "Add a new section",
"new": "Add New Section",
"clear": "Clear",
"update": "Update section",
"overwrite": "There is already a section starting on page {n}."
},
"delete": {
"title": "Confirm delete",
"title": "Confirm Delete",
"really": "Proceeding will permanently delete the {n, plural, one {selected document} other {# selected documents}}.",
"continue": "Do you wish to continue?",
"confirm": "Delete",
Expand All @@ -447,7 +455,7 @@
"none": "No documents selected. Close this form and select at least one document first."
},
"data": {
"title": "Edit tags and data",
"title": "Edit Tags & Data",
"key": "Key",
"newkey": "New item",
"value": "Value",
Expand All @@ -457,15 +465,15 @@
"save": "Save",
"cancel": "Cancel",
"addNew": "Add new item:",
"many": "Saving will add the following data and tags to {n, plural, one {the selected document} other {all # selected documents}}. No tags or data will be removed."
"many": "Saving will add the following tags and data to {n, plural, one {the selected document} other {all # selected documents}}. No tags or data will be removed."
},
"bulk": {
"title": "Edit",
"title": "Actions",
"actions": {
"share": "Share",
"edit": "Edit metadata",
"data": "Edit tags & data",
"project": "Move to project",
"share": "Share & Embed",
"edit": "Edit Metadata",
"data": "Edit Tags & Data",
"project": "Move to Project",
"reprocess": "Reprocess",
"delete": "Delete"
}
Expand Down
6 changes: 2 additions & 4 deletions src/lib/api/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* API response types
*
* This is a separate module from what's in src/api to prevent conflicts.
* Both modules can be merged later.
* */
*/

import type { DefinedError } from "ajv";

export type Access = "public" | "private" | "organization"; // https://www.documentcloud.org/help/api#access-levels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`UserMenu 1`] = `
tabindex="0"
>
<span
class="sidebarItem container svelte-1i964q1"
class="sidebarItem container svelte-8l7as"
role="button"
tabindex="0"
title="Open Menu"
Expand All @@ -26,7 +26,7 @@ exports[`UserMenu 1`] = `
</div>

<span
class="label svelte-1i964q1"
class="label svelte-8l7as"
>
<span
class="name"
Expand Down Expand Up @@ -65,7 +65,7 @@ exports[`UserMenu 1`] = `
role="menu"
>
<a
class="sidebarItem container svelte-1i964q1"
class="sidebarItem container svelte-8l7as"
href="https://dev.squarelet.com"
target="_blank"
title=""
Expand All @@ -84,7 +84,7 @@ exports[`UserMenu 1`] = `
</svg>

<span
class="label svelte-1i964q1"
class="label svelte-8l7as"
>
Account settings
</span>
Expand All @@ -93,7 +93,7 @@ exports[`UserMenu 1`] = `


<span
class="sidebarItem container svelte-1i964q1 hover"
class="sidebarItem container svelte-8l7as hover"
role="button"
tabindex="0"
title=""
Expand All @@ -112,7 +112,7 @@ exports[`UserMenu 1`] = `
</svg>

<span
class="label svelte-1i964q1"
class="label svelte-8l7as"
>
Upload via email
</span>
Expand All @@ -121,7 +121,7 @@ exports[`UserMenu 1`] = `


<a
class="sidebarItem container svelte-1i964q1"
class="sidebarItem container svelte-8l7as"
href="https://api.dev.documentcloud.org/accounts/logout/"
title=""
>
Expand All @@ -139,7 +139,7 @@ exports[`UserMenu 1`] = `
</svg>

<span
class="label svelte-1i964q1"
class="label svelte-8l7as"
>
Sign out
</span>
Expand Down
35 changes: 22 additions & 13 deletions src/lib/components/addons/History.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,46 @@
import type { Run } from "$lib/api/types";

import { _ } from "svelte-i18n";
import { History16, History24, Hourglass24 } from "svelte-octicons";
import { Alert24, History16, History24, Hourglass24 } from "svelte-octicons";

import HistoryEvent from "./HistoryEvent.svelte";
import Paginator from "$lib/components/common/Paginator.svelte";
import SidebarGroup from "../sidebar/SidebarGroup.svelte";
import SidebarItem from "../sidebar/SidebarItem.svelte";
import Empty from "../common/Empty.svelte";

import { getApiResponse } from "$lib/utils/api";

export let runs: Run[];
export let previous: Maybe<Nullable<string>> = undefined;
export let next: Maybe<Nullable<string>> = undefined;

export let loading = false;

let error: string = "";

$: empty = runs.length === 0;

// load the next set of results
async function load(url: URL) {
loading = true;

// todo: better error handling
const res = await fetch(url, { credentials: "include" }).catch(
const resp = await fetch(url, { credentials: "include" }).catch(
console.error,
);
if (!res) return console.error("API error");
if (!res.ok) {
console.error(res.statusText);
loading = false;

const { data: results, error: err } = await getApiResponse<Page<Run>>(resp);

if (err) {
error = err.message;
}

const results: Page<Run> = await res.json();
if (results) {
runs = results.results;
next = results.next;
previous = results.previous;
}

runs = results.results;
next = results.next;
previous = results.previous;
loading = false;
}
</script>
Expand All @@ -50,6 +55,10 @@

{#if loading}
<Empty icon={Hourglass24}>Loading past runs…</Empty>
{:else if error}
<Empty icon={Alert24}>
{error}
</Empty>
{:else}
{#each runs as run}
<HistoryEvent {run} />
Expand All @@ -62,10 +71,10 @@
<Paginator
has_next={Boolean(next)}
has_previous={Boolean(previous)}
on:next={(e) => {
on:next={() => {
if (next) load(new URL(next));
}}
on:previous={(e) => {
on:previous={() => {
if (previous) load(new URL(previous));
}}
/>
Expand Down
Loading