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

Add toggle to make fields language independent #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions src/lib/components/FieldItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@
{/if}
</div>

<div slot="toggle">
<Toggle
label="Language Independent"
toggled={field.is_language_independent}
on:toggle={({ detail }) => {
field.is_language_independent = detail
}}
/>
</div>

<!-- <input type="checkbox" bind:checked={field.is_static} slot="static" /> -->

{#each field.fields as subfield, i (subfield.id)}
Expand Down
1 change: 1 addition & 0 deletions src/lib/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const Field = (field = {}) => ({
fields: [],
options: {},
is_static: false,
is_language_independent: false,
...field
})

Expand Down
2 changes: 2 additions & 0 deletions src/lib/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export function validate_site_structure_v2(site) {
fields: [],
options: {},
is_static: false,
is_language_independent: false,
}],
content: {
en: {
Expand Down Expand Up @@ -426,6 +427,7 @@ export function convertFields(fields = [], fn = () => { }) {
options: field.options || {},
default: field.default || '',
is_static: field.is_static || false,
is_language_independent: field.is_language_independent || false,
}
})
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type Field = {
fields: Array<Field>,
options: object,
is_static: boolean,
is_language_independent: false,
value?: any
}

Expand Down
11 changes: 10 additions & 1 deletion src/lib/stores/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,19 @@ export function get_content_with_static({ component, symbol, loc }) {
const field_value = component.content?.[loc]?.[field.key]
// if field is static, use value from symbol content
if (field.is_static) {
const symbol_value = symbol.content?.[loc]?.[field.key]
const symbol_value = field.is_language_independent
? symbol.content?.['en']?.[field.key]
: symbol.content?.[loc]?.[field.key]
return {
key: field.key,
value: symbol_value
}
} else if (field.is_language_independent) {
const default_value = symbol.content?.['en']?.[field.key]
return {
key: field.key,
value: default_value
}
} else if (field_value !== undefined) {
return {
key: field.key,
Expand All @@ -199,6 +207,7 @@ export function get_content_with_static({ component, symbol, loc }) {
return _.cloneDeep(content)
}


export function getPageData({ page = get(activePage), site = get(activeSite), loc = get(locale) }) {
const page_content = page.content[loc]
const site_content = site.content[loc]
Expand Down