Skip to content

Commit

Permalink
web/settings: show every layer of settings objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Nov 17, 2024
1 parent 216d16d commit 1041ebc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
6 changes: 5 additions & 1 deletion web/src/ui/settings/SettingsView.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ div.settings-view {
display: flex;
flex-direction: column;

h2, h3 {
h2, h3, h4 {
margin: 0;
}

summary > h3, summary > h4 {
display: inline;
}

table {
text-align: left;

Expand Down
32 changes: 30 additions & 2 deletions web/src/ui/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,37 @@ const CustomCSSInput = ({ setPref, room }: { setPref: SetPrefFunc, room: RoomSta
</div>
}

const AppliedSettingsView = ({ room }: SettingsViewProps) => {
const client = use(ClientContext)!

return <div className="applied-settings">
<h3>Raw settings data</h3>
<details>
<summary><h4>Applied settings in this room</h4></summary>
<JSONView data={room.preferences}/>
</details>
<details open>
<summary><h4>Global account settings</h4></summary>
<JSONView data={client.store.serverPreferenceCache}/>
</details>
<details open>
<summary><h4>Global local settings</h4></summary>
<JSONView data={client.store.localPreferenceCache}/>
</details>
<details open>
<summary><h4>Room account settings</h4></summary>
<JSONView data={room.serverPreferenceCache}/>
</details>
<details open>
<summary><h4>Room local settings</h4></summary>
<JSONView data={room.localPreferenceCache}/>
</details>
</div>
}

const SettingsView = ({ room }: SettingsViewProps) => {
const client = use(ClientContext)!
const setPref = useCallback((context: PreferenceContext, key: keyof Preferences, value: PreferenceValueType | undefined)=> {
const setPref = useCallback((context: PreferenceContext, key: keyof Preferences, value: PreferenceValueType | undefined) => {
if (context === PreferenceContext.Account) {
client.rpc.setAccountData("fi.mau.gomuks.preferences", {
...client.store.serverPreferenceCache,
Expand Down Expand Up @@ -236,7 +264,7 @@ const SettingsView = ({ room }: SettingsViewProps) => {
</tbody>
</table>
<CustomCSSInput setPref={setPref} room={room} />
<JSONView data={room.preferences} />
<AppliedSettingsView room={room} />
</>
}

Expand Down
4 changes: 2 additions & 2 deletions web/src/ui/util/JSONView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function renderJSONValue(data: unknown, collapsed: boolean) {
}
return <ul className="json-object-children">
{entries.map(([key, value], index, arr) =>
<li key={key} className="json-object-entry">
value !== undefined ? <li key={key} className="json-object-entry">
<JSONValueWithKey data={value} objectKey={key} trailingComma={index < arr.length - 1}/>
</li>)}
</li> : null)}
</ul>
}
case "string":
Expand Down

0 comments on commit 1041ebc

Please sign in to comment.