Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

make title field editable #509

Merged
merged 11 commits into from
Feb 10, 2018
Merged

make title field editable #509

merged 11 commits into from
Feb 10, 2018

Conversation

aks-
Copy link
Collaborator

@aks- aks- commented Feb 7, 2018

No description provided.

className='bn f6 pl1 normal w-100'
defaultValue={editValue || title}
onKeyUp={ev => this.handleKeyup(ev)}
innerRef={input => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why innerRef? check here - styled-components/styled-components#102

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its hard enough to make a note in a github comment, then its maybe hard/rare enough to add a comment to the code?

martinheidegger
martinheidegger previously approved these changes Feb 7, 2018
Copy link
Collaborator

@martinheidegger martinheidegger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a step-up to the former PR! 👍 I added some notes on improvements. Maybe you find some useful.


export const updateTitle = (key, path, editValue) => {
const filePath = `${path}/dat.json`
readFile(filePath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to use dat-json ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinheidegger it requires archive for it to work https://github.com/joehand/dat-json/blob/master/index.js#L14 which we are not saving in our dat(s). Additionally in the prior version they did almost same as what we are doing right now in this pr - https://github.com/dat-land/dat-desktop/blob/master/lib/dat-json.js

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure 👍 or not but can be fixed in a future pr.

className='bn f6 pl1 normal w-100'
defaultValue={editValue || title}
onKeyUp={ev => this.handleKeyup(ev)}
innerRef={input => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its hard enough to make a note in a github comment, then its maybe hard/rare enough to add a comment to the code?

dispatch(updateTitle(key, path, editValue)),
activateTitleEditing: (title, editable) =>
dispatch(activateTitleEditing(title)),
editTitle: title => dispatch(editTitle(title)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused by the name editTitle. Maybe directTitleInput or so? Tbh. editTitle seems like the only action that doesn't make sense while the others seem to fit perfectly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the name to updateTemporaryTitleValue

this.titleInput = input
}}
/>
{editValue === title ? (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only place where we need the editValue and that's why we are keeping it in the state using the updateTemporaryTitleValue, if we can get rid of it somehow we can have just one flag in state isTitleUnderEdit and get rid of updateTemporaryTitleValue action and UPDATE_TEMPORARY_TITLE_VALUE event as well. Maybe when we refactor out this inline title input field to a package...

martinheidegger
martinheidegger previously approved these changes Feb 9, 2018
Copy link
Collaborator

@martinheidegger martinheidegger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice!


export const updateTitle = (key, path, editValue) => {
const filePath = `${path}/dat.json`
readFile(filePath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use async/await

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this fails if there's no dat.json yet

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A. Currently it fails silently (no catch handler) and it returns the function before the writing is finished. Not sure if writing this async would look so cool:

(async function () {
   const metadata = JSON.parse(await readFile(filePath)
   await writeFile(filePath, JSON.stringify({... metadata, title: editValue})
})()

Not soo much better, but I agree: slightly.

B. I didn't mention the fail of missing dat.json because in practice the duration of not-having a dat.json is very short. (milliseconds?) - quicker than any user can edit a title. Also I am not sure how the whole functionality should work: If there is no dat.json - can you edit the title? What if the dat.json was deleted while editing or we had an write error? Should there be an alert? Shouldn't this be part of the "lock" discussion (-> future work)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it failing in the way if someone deletes the file in middle of editing, what will happen. But was struggling with design on how and where to show the alert, maybe alert box like when we delete the dat. Should we create an issue or add it to todo list?

const Row = ({ dat, shareDat, onDeleteDat, inspectDat, onTogglePause }) => (
<Tr
onClick={ev => {
if (ev.target.tagName === 'SVG' || ev.target.tagName === 'use') return
if (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be refactored using an array: if (['SVG', 'use', 'INPUT'].includes(ev.target.tagName))

return mapStateToProps
}

const mapDispatchToProps = dispatch => ({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hard to read, maybe let's add the { return ... } around the function block?

import React, { Component } from 'react'
import styled from 'styled-components'
import Icon from './icon'
import { Plain as PlainButton, Green as GreenButton } from './button'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be written shorter using

import { * as Button }  from './button'

and then

<Button.Green />

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to have any * in the import statements as that makes it unclear which of the parts of ./button are required in the file by just looking at the header.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that point, but for buttons this is literally just different colors, so you don't get relevant information out of this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?! Just reading it like this: I get the information what buttons are used, because only those two buttons are referenced. If I don't use one of the two buttons the linter will complain about an unused reference.

Copy link
Collaborator Author

@aks- aks- Feb 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, not sure if I should go ahead with this one? I personally like PlainButton than Button.plain 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, then 2>1 => PlainButton it is :)

Copy link
Collaborator

@juliangruber juliangruber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise, LGTM!

@@ -15,7 +15,11 @@ const defaultState = {
up: 0,
down: 0
},
inspect: { key: null }
inspect: { key: null },
titleUnderEdit: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name isn't clear to me, under is mostly used for location.

Can we call this for example titleEditInPlace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juliangruber yeah titleEditInPlace sounds better. Making that change now....

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My - horrible - default approach would be currentlyEditedTitle. To me both titleEditInPlace and titleUnderEdit are almost equal so I leave it up to you. Other ideas: focussedTitle or titleEditorField

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentlyEditedTitle works for me too, it's natural +1 but different from all the other state names -1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since titleEditInPlace is already in this PR. lets go with that 😆

@juliangruber juliangruber merged commit ea732f0 into react Feb 10, 2018
@juliangruber juliangruber deleted the add/edit-dat-title branch February 10, 2018 08:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants